0% found this document useful (0 votes)
28 views28 pages

Advance C Programming100-Ques

The document contains a series of output-based questions related to advanced C programming concepts, including keywords, error identification in code snippets, and expected outputs of various programs. Each question is followed by multiple-choice answers and explanations of the correct answers. The topics covered include storage classes, memory allocation, control flow, and operator behavior.

Uploaded by

dwivedialok
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views28 pages

Advance C Programming100-Ques

The document contains a series of output-based questions related to advanced C programming concepts, including keywords, error identification in code snippets, and expected outputs of various programs. Each question is followed by multiple-choice answers and explanations of the correct answers. The topics covered include storage classes, memory allocation, control flow, and operator behavior.

Uploaded by

dwivedialok
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 28

Advance C Programming

Output Based Questions

1. Which of the following is a keyword used for a storage class?


A] Printf B] external
C] auto D] scanf

Answer: Option C

2. Point out the error in the program?

#include<stdio.h>
#include<stdlib.h>

int main()
{
unsignedchar;
FILE *fp;
fp=fopen("trial", "r");
if(!fp)
{
printf("Unable to open file");
exit(1);
}
fclose(fp);
return0;
}

A. Error: in unsigned char statement


B. Error: unknown file pointer
C. No error
D. None of above

Answer: Option C

Explanation:

This program tries to open the file trial.txt in read mode. If file not
exists or unable to read it prints "Unable to open file" and then
terminate the program.

If file exists, it simply close the file and then terminates the program.
3. Point out the error in the following program.

#include<stdio.h>
#include<stdlib.h>

int main()
{
char *ptr;
*ptr = (char)malloc(30);
strcpy(ptr, "RAM");
printf("%s", ptr);
free(ptr);
return0;
}

A. Error: in strcpy() statement.

B. Error: in *ptr = (char)malloc(30);

C. Error: in free(ptr);

D. No error

Answer: Option B

Explanation:

Answer: ptr = (char*)malloc(30);

4. What will be the output of the program?

#include<stdio.h>
int main()
{
inti=0;
for(; i<=5; i++);
printf("%d", i);
return0;
}

A. 0, 1, 2, 3, 4, 5 B. 5

C. 1, 2, 3, 4 D. 6
Answer: Option D

Explanation:

Step 1: inti = 0; here variable i is an integer type and initialized to '0'.


Step 2: for(; i<=5; i++); variable i=0 is already assigned in previous
step. The semi-colon at the end of this for loop tells, "there is no more
statement is inside the loop".

Loop 1: here i=0, the condition in for(; 0<=5; i++) loop satisfies and
then i is incremented by '1'(one)
Loop 2: here i=1, the condition in for(; 1<=5; i++) loop satisfies and
then i is incremented by '1'(one)
Loop 3: here i=2, the condition in for(; 2<=5; i++) loop satisfies and
then i is incremented by '1'(one)
Loop 4: here i=3, the condition in for(; 3<=5; i++) loop satisfies and
then i is increemented by '1'(one)
Loop 5: here i=4, the condition in for(; 4<=5; i++) loop satisfies and
then i is incremented by '1'(one)
Loop 6: here i=5, the condition in for(; 5<=5; i++) loop satisfies and
then i is incremented by '1'(one)
Loop 7: here i=6, the condition in for(; 6<=5; i++) loop fails and then i is
not incremented.

Step 3: printf("%d", i); here the value of i is 6. Hence the output is


'6'.

5. What will be the output of the program?

#include<stdio.h>

int main()
{
inti;
i = printf("How r u\n");
i = printf("%d\n", i);
printf("%d\n", i);
return0;
}

How r u How r u
A. 7 B. 8
2 2
How r u
Error: cannot
C. 1 D.
assign printf to variable
1
Answer: Option B

Explanation:

In the program, printf() returns the number of charecters printed on the


console

i = printf("How r u\n"); This line prints "How r u" with a new line
character and returns the length of string printed then assign it
to variable i.
So i = 8 (length of '\n' is 1).

i = printf("%d\n", i); In the previous step the value of i is 8. So it


prints "8" with a new line character and returns the length of string
printed then assign it tovariablei. So i = 2 (length of '\n' is 1).

printf("%d\n", i); In the previous step the value of i is 2. So it prints


"2".

6. What will be the output of the program?

#include<stdio.h>
int main()
{
int a = 500, b = 100, c;
if(!a >= 400)
b = 300;
c = 200;
printf("b = %d c = %d\n", b, c);
return0;
}

A. b = 300 c = 200 B. b = 100 c = garbage

C. b = 300 c = garbage D. b = 100 c = 200


Answer: Option D

Explanation:

Initially variables a = 500, b = 100 and c is not assigned.


Step 1: if(!a >= 400)
Step 2: if(!500 >= 400)
Step 3: if(0 >= 400)
Step 4: if(FALSE) Hence the if condition is failed.
Step 5: So, variable c is assigned to a value '200'.
Step 6: printf("b = %d c = %d\n", b, c); It prints value of b and c.
Hence the output is "b = 100 c = 200"

7. Which of the following are unary operators in C?

1. !
2. sizeof
3. ~
4. &&

A. 1, 2 B. 1, 3

C. 2, 4 D. 1, 2, 3
Answer: Option D

Explanation:

An operation with only one operand is called unary operation.


Unary operators:
! Logical NOT operator.
~ bitwise NOT operator.
sizeof Size-of operator.

&& Logical AND is a logical operator.

Therefore, 1, 2, 3 are unary operators.

8. What will be the output of the program?

#include<stdio.h>
int main()
{
inti=-3, j=2, k=0, m;
m = ++i&& ++j && ++k;
printf("%d, %d, %d, %d\n", i, j, k, m);
return0;
}

A. -2, 3, 1, 1 B. 2, 3, 1, 2

C. 1, 2, 3, 1 D. 3, 3, 1, 2
Answer: Option A

Explanation:

Step 1: inti=-3, j=2, k=0, m; here variable i, j, k, m are declared


as an integer type and variable i, j, k are initialized to -3, 2, 0
respectively.

Step 2: m = ++i&& ++j && ++k;


becomes m = -2 && 3 && 1;
becomes m = TRUE && TRUE; Hence this statement becomes TRUE. So it
returns '1'(one). Hence m=1.

Step 3: printf("%d, %d, %d, %d\n", i, j, k, m); In the previous


step the value of i,j,k are increemented by '1'(one).

Hence the output is "-2, 3, 1, 1".

9. What will be the output of the program?

#include<stdio.h>
int reverse(int);

int main()
{
int no=5;
reverse(no);
return0;
}
int reverse(int no)
{
if(no == 0)
return0;
else
printf("%d,", no);
reverse (no--);
}
A. Print 5, 4, 3, 2, 1 B. Print 1, 2, 3, 4, 5

C. Print 5, 4, 3, 2, 1, 0 D. Infinite loop


Answer: Option D

Explanation:

Step 1: int no=5; The variable no is declared as integer type and


initialized to 5.

Step 2: reverse(no); becomes reverse(5); It calls the


function reverse() with '5' as parameter.

The function reverse accept an integer number 5 and it returns '0'(zero)


if(5 == 0) if the given number is '0'(zero) or else printf("%d,", no); it
prints that number 5 and calls the function reverse(5);.

The function runs infinetely because the there is a post-decrement


operator is used. It will not decrease the value of 'n' before calling the
reverse() function. So, it callsreverse(5) infinitely.

Note: If we use pre-decrement operator like reverse(--n), then the


output will be 5, 4, 3, 2, 1. Because before calling the function, it
decrements the value of 'n'.

10. What will be the output of the program?

#include<stdio.h>
#include<stdlib.h>

int main()
{
inti=0;
i++;
if(i<=5)
{
printf("Informatrix”);
exit(1);
main();
}
return0;
}

A. Prints "informatrix" 5 times


B. Function main() doesn't calls itself

C. Infinite loop

D. Prints "Informatrix"
Answer: Option D

Explanation:

Step 1: inti=0; The variable i is declared as in integer type and


initialized to '0'(zero).

Step 2: i++; Here variable i is increemented by 1. Hence i becomes


'1'(one).

Step 3: if(i<=5) becomes if(1 <=5). Hence the if condition is satisfied


and it enter into if block statements.

Step 4: printf("IndiaBIX"); It prints "IndiaBIX".

Step 5: exit(1); This exit statement terminates the program execution.

Hence the output is "Informatrix".

11. What does the following declaration mean?


int (*ptr)[10];
A. ptr is array of pointers to 10 integers
B. ptr is a pointer to an array of 10 integers
C. ptr is an array of 10 integers
D. ptr is an pointer to array
Option B

12. What will be the output of the program?


#include<stdio.h>
#define PRINT(i) printf("%d,",i)
int main()
{
int x=2, y=3, z=4;
PRINT(x);
PRINT(y);
PRINT(z);
return 0;
}
A. 2, 3, 4, B. 2, 2, 2,
C. 3, 3, 3, D. 4, 4, 4,
Option A
Explanation:
The macro PRINT(i) print("%d,", i); prints the given variable value in an
integer format.
Step 1: int x=2, y=3, z=4; The variable x, y, z are declared as an integer
type and initialized
to 2, 3, 4 respectively.
Step 2: PRINT(x); becomes printf("%d,",x). Hence it prints '2'.
Step 3: PRINT(y); becomes printf("%d,",y). Hence it prints '3'.
Step 4: PRINT(z); becomes printf("%d,",z). Hence it prints '4'.

13. What will be output if you will execute following c code?


#include<stdio.h>
int sq(int);
int main(){
int a=1,x;
x=sq(++a)+sq(a++)+sq(a++);
printf("%d",x);
return 0;
}
int sq(int num){
return num*num; }
A)15
B)16
C)17
D)18
Explanation:
= sq(++a) + sq(a++) +
sq(a++) //a= 1 + 1
= sq(2) + sq(2) + sq(a+
+) //a = 2 + 1
= sq(2) + sq(2) +
sq(3) //a = 3 + 1
=4+4+9
= 17

14. What will be the output of the program (sample.c) given


below if it is executed from the command line?
cmd> sample friday tuesday sunday
/* sample.c */
#include<stdio.h>
int main(int argc, char *argv[])
{
printf("%c", *++argv[2] );
return 0;
}
A. s B. f
C. u D. r
Answer: Option C
15. What will be the output of the program?
#include<stdio.h>
#include<string.h>
int main()
{
char str1[20] = "Hello", str2[20] = " World";
printf("%s\n", strcpy(str2, strcat(str1, str2)));
return 0;
}
A. Hello B. World
C. Hello World D. WorldHello
Answer: Option C
Explanation:
Step 1: char str1[20] = "Hello", str2[20] = " World"; The variable str1 and
str2 is declared as
an array of characters and initialized with value "Hello" and " World"
respectively.
Step 2: printf("%s\n", strcpy(str2, strcat(str1, str2)));
=> strcat(str1, str2)) it append the string str2 to str1. The result will be
stored in str1.
Therefore str1 contains "Hello World".
=> strcpy(str2, "Hello World") it copies the "Hello World" to the variable
str2.
16. What will be the output of the program if the array begins
1200 in memory?
#include<stdio.h>
int main()
{
int arr[]={2, 3, 4, 1, 6};
printf("%u, %u, %u\n", arr, &arr[0], &arr);
return 0;
}
A. 1200, 1202, 1204 B. 1200, 1200, 1200
C. 1200, 1204, 1208 D. 1200, 1202, 1200
Answer: Option B
Explanation:
Step 1: int arr[]={2, 3, 4, 1, 6}; The variable arr is declared as an integer
array and
initialized.
Step 2: printf("%u, %u, %u\n", arr, &arr[0], &arr); Here,
The base address of the array is 1200.
=> arr, &arr is pointing to the base address of the array arr.
=> &arr[0] is pointing to the address of the first element array arr. (ie.
base address)
Hence the output of the program is 1200, 1200, 1200

17. What will be the output of the program?


#include<stdio.h>
int main()
{
int i=3,
j=2, k=0, m;
m = ++i && ++j || ++k;
printf("%d, %d, %d, %d\n", i, j, k, m);
return 0;
}
A. 1, 2, 0, 1
B. 3,2, 0, 1
C. 2,3, 0, 1
D. 2, 3, 1, 1
Answer: Option C
Explanation:
Step 1: int i=3,
j=2, k=0, m; here variable i, j, k, m are declared as an integer type and
variable i, j, k are initialized to 3,
2, 0 respectively.
Step 2: m = ++i && ++j || ++k;
becomes m = (2
&& 3) || ++k;
becomes m = TRUE || ++k;.
(++k) is not executed because (2
&& 3) alone return TRUE.
Hence this statement becomes TRUE. So it returns '1'(one). Hence m=1.
Step 3: printf("%d, %d, %d, %d\n", i

18.Which of the following statements are correct about the below


Cprogram?
#include<stdio.h>
int main()
{
int x = 10, y = 100%90, i;
for(i=1; i<10; i++)
if(x != y);
printf("x = %d y = %d\n", x, y);
return 0;
}
1 : The printf() function is called 10 times.
2 : The program will produce the output x = 10 y = 10
3 : The ; after the if(x!=y) will NOT produce an error.
4 : The program will not produce output.
A. 1 B. 2, 3
C. 3, 4 D. 4
Answer: Option B
19. What will be the output of the program?
#include<stdio.h>
int main()
{
int k, num=30;
k = (num>5 ? (num <=10 ? 100 : 200): 500);
printf("%d\n", num);
return 0;
}
A. 200 B. 30
C. 100 D. 500
Answer: Option B
Explanation:
Step 1: int k, num=30; here variable k and num are declared as an integer
type and variable
num is initialized to '30'.
Step 2: k = (num>5 ? (num <=10 ? 100 : 200): 500); This statement does
not affect the
output of the program. Because we are going to print the variable num in
the next statement.
So, we skip this statement.
Step 3: printf("%d\n", num); It prints the value of variable num '30'
Step 3: Hence the output of the program is '30'

20. What will be the output of the program, if a short int is 2


bytes wide?
#include<stdio.h>
int main()
{
short int i = 0;
for(i<=5 && i>=1;
++i; i>0)
printf("%u,", i);
return 0;
}
A. 1 ... 65535 B. Expression syntax error
C. No output D. 0, 1, 2, 3, 4, 5
Answer: Option A
Explanation:
for(i<=5 && i>=1;
++i; i>0) so expression i<=5 && i>=1
initializes for loop. expression
++i is the loop condition. expression i>0 is the increment expression.
In for( i <= 5 && i >= 1;
++i; i>0) expression i<=5 && i>=1
evaluates to one.
Loop condition always get evaluated to true. Also at this point it increases
i by one.
An increment_expression i>0 has no effect on value of i.so for loop get
executed till the limit
of integer (ie. 65535)
21. If the size of pointer is 4 bytes then What will be the output of
the program?
#include<stdio.h>
int main()
{
char *str[] = {"Frogs", "Do", "Not", "Die", "They", "Croak!"};
printf("%d, %d", sizeof(str), strlen(str[0]));
return 0;
}
A. 22, 4 B. 25, 5
C. 24, 5 D. 20, 2
Answer: Option C
Explanation:
Step 1: char *str[] = {"Frogs", "Do", "Not", "Die", "They", "Croak!"}; The
variable str is
declared as an pointer to the array of 6 strings.
Step 2: printf("%d, %d", sizeof(str), strlen(str[0]));
sizeof(str) denotes 6 * 4 bytes = 24 bytes. Hence it prints '24'
strlen(str[0])); becomes strlen(Frogs)). Hence it prints '5';
Hence the output of the program is 24, 5
22. Which of the following correctly shows the hierarchy of arithmetic operations in C?

A. /+*-

B. *-/+

C. +-/*

D. /*+-

Ans Option D
Explanation:
Simply called as BODMAS (Bracket of Division, Multiplication, Addition and Subtraction).
How Do I Remember ? BODMAS !
• B - Brackets first
• O - Orders (ie Powers and Square Roots, etc.)
• DM - Division and Multiplication (left-to-right)
• AS - Addition and Subtraction (left-to-right)

23. What will be the output of the program ?


#include<stdio.h>
int main()
{
char p[] = "%d\n";
p[1] = 'c';
printf(p, 65);
return 0;
}

A. A

B. a

C. c

D. 65
Answer: Option A
Explanation:
Step 1: char p[] = "%d\n"; The variable p is declared as an array of characters and initialized
with string "%d".
Step 2: p[1] = 'c'; Here, we overwrite the second element of array p by 'c'. So array
pbecomes "%c".
Step 3: printf(p, 65); becomes printf("%c", 65);
Therefore it prints the ASCII value of 65. The output is 'A'.

24. What will be the output of the program?

#include<stdio.h>
int get();

int main()
{
const int x = get();
printf("%d", x);
return 0;
}
int get()
{
return 20;
}
A.Garbage value
B.Error
C.20
D.0

Answer: Option C

Explanation:

Step 1: int get(); This is the function prototype for the funtion get(), it tells the compiler
returns an integer value and accept no parameters.

Step 2: const int x = get(); The constant variable x is declared as an integer data type and
initialized with the value "20".

The function get() returns the value "20".

Step 3: printf("%d", x); It prints the value of the variable x.

Hence the output of the program is "20".

25. How many times the while loop will get executed if a short int is 2 byte wide?

#include<stdio.h>
int main()
{
int j=1;
while(j <= 255)
{
printf("%c %d\n", j, j);
j++;
}
return 0;
}
A.Infinite times
B.255 times
C.256 times
D.254 times

Answer: Option B
Explanation:
The while(j <= 255) loop will get executed 255 times. The size short int(2 byte wide)
does not affect the while() loop.

26. How many times the below loop will get executed?

#include<stdio.h>
main()
{
int i,j;
i = 10;
for (j=i==10 ; j<=10 ; j++)
{
printf("\n%d",j);
}
}
(A) 1
(B) 10
(C) 11
(D) Compilation Error
Answer : 10
Explanation: Expression i ==10 return 1 and j get initialized to 1.

27. How many storage class specifiers in "C" language?


(A) 3
(B) 4
(C) 5
(D) 6
Answer : 4
Explanation: auto, register, static and extern are the storage class specifiers in "C".

28.What is the output of the following code?

#include "stdio.h"
extern int a;
main(){
printf("\na=%d",a);
return 0;
}
(A) a=0
(B) a=garbage value
(C) error
(D) none of these

Answer : error
Explanation: Linking undefined symbol.

29. What is the output of this C code?


#include <stdio.h>
#define foo(m, n) m * n = 10
int main()
{
printf("in main\n");
}
a) In main
b) Compilation error as lvalue is required for the expression m*n=10
c) Preprocessor error as lvalue is required for the expression m*n=10
d) None of the mentioned
Answer: a
Explanation:
Preprocessor just replaces whatever is given compiler
then checks for error at the replaced part of the code. Here it is not replaced anywhere.
Output:
$ cc pgm1.c
$ a.out
in main

30. Which of the following cannot be static in C?


a) Variables
b) Functions
c) Structures
d) None of the mentioned
Answer: d

31 .What is the output of this C code?


#include <stdio.h>
void main()
{
static int x;
if (x++ < 2)
main();
}
a) Infinite calls to main
b) Run time error
c) Varies
d) main is called twice
Answer: d

32. What is the output of this C code?


#include <stdio.h>
struct student
{
char a[5];
};
void main()
{
struct student s[] = {"hi", "hey"};
printf("%c", s[0].a[1]);
}
a) h
b) i
c) e
d) y
Answer: b

33.What is the output of the below c code?


#include <stdio.h>
void main()
{
char *s = "hello";
char *p = s;
printf("%p\t%p", p, s);
}
a) Different address is printed
b) Same address is printed
c) Run time error
d) Nothing

Answer: b

34. What is the output of this C code?


#include <stdio.h>
void main()
{
int x = 97;
int y = sizeof(x++);
printf("x is %d", x);
}
a) x is 97
b) x is 98
c) x is 99
d) Run time error

Answer: a

35. What is the output of this C code?


int main()
{
int a=8,b=2,c;
c=a<<b;
printf("%d",c);
return 0;
}
a) 32
b) 16
c) 8
d) 4
Answer: a
Explanation: Write 8 in binary system(1000) and shift it towards left by 2
i.e. 100000 which is 32 in decimal system.

36.What is the output of this C code?


int main()
{
char c='8';
printf("%d",c);
return 0;
}
a) 56
b) 16
c) 8
d) 4

Answer: a
Explanation: 64-8

37. What is the output of this C code?


int main()
{
int x = 100;
printf("decimal = %d; octal = %o; hex = %x\n", x, x, x);
printf("decimal = %d; octal = %#o; hex = %#x\n", x, x, x);
return 0;
}
a) decimal = 100; octal = 414; hex = 46
b) decimal = 100; octal = 414; hex = 64
c) decimal = 100; octal = 144; hex = 64
d) decimal = 100; octal = 144; hex = 46

Answer: c
Explanation: Decimal to Hexa conversion:
100/16 Quotient 6; Remainder 4
6/16 Quotient 0; Remainder 6
Writing the remainders in down to upward direction we get 64
Decimal to Octal conversion:
100/8 Quotient 12; Remainder 4
12/8 Quotient 1; Remainder 4
1/8 Quotient 0; Remainder 1
Writing the remainders in down to upward direction we get 144

38. what is the Output?


int main()
{
int arri[] = {1, 2 ,3};
int *ptri = arri;
char arrc[] = {1, 2 ,3};
char *ptrc = arrc;
printf("sizeof arri[] = %d ", sizeof(arri));
printf("sizeof ptri = %d ", sizeof(ptri));
printf("sizeof arrc[] = %d ", sizeof(arrc));
printf("sizeof ptrc = %d ", sizeof(ptrc));
return 0;
}
a) sizeof arri[] = 12 sizeof ptri = 8 sizeof arrc[] = 12 sizeof ptrc = 8
b) sizeof arri[] = 12 sizeof ptri = 8 sizeof arrc[] = 3 sizeof ptrc = 8
c) sizeof arri[] = 12 sizeof ptri = 4 sizeof arrc[] = 3 sizeof ptrc = 8
d) sizeof arri[] = 12 sizeof ptri = 4 sizeof arrc[] = 3 sizeof ptrc = 8
Answer: b
Explanation: Size of pointer is independent of data type.

39. Predict the output of the following C snippets


int main()
{
int main = 56;
printf("%d", main);
return 0;
}
a) Compiler Error
b) Depends on the compiler
c) 56
d) none of above
Answer: c
Explanation: main is not a keyword in C.

40. What is the output of the below c code?


#include<stdio.h>
int main()
{
char ch;
if(ch = printf(""))
printf("It matters\n");
else
printf("It doesn't matters\n");
return 0;
}
a) It matters
b) It doesn’t matters
c) Run time error
d) Nothing
Answer: b
Explanation: printf returns the number of characters successfully written on output.
Hence ch=0 and else statement executes.

41. What is the output of this C code?


#include<stdio.h>
int main()
{
int x=1, y=0,z=5;
int a=x&&y||++z;
printf("%d",z++);
}
a) 1
b) 5
c) 6
d) 7
Answer: c
Explanation: and operator doesnt operate if second argument is zero. & operator has more
precedence than ||

42. What is the output of this C code?


#define max(a) a
int main()
{
int x = 1;
switch (x)
{
case max(2):
printf("yes\n");
case max(1):
printf("no\n");
break;
}
}
a) yes
b) no
c) Runtime error
d) Compile time error
Answer: b
Explanation: Preprocessor just replaces whatever is given such that max(1) is replaced by 1
and switch case 1 is executed.

43.What is the output of this C code?


#include<stdio.h>
int main()
{
int x=35;
printf("%d %d %d",x==35,x=50,x>40);
return 0;
}
a) 1 50 1
b) 0 50 0
c) Runtime error
d) Compile time error

Answer: b
Explanation: Compiler executes right to left.

44. What is the output of this C code?


#include <stdio.h>
int main()
{
char chr;
chr = 128;
printf("%d\n", chr);
return 0;
}
a) 128
b) -128
c) Depends on the compiler
d) None of the mentioned
Answer: b
Explanation: signed char will be a negative number.

45. What is the output of this C code?


#include <stdio.h>
int main()
{
char *p[1] = {"hello"};
printf("%s", (p)[0]);
return 0;
}
a) Compile time error
b) Undefined behaviour
c) hello
d) None of the mentioned
Answer: c

46. Which among the following is NOT a logical or relational operator?


a) !=
b) ==
c) ||
d) =

Answer: d

47. Default storage class if not any is specified for a local variable, is auto
a) true
b) false
c) Depends on the standard
d) None of the mentioned

Answer: a

48.What will be the output of the program?


#include<stdio.h>
#include<math.h>
int main()
{
printf("%f\n", sqrt(36.0));
return 0;
}
A. 6.0
B. 6
C.6.000000
D.Error: Prototype sqrt() not found.
Answer: Option C
Explanation:

printf("%f\n", sqrt(36.0)); It prints the square root of 36 in the float format(i.e 6.000000).
Declaration Syntax: double sqrt(double x) calculates and return the positive square root of
the given number.

49. What is the output of this C code?


1. #include <stdio.h>
2. main()
3. {
4. int n = 0, m = 0;
5. if (n > 0)
6. if (m > 0)
7. printf("True");
8. else
9. printf("False");
10. }
a) True
b) False
c) No Output will be printed
d) Run Time Error
View Answer

Answer:c

50.What will be the output of program ?


#include<stdio.h>
int main( )
{
printf("nn /n/n nn/n");
return 0;
}

a.Nothing
b.nn /n/n nn
c.nn /n/n
d.Error
Show/Hide Answer
Answer = B
51. How many times will the following loop be executed?
ch = 'b';
while(ch >= 'a' && ch <= 'z')
A. 0 B. 25
C. 26 D. 1
View Answer & Explanation
Ans : B
52. Consider the following program fragment
switch(input)
{
case '1':
printf("One");
case '2':
printf("Two");
case '3':
printf(""Three");
default:
Printf("Default");
break;
}What will be printed when input is 2?

A. Two Three Default B. Two


C. Two Default D. Two Two Default
View Answer & Explanation
Ans : A

53. Consider the following 'C' program


#include<stdio.h>
int main()
{
int a=7, b=5;
switch(a = a % b)
{
case 1:
a = a - b;
case 2:
a = a + b;
case 3:
a = a * b;
case 4:
a = a / b;
default:
a = a;
}
return 0;
}On the execution of the above program what will be the value of a?

A. 7 B. 5
C. 2 D. None of the above
View Answer & Explanation
Ans : A
54.What is the output of the below code snippet?

#include<stdio.h>

main()
{
int a = 5, b = 3, c = 4;

printf("a = %d, b = %d\n", a, b, c);


}
A - a=5, b=3

B - a=5, b=3, c=0

C - a=5, b=3, 0

D - compile error

Answer : A

55. What is the output of the following program?

#include<stdio.h>

main()
{
int a[3] = {2,1};

printf("%d", a[a[1]]);
}
A-0

B-1

C-2

D-3

Answer : B

56. What is rightway to initialize array?


a.int num[6]={2,3,4,5,6,7}
b.int n(6)={1,2,3,4,5,6}
c.both a,b
d.int n{}={1,2,3,4,5,6}
ANS:a
57.What will be the output of the program?

#include<stdio.h>
#include<math.h>
int main()
{
float n=1.54;
printf("%f, %f\n", ceil(n), floor(n));
return 0;
}

A. 2.000000, 1.000000
B. 1.500000, 1.500000

C. 1.550000, 2.000000
D. 1.000000, 2.000000

Answer: Option A

58. What function should be used to free the memory allocated by calloc() ?

A. dealloc();
B. malloc(variable_name, 0)

C. free();
D. memalloc(variable_name, 0)

Answer: Option C

59.. Point out the correct statement which correctly free the memory pointed to by 's' and
'p' in the following program?

#include<stdio.h>
#include<stdlib.h>

int main()
{
struct ex
{
int i;
float j;
char *s
};
struct ex *p;
p = (struct ex *)malloc(sizeof(struct ex));
p->s = (char*)malloc(20);
return 0;
}

A. free(p); , free(p->s);
B. free(p->s); , free(p);

C. free(p->s);
D. free(p);
Answer: Option B

60. Which statement will you add in the following program to work it correctly?

#include<stdio.h>
int main()
{
printf("%f\n", log(36.0));
return 0;
}

A. #include<conio.h>
B. #include<math.h>

C. #include<stdlib.h>
D. #include<dos.h>

Answer: Option B

61. In a file contains the line "I am a boy\r\n" then on reading this
line into the array strusing fgets(). What will str contain?
A. "I am a boy\r\n\0" B. "I am a boy\r\0"

C. "I am a boy\n\0" D. "I am a boy"

Answer: Option C

Explanation:

Declaration: char *fgets(char *s, int n, FILE *stream);

fgets reads characters from stream into the string s. It stops when it
reads either n - 1 characters or a newline character, whichever comes
first.

Therefore, the string str contain "I am a boy\n\0"

You might also like