C MCQ Set-5 : Multiple Choice Questions in C Set-5

Set-26 C MCQ

1.What will be output of following code?

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

A)0 1 2 3 4 5
B)6
C)0 1 2 3 4 5 6
D)compilation error

Ans:B


2.What will be output of following code?

# include <stdio.h>
int main()
{
int loop=10;
while(printf(“Hello “) && loop–);
}

A)Hello
B)Hello Hello Hello Hello … (Infinite times)
C)Hello Hello Hello Hello …(10 times)
D)Hello Hello Hello Hello … (11 times)

Ans: D


3. What will be output of following code?

# include <stdio.h>
int main()
{
int i=6;
for(;i>0;i-=2);
printf(“%d”,i);
return 0;
}

A)6 4 3 2
B)0
C)6 5 4 3 2 1
D)compilation error

Ans: B


4. What will be output of following code?

# include <stdio.h>
int main()
{
unsigned int i = 65536; /* Assume 2 byte integer*/
while(i != 0)
printf(“%d”,++i);
return 0;
}
A.Infinite loop
B.0 1 2 … 65535
C.0 1 2 … 32767 – 32766 -32765 -1 0
D.No output

Ans: D


5. What will be output of following code?

# include<stdio.h>
int main()
{
int i = 0;
for (printf(“1st\n”); i < 2 && printf(“2nd\n”); ++i && printf(“3rd\n”))
{
printf(“*\n”);
}
return 0;
}

A)1st
2nd
*
3rd
2nd
*

B)1st
2nd
*
3rd
2nd
*
3rd

C)1st
2nd
3rd
*
2nd
3rd

D)1st
2nd
3rd
*
1st
2nd
3rd

Ans: B


6. What will be output of following code?

# include <stdio.h>
int main()
{
int i=1;
while(i<=5);
{
printf(“%d\n”,i);
i=i+1;
}
printf(“The value of i after the loop is %d”,i);
}

A)1 2 3 4 5
B)1
C)Compilation Error
D)infinite loop

Ans: D


7. What is the output of this program?

#include <stdio.h>
int demo()
{
static int i = 0;
printf(“%d “,i++);
}
int main()
{
for(int j = 0 ; j < 5 ; j++ )
{
demo();
}
}

A. 0 0 0 0 0
B. 1 1 1 1 1
C. 1 2 3 4 5
D. 0 1 2 3 4

Ans:D


8. What is the output of this program?

# include<stdio.h>
int test()
{
static int n = 10;
return n–;
}
int main()
{
for(test(); test(); test())
printf(“%d “, test());
return 0;
}

A. 7 4 1
B. 8 5 2
C. Infinite loop
D. Compilation Error

Ans:B
C MCQ Set-5 Explanation


9. What is the output of this program?

#include <stdio.h>
void test(int * , int *);
main()
{
int a = 5 , b = 6;
test(&a,&b);
printf(“%d %d”,a,b);
}
void test(int *p, int *q)
{
*p = *p * *q;
*q = *p / *q;
*p = *p / *q;
}

A. 30 5
B. 6 5
C. 5 6
D. None of the above

Ans:B
C MCQ Set-5 Explanation


10. What is the output of this program?

# include<stdio.h>
test(int *a, int *b)
{
a = b;
*a = 15;
}
int x = 10, y = 20;
int main()
{
test(&x, &y);
printf(“%d %d”, x, y);
return 0;
}

A. 15 15
B. 10 15
C. 10 20
D. 15 20

Ans:B


11. What is the output of the following?

# include<stdio.h>
int main()
{
int a = 5;
void *ptr = &a ;
printf(“%f”, *(float*)ptr);
return 0;
}

A. 5
B. 5.000000
C. 0.000000
D. 0

Ans:C
C MCQ Set-5 Explanation


12. What is the output of the following?

# include<stdio.h>
int main()
{
int a = 0 ;
int *const ptr = &a ;
printf(“%p “, ptr);
ptr++;
printf(“%p “, ptr);
}

A. 0 1
B. compilation Error
C. Run Time Error
D. None of the above

Ans:B


13. What is the output of the following?

# include <stdio.h>
int main()
{
int a = 5 ;
int *b = &a ;
int **c = &b ;
printf(“%d%d%d\n”, a, *b, **c);
}

A. 5 garbage value garbage value
B. 5 5 garbage value
C. 5 5 5
D. Error

Ans:C


14. What is the output of this program?

# include<stdio.h>
void test(int * , int *);
void main()
{
int a = 5 , b = 6;
test(&a,&b);
printf(“%d %d”,a,b);
}
void test(int *p, int *q)
{
*p = *p * *q;
*q = *p + *q;
*p = *p – *q;
}

A. -6 36
B. 6 36
C. 36 6
D. -6 -36

Ans:A


15. Pick the correct statements.

I. The body of a function should have only one return statement.
II. The body of a function may have many return statements.
III. A function can return only one value to the calling environment.
IV. return statement is mandatory.

A. I and II
B. I and III
C. II and III
D. II and IV

Ans:C


C MCQ Set-1
C MCQ Set-2
C MCQ Set-3
C MCQ SET 4
C MCQ Set-5

Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *