100% found this document useful (1 vote)
561 views11 pages

C MCQ Catest1

The document contains 35 practice questions related to C programming. Each question has multiple choice answers regarding the output of code snippets. Some questions test concepts like loops, conditional statements, operators, constants, type conversions etc. The questions would help students practice and test their understanding of basic C programming concepts.

Uploaded by

Syed Akram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
561 views11 pages

C MCQ Catest1

The document contains 35 practice questions related to C programming. Each question has multiple choice answers regarding the output of code snippets. Some questions test concepts like loops, conditional statements, operators, constants, type conversions etc. The questions would help students practice and test their understanding of basic C programming concepts.

Uploaded by

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

Department of Computer Applications

I BE-Mech(G1) , ECE (G1)


Practice Questions- 1

1. How many times Hello is printed?


void main()
{
int a = 0;
while(a++);
{
printf("Hello");
}
}
a) 0 time
b) 1 time
c) Compilation Error
d) Infinite times

2. What is output of below program?


void main()
{
int i;
for(i=0; i<5; i++);
{
printf("c program");
}
}
a) c program is printed 5 times
b) Compilation Error
c) c program is printed 1 time
d) Nothing is printed

3. What is output of below program?


void main()
{
const int a = 10;
printf("%d",++a);
}
a) 11
b) 10
c) Compilation Error
d) 0

4. #include <stdio.h>
int main()
{
int a = 10, b = 20;
if(a=b)
{
printf("Easy"); }
else
{
printf("Hard"); }

return 0;
}
(A) Easy
(B) Hard
(C) EasyHard
(D) Error in program

5. #include <stdio.h>
int main()
{
if(printf("C programming is "))
{
printf("Easy");
}
else
{
printf("Hard");
}

return 0;
}
A) Easy
(B) Hard
(C) C programming is Easy
(D) None of the above

6. #include <stdio.h>
int main()
{
int a = 0;
if(a = printf("How old are you?"))
{
printf(" %d - too young", a);
}
return 0;
}

(A) 0 - too young


(B) Compilation Error
(C) Nothing is printed
(D) How old are you? 16 - too young

7. #include<stdio.h>
int main()
{
int k;
k = (1,2,3,4,5);
printf("%d\n", k);

return 0;
}

a) 5
b) 1
c) 2
d) 4

8. #include<stdio.h>
int main()
{
int k;
k = 1,2,3,4,5;
printf("%d\n", k);
return 0;
}
a) 4
b) 1
c) 5
d) 2

9. How many times printf will be executed ?


#include<stdio.h>
int main()
{
int x;
for(x=0; x<=15; x++)
{
if(x < 5)
continue;
else
break;
printf("c4learn.com");
}
return 0;
}

a) 5 times
b) 0 times
c) 16 times
d) 15 times

10. int main()


{
for (5; 2; 2)
printf("Hello\n");
return 0;
}

a) compilation error
b) Hello
c) infinite loop
d) none of the above

11. #include<stdio.h>
int main()
{
int x = 10; // integer x
char y = 'a'; // character c
x = x + y;
float z = x + 1.0;
printf("x = %d, z = %f", x, z);
return 0;
}

Output:

12. #include<stdio.h>

int main()
{
double x = 1.2;
// Explicit conversion from double to int
int sum = (int)x + 1;
printf("sum = %d", sum);
return 0;
}
Output:

13. #include <stdio.h>

int main()
{
int i = 1, 2, 3;
printf("%d", i);
return 0;
}

a) 1
b) 3
c) Garbage value

d) Compile time error

14. #include <stdio.h>


int main()
{ int i = (1, 2, 3);
printf("%d", i);
return 0;
}

a) 1
b) 3
c) Garbage value
d) Compilation error

15. #include <stdio.h>

int main()
{
int i;
i = 1, 2, 3;
printf("%d", i);
return 0;
}
a) 1
b) 3
c) Garbage value
d) Compile time error

16. int main()


{
int a = 1;
int b = 1;
int c = a || --b;
int d = a-- && --b;
printf("a = %d, b = %d, c = %d, d = %d", a, b, c, d);
return 0;
}

a) a = 0, b = 1, c = 1, d = 0
b) a = 0, b = 0, c = 1, d = 0
c) a = 1, b = 1, c = 1, d = 1
d) a = 0, b = 0, c = 0, d = 0

17. #include <stdio.h>


int main()
{
int a = 10, b = 20, c = 30;
if (c > b > a)
printf("TRUE");
else
printf("FALSE");
return 0;
}
a) TRUE
b) FALSE
c) Compiler Error
d) Output is compiler dependent

18. Given i = 0, j = 1, k = –1 x = 0.5, y = 0.0 What is the output of the following


expression in C language ? x * y <i + j || k
a) -1
b) 0
c) 1
d) 2

19. Given that x = 7.5, j = -1.0, n = 1.0, m = 2.0 the value of - - x + j == x>n> = m
is:
a) 0
b) 1
c) 2
d) 3

20. #include <stdio.h>


int main()
{
int i = 0;
switch (i)
{
case '0': printf("Geeks");
break;
case '1': printf("Quiz");
break;
default: printf("GeeksQuiz");
}
return 0;
}

a) Geeks
b) Quiz
c) GeeksQuiz
d) Compile-time error

21. #include <stdio.h>


int main()
{
int i;
if (printf("0"))
i = 3;
else
i = 5;
printf("%d", i);
return 0;
}

Predict the output of above program?


a) 3
b) 5
c) 03
d) 05

22. #include<stdio.h>

int main()
{
int n;
for (n = 9; n!=0; n--)
printf("n = %d", n--);
return 0;
}

What is the output?


a) 9 7 5 3 1
b) 9 8 7 6 5 4 3 2 1
c) Infinite Loop
d) 9 7 5 3

23. #include <stdio.h>


int main()
{
int c = 5, no = 10;
do {
no /= c;
} while(c--);

printf ("%dn", no);


return 0;
}

a) 1
b) Runtime Error
c) 0
d) Compiler Error

24. How many times GeeksQuiz is printed


#include<stdio.h>
int main()
{
int i = -5;
while (i<= 5)
{
if (i>= 0)
break;
else
{
i++;
continue;
}
printf("GeeksQuiz");
}
return 0; }

a) 10 times
b) 5 times
c) Infinite times
d) 0 times

25. What will be the output of the following C code?


#include <stdio.h>
#define a 10
int main()
{
const int a = 5;
printf("a = %d\n", a);
}
a) a = 5
b) a = 10
c) Compilation error
d) Runtime error

26. What will be the output of the following C code?


#include <stdio.h>
int main()
{
const int p;
p = 4;
printf("p is %d", p);
return 0;
}
a) p is 4
b) Compile time error
c) Run time error
d) p is followed by a garbage value

27. . What will be the output of the following C code?


#include <stdio.h>
void main()
{
int const k = 5;
k++;
printf("k is %d", k);
}
a) k is 6
b) Error due to const succeeding int
c) Error, because a constant variable can be changed only twice
d) Error, because a constant variable cannot be changed

28. What will be the output of the following C code?


#include <stdio.h>
int main()
{
int x = 2, y = 0;
int z = (y++) ? y == 1 && x : 0;
printf("%d\n", z);
return 0;
}
a) 0
b) 1
c) Undefined behaviour
d) Compile time error

29. What will be the final value of c in the following C code snippet? (Initial values:
a = 1, b = 2, c = 1) c += (-c) ? a : b;

a) Syntax Error
b) c = 1
c) c = 2
d) c = 3

30. What will be the output of the following C code?


#include <stdio.h>
void main()
{
int b = 6;
int c = 7;
int a = ++b + c--;
printf("%d", a);
}

a) Run time error


b) 15
c) 13
d) 14

31. What will be the output of the following C code?


#include <stdio.h>
void main()
{
double b = 3 % 0 * 1 - 4 / 2;
printf("%lf", b);
}

a) -2
b) Floating point Exception
c) 1
d) None of the mentioned

32. What will be the output of the following C code?


#include <stdio.h>
int main()
{
int a = -1, b = 4, c = 1, d;
d = ++a && ++b || ++c;
printf("%d, %d, %d, %d\n", a, b, c, d);
return 0; }
a) 0, 4, 2, 1
b) 0, 5, 2, 1
c) -1, 4, 1, 1
d) 0, 5, 1, 0

33. Find the output of the following cases.

main()
{
int x;
printf("%d",scanf("%d",&x)); /* Suppose that input value for scanf is 20 */

34.
# include <stdio.h>
main()
{
int i=0;
for(i=0; i<20; i++)
{
switch(i)
{
case 0: i+=5;
case 1: i+=2;
case 5: i+=5;
default: i+=4;
break;
}
printf("%d ", i);
}

35.
#include <stdio.h>
int main()
{
int c = 5, no = 1000;
do {
no /= c;
} while(c--);

printf ("%d\n", no);


return 0;
}

You might also like