0% found this document useful (0 votes)
61 views90 pages

Practice MCQs

The document contains a series of multiple-choice questions (MCQs) focused on C programming concepts, including code output, pointer arithmetic, and array manipulation. It emphasizes understanding the underlying concepts rather than memorizing answers, encouraging systematic practice and review of mistakes. Each question is accompanied by a correct answer and aims to enhance problem-solving skills in C programming.

Uploaded by

rohitsi1620
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
0% found this document useful (0 votes)
61 views90 pages

Practice MCQs

The document contains a series of multiple-choice questions (MCQs) focused on C programming concepts, including code output, pointer arithmetic, and array manipulation. It emphasizes understanding the underlying concepts rather than memorizing answers, encouraging systematic practice and review of mistakes. Each question is accompanied by a correct answer and aims to enhance problem-solving skills in C programming.

Uploaded by

rohitsi1620
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/ 90

C Programming Practice MCQs

Important Instructions:

Do not memorize the answers provided. The goal is to understand the concepts behind each

question.
If you encounter any questions where the answer is unclear or you don’t understand why a particular

answer is correct, feel free to reach out to me. I’ll be happy to explain it to you.
These questions are meant for practice and do not guarantee that these exact questions
will appear on your exam. Use them to enhance your understanding of key concepts, not to predict

the exam content.


Focus on improving your problem-solving skills and understanding the logic behind the questions.
Work through the questions systematically and review your mistakes to strengthen your grasp of

the subject.
Do not only focus on the correct answer. Also, review why the other options were incorrect. This
way, you will gain a deeper understanding of the concepts and avoid common pitfalls.

1. What is the output of the following code?

#include <stdio.h>
int main() {
int a = 5, b = 10;

printf("%d", a+++b);
return 0;

A) 15

B) 16
C) 14

D) Compilation error

Answer: C

2. What will be the value printed?


#include <stdio.h>

int main() {
int a = 10;

int *p = &a;

*p += 2;
printf("%d", a);

return 0;

A) 10

B) 12
C) Garbage
D) Compilation error

Answer: B

3. What character will be printed?

#include <stdio.h>
int main() {
char str[] = "ABCDE";

printf("%c", *(str + 3));


return 0;
}

A) A

B) B
C) D
D) E

Answer: C

4. Output of accessing array element:

#include <stdio.h>

int main() {
int a[] = {1, 2, 3};
printf("%d", *(a + 1));

return 0;
}

A) 1
B) 2

C) 3
D) Garbage
Answer: B

5. What happens here?

#include <stdio.h>
int main() {

int *p = NULL;
printf("%d", *p);
return 0;

A) 0
B) Garbage

C) Segmentation Fault
D) Compilation Error

Answer: C

6. What does the loop print?

#include <stdio.h>

int main() {
int i = 0;

for (; i < 3; printf("%d", i++));

return 0;
}
A) 012
B) 123

C) 234

D) 345
Answer: A

7. Which string gets printed?

#include <stdio.h>

int main() {

char str[] = "World";


printf("%s", str + 2);

return 0;

A) World
B) orld

C) rld

D) rld
Answer: C

8. Output of this pointer arithmetic?

#include <stdio.h>

int main() {

char *p = "Hello";
printf("%c", *++p);

return 0;
}

A) H

B) e
C) l

D) Error

Answer: B
9. What does this code print?

#include <stdio.h>
int main() {

int x = 5;

printf("%d", x++);
return 0;

A) 6

B) 5
C) 4

D) Garbage

Answer: B

10. What will be the output?

#include <stdio.h>
int main() {

int arr[] = {10, 20, 30, 40};

printf("%d", *(arr + *(arr + 1)/10));


return 0;

A) 10

B) 20

C) 30
D) 40

Answer: C

11. How many bytes will sizeof return?

#include <stdio.h>

int main() {
int arr[10];
printf("%lu", sizeof(arr));
return 0;

A) 10
B) 40

C) 4
D) Depends on platform

Answer: B

12. What will be the output?

#include <stdio.h>
int main() {
int a = 1;

if (a = 0)
printf("Zero");
else

printf("Non-zero");
return 0;
}

A) Zero
B) Non-zero
C) Compilation error

D) Runtime error
Answer: B

13. What happens here?

#include <stdio.h>
int main() {

char s[] = "abc";


s[1] = '\0';
printf("%s", s);
return 0;
}

A) abc
B) a
C) ab

D) Error
Answer: B

14. Output of this loop?

#include <stdio.h>
int main() {

int i;
for (i = -1; i < 5; i++) {
if (i == 0)

continue;
printf("%d ", i);
}

return 0;
}

A) -1 1 2 3 4

B) -1 0 1 2 3 4
C) -1 1 2 3 4 5
D) Compilation error

Answer: A

15. What does main() return in C by default?


A) 0
B) 1

C) Depends on compiler
D) Garbage
Answer: A
16. Which of the following is true for a char* in C?
A) It can be used as a string

B) It must always point to malloc 'ed memory


C) It’s invalid syntax
D) It cannot be incremented

Answer: A

17. Output?

#include <stdio.h>
int main() {
char *s = "pointer";

printf("%c", s[3]);
return 0;
}

A) p
B) o
C) i

D) n
Answer: D

18. What happens?

#include <stdio.h>
int main() {

int i = 0;
while (i < 3)
printf("%d", i++);

return 0;
}

A) 012

B) 123
C) 234
D) Compilation error

Answer: A

19. Output?

#include <stdio.h>
int main() {
char str[5] = "Hello";

printf("%s", str);
return 0;
}

A) Hello
B) Compile error
C) Hel

D) Garbage
Answer: B

20. What is the output of the loop?

#include <stdio.h>
int main() {
int a = 1;

do {
printf("%d ", a);
a++;

} while (a < 4);


return 0;
}

A) 1 2
B) 1 2 3

C) 1 2 3 4
D) 1 2 3 4 5
Answer: B
21. Output?

#include <stdio.h>

int main() {
char *s = "C Programming";
printf("%s", s + 2);

return 0;
}

A) C Programming

B) Programming
C) Programming
D) Programming

Answer: D

22. Result of:

#include <stdio.h>
int main() {
int a = 10;

printf("%d %d", a++, ++a);


return 0;
}

A) 10 12
B) 11 12
C) Undefined behavior

D) 10 11
Answer: C

23. What is printed?

#include <stdio.h>
int main() {

int a[] = {1,2,3,4};


printf("%d", 2[a]);
return 0;
}

A) 2
B) 3
C) Error

D) Garbage
Answer: B

24. Output of this loop:

#include <stdio.h>
int main() {

for (int i = 0; i < 5; i++)


if (i == 2)

break;

else
printf("%d", i);

return 0;

A) 01
B) 012

C) 1234

D) 0
Answer: A

25. What will be printed?

#include <stdio.h>

int main() {

int a = 5;
printf("%d %d %d", a, a<<1, a>>1);
return 0;

A) 5 10 2

B) 5 20 1

C) 5 2 10
D) 5 5 5

Answer: A

26. What will be the output?

#include <stdio.h>

int main() {
int a = 10, b = 20;

printf("%d", b+++a);

return 0;
}

A) 30

B) 31

C) 29
D) Compilation error

Answer: C

27. What does this code print?

#include <stdio.h>

int main() {
char *p = "ABCDE";

printf("%c", *(&p[1] + 1));

return 0;
}

A) A
B) B
C) C
D) D

Answer: C

28. What will be the output of this pointer operation?

#include <stdio.h>
int main() {

int a = 10;

int *p = &a;
printf("%d", *p++);

return 0;

A) 10

B) Garbage

C) Compilation error
D) Undefined

Answer: A

29. What happens when this runs?

#include <stdio.h>

int main() {
int a = 5;

int b = 2;

printf("%d", a/b);
return 0;

A) 2.5

B) 2
C) 3

D) Error

Answer: B
30. Output of this loop?

#include <stdio.h>

int main() {

for (int i = 0; i < 5; i++);


printf("Hello");

return 0;

A) Hello
B) HelloHelloHelloHelloHello

C) Compilation error

D) Hello printed once


Answer: D

31. What gets printed?

#include <stdio.h>

int main() {

int arr[3] = {1,2,3};


printf("%d", arr[1]);

return 0;

A) 1

B) 2

C) 3
D) Garbage

Answer: B

32. Output of this code:

#include <stdio.h>
int main() {

int i = 0;
while (i++ < 3)

printf("%d", i);

return 0;
}

A) 123
B) 012

C) 134

D) 1234
Answer: A

33. What happens here?

#include <stdio.h>

int main() {

int x = 5;
int y = ++x + x++;

printf("%d", y);

return 0;
}

A) 11

B) 12

C) 13
D) Undefined behavior

Answer: D

34. Output of this string operation?

#include <stdio.h>

int main() {
char str[] = "Exam";

str[1] = 'r';

printf("%s", str);
return 0;
}

A) Exam
B) Eram

C) Eeam

D) Error
Answer: B

35. Result of this character addition:

#include <stdio.h>

int main() {

char c = 'A' + 1;
printf("%c", c);

return 0;

A) A
B) B

C) C

D) Compilation error
Answer: B

36. What is printed?

#include <stdio.h>

int main() {

int a = 10;
int b = 5;

printf("%d", a && b);

return 0;
}
A) 1

B) 0
C) 5

D) 10

Answer: A

37. Identify the output:

#include <stdio.h>
int main() {

int arr[3] = {10};

printf("%d %d", arr[0], arr[2]);


return 0;

A) 10 0
B) 10 garbage

C) garbage garbage

D) Compilation error
Answer: A

38. What is printed?

#include <stdio.h>

int main() {

int i = 2;
printf("%d", i << 1);

return 0;

A) 2

B) 4

C) 1
D) 3

Answer: B
39. What is the result?

#include <stdio.h>

int main() {
printf("%d", sizeof("GLA"));

return 0;

A) 3

B) 4

C) 5
D) 2

Answer: B

40. What is the output?

#include <stdio.h>

int main() {
int a = 1;

int b = 0;

printf("%d", a || b);
return 0;

A) 1
B) 0

C) Error

D) Compilation fail
Answer: A

41. What is printed?

#include <stdio.h>

int main() {

char str[4] = "Hi";


printf("%s", str);
return 0;

A) Hi

B) H

C) Error
D) Garbage

Answer: A

42. Choose the correct output:

#include <stdio.h>

int main() {
int a = 5;

int b = 2;

float c = (float)a / b;
printf("%.2f", c);

return 0;

A) 2.50
B) 2

C) 2.0

D) Compilation error
Answer: A

43. What does this output?

#include <stdio.h>

int main() {

int arr[] = {5, 10, 15};


printf("%d", *(arr + 2));

return 0;

}
A) 5

B) 10
C) 15

D) Garbage

Answer: C

44. Which value is printed?

#include <stdio.h>
int main() {

int a = 2;

printf("%d", a << 2);


return 0;

A) 4
B) 6

C) 8

D) 16
Answer: C

45. What is printed?

#include <stdio.h>

int main() {

int a = 5;
int b = 3;

printf("%d", a & b);

return 0;
}

A) 1

B) 0
C) 3
D) 5

Answer: A

46. Choose the output:

#include <stdio.h>

int main() {
int a = 10;

printf("%d", ~a);
return 0;

A) -10
B) -11

C) 11

D) Error
Answer: B

47. Which of the following is a valid pointer assignment?

A) int *p = 10;
B) int *p = NULL;

C) int p = &a;

D) None
Answer: B

48. Which statement is true about arrays in C?


A) Array size can be changed at runtime

B) Array index starts from 1

C) Array elements are stored in contiguous memory


D) Arrays store different data types

Answer: C

49. Output?
#include <stdio.h>

int main() {

int arr[] = {1,2,3,4};


printf("%d", *(arr+3));

return 0;

A) 1

B) 2

C) 3

D) 4

Answer: D

50. What will be printed?

#include <stdio.h>

int main() {
char str[] = "Hello";

printf("%c", 3[str]);

return 0;

A) l

B) o

C) e

D) Error

Answer: A

51. What will be the output?

#include <stdio.h>
int main() {

char str[] = "World";

printf("%c", *(str + 4));


return 0;

A) r

B) d

C) o

D) l
Answer: B

52. What will be printed?

#include <stdio.h>

int main() {

int i = 0;

do {

printf("%d", i);

i++;
} while (i < 3);

return 0;

A) 012

B) 123

C) 01

D) Infinite loop

Answer: A

53. Identify the output:

#include <stdio.h>

int main() {
int x = 3;

int y = x++ + ++x;

printf("%d", y);
return 0;
}

A) 7

B) 8
C) 9

D) Undefined

Answer: C

54. What will this program output?

#include <stdio.h>

int main() {

char ch = 'A';

printf("%d", ch);
return 0;

A) 65
B) A

C) Compilation error

D) Garbage

Answer: A

55. What is the output of this code?

#include <stdio.h>

int main() {

int arr[2][2] = {{1,2},{3,4}};


printf("%d", arr[1][0]);

return 0;

A) 1

B) 2
C) 3

D) 4

Answer: C

56. What is printed?

#include <stdio.h>

int main() {

int i = 5;
while(i-- > 0)

printf("%d", i);

return 0;

A) 54321

B) 43210

C) 543210

D) 4321

Answer: B

57. Output of the following:

#include <stdio.h>
int main() {

int a = 5;

int b = 0;

printf("%d", a && b++);

printf("%d", b);

return 0;
}

A) 10

B) 01
C) 00

D) 01

Answer: C
58. Result of this expression:

#include <stdio.h>

int main() {

int a = 10;
printf("%d", a >> 1);

return 0;

A) 5

B) 10

C) 20

D) 0

Answer: A

59. What does this print?

#include <stdio.h>

int main() {
char str[] = "abcdef";

printf("%c", *(str + 2));

return 0;

A) a

B) b

C) c

D) d

Answer: C

60. Output of the code below:

#include <stdio.h>
int main() {

char *p = "pointer";
printf("%c", *p + 1);
return 0;

A) q
B) p

C) o

D) Compilation error

Answer: A

61. Output of this program:

#include <stdio.h>

int main() {

int x = 5;
int y = x++ * 2;

printf("%d", y);

return 0;

A) 10

B) 12

C) 11

D) 6

Answer: A

62. Which of these is correct about void* ?

A) Can store address of any type

B) Cannot be dereferenced directly


C) Needs to be typecast before use

D) All of the above

Answer: D

63. Output?
#include <stdio.h>

int main() {

int arr[] = {1,2,3};


int *p = arr;

printf("%d", *(p + 1));

return 0;

A) 1

B) 2

C) 3

D) Garbage

Answer: B

64. What is the result of this loop?

#include <stdio.h>
int main() {

int i = 0;

while (++i < 3)

printf("%d", i);

return 0;

A) 01

B) 12

C) 123
D) 234

Answer: B

65. Output of this nested loop:

#include <stdio.h>

int main() {

for (int i = 0; i < 2; i++)


for (int j = 0; j < 2; j++)

printf("*");

return 0;
}

A) **

B) ****
C) \n

D) \n\n

Answer: B

66. What is the output of this?

#include <stdio.h>

int main() {

int a = 2;

printf("%d", a == 2 ? 5 : 10);
return 0;

A) 5
B) 10

C) 2

D) Error

Answer: A

67. What does the following code print?

#include <stdio.h>

int main() {

char str[] = "abcde";


printf("%s", str + 2);

return 0;

}
A) abcde

B) cde

C) e

D) b

Answer: B

68. Output of:

#include <stdio.h>
int main() {

int arr[5] = {0};

printf("%d", arr[3]);

return 0;

A) 0

B) Garbage

C) 3

D) Compilation error
Answer: A

69. What will happen?

#include <stdio.h>

int main() {

int *p;

*p = 10;

printf("%d", *p);

return 0;
}

A) 10

B) 0
C) Segmentation fault
D) Compilation error

Answer: C

70. What does this return?

#include <stdio.h>

int main() {

int a = 0;

if (a = 5)
printf("Yes");

else

printf("No");

return 0;

A) Yes

B) No

C) Compilation error

D) Nothing
Answer: A

71. What will be printed?

#include <stdio.h>

int main() {

char c = 255;

printf("%d", c);

return 0;

A) 255

B) -1

C) 0
D) Error

Answer: B
72. What will this print?

#include <stdio.h>

int main() {

char *s = "abc";

s++;

printf("%s", s);
return 0;

A) abc
B) bc

C) c

D) Compilation error

Answer: B

73. Choose the correct output:

#include <stdio.h>

int main() {

int i = 1;
while (i < 5) {

if (i == 3) break;

printf("%d", i);

i++;

return 0;
}

A) 123

B) 12
C) 1

D) 13

Answer: B
74. Which statement about pointers is FALSE?

A) They hold memory addresses

B) int *p means p is a pointer to int

C) *p gives the address of p

D) NULL is often used to initialize pointers


Answer: C

75. What is the output?

#include <stdio.h>

int main() {

int a = 3;

int b = 4;

printf("%d", a^b);

return 0;
}

A) 7

B) 0
C) 5

D) 1

Answer: C

76. What will be printed?

#include <stdio.h>

int main() {

int a = 2;

int b = 3;
printf("%d", a+++b);

return 0;

A) 6

B) 5
C) 4

D) Compilation error

Answer: B

77. What does this print?

#include <stdio.h>

int main() {

char str[] = "hello";


printf("%c", *(&str[1]));

return 0;

A) h

B) e

C) l

D) Compilation error

Answer: B

78. What is the result?

#include <stdio.h>

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

a = a++ + ++b;

printf("%d", a);

return 0;

A) 7

B) 8

C) 9

D) 10
Answer: C
79. Choose output:

#include <stdio.h>

int main() {

int i = 0;

for (; i < 3; )

printf("%d", i++);
return 0;

A) 012
B) 123

C) 01

D) 1234

Answer: A

80. What is printed?

#include <stdio.h>

int main() {

char s[] = "xyz";


printf("%d", sizeof(s));

return 0;

A) 3

B) 4

C) 2

D) Garbage

Answer: B

81. Output of this snippet:

#include <stdio.h>

int main() {
int i = 10;
printf("%d", i++ + i++);

return 0;

A) 20

B) 21

C) 19

D) Undefined

Answer: B

82. What will happen?

#include <stdio.h>

int main() {
int *ptr = NULL;

printf("%d", *ptr);

return 0;

A) 0

B) NULL

C) Segmentation fault

D) Compilation error

Answer: C

83. What does this print?

#include <stdio.h>
int main() {

char str[] = "abc";

str[1] = '\0';

printf("%s", str);

return 0;

}
A) abc

B) a

C) b
D) ab

Answer: B

84. What is the output?

#include <stdio.h>

int main() {

char *s = "C Language";

printf("%c", *(s + 2));

return 0;
}

A) C

B) a
C) L

D) Space

Answer: D

85. What is printed?

#include <stdio.h>

int main() {

int a = 5;

int *p = &a;
*p += 2;

printf("%d", a);

return 0;

A) 5

B) 2

C) 7
D) Garbage

Answer: C

86. Output of:

#include <stdio.h>

int main() {
int i = 0;

for (; i < 5; i++);

printf("%d", i);

return 0;

A) 4

B) 5

C) 0

D) Compilation error
Answer: B

87. What is the output?

#include <stdio.h>

int main() {

int x = 10;

int y = 5;

int z = x > y ? x : y;

printf("%d", z);
return 0;

A) 10
B) 5

C) 15

D) 0

Answer: A
88. Identify the result:

#include <stdio.h>

int main() {

int arr[3] = {1,2,3};


printf("%d", *(arr + 2));

return 0;

A) 1

B) 2

C) 3

D) Compilation error

Answer: C

89. What will this print?

#include <stdio.h>

int main() {
char s1[] = "abc", s2[] = "def";

printf("%s", strcat(s1, s2));

return 0;

A) abc

B) def

C) abcdef

D) Compilation error

Answer: C

90. What is the output?

#include <stdio.h>
int main() {

int a = 5;
printf("%d", !a);

return 0;

A) 0

B) 1

C) 5

D) -1

Answer: A

91. Choose the correct output:

#include <stdio.h>
int main() {

int a = 10;

int b = 3;

printf("%d", a % b);

return 0;

A) 1

B) 2

C) 3
D) 0

Answer: B

92. What is the output?

#include <stdio.h>

int main() {

int x = 1;

x = x << 3;

printf("%d", x);
return 0;

}
A) 3
B) 6

C) 8

D) 1

Answer: C

93. Output?

#include <stdio.h>

int main() {

char s[] = "hi";


printf("%d", sizeof(s));

return 0;

A) 2

B) 3

C) 4

D) Compilation error

Answer: B

94. What is printed?

#include <stdio.h>

int main() {
int i = 0;

while (i < 3) {

if (i == 1)

continue;

printf("%d", i);

i++;
}

return 0;

}
A) 0

B) 012

C) 02

D) Infinite loop

Answer: D

95. Output?

#include <stdio.h>
int main() {

int a = 3;

int b = 4;

printf("%d", a & b);

return 0;

A) 0

B) 1

C) 2
D) 0

Answer: C

96. What does this output?

#include <stdio.h>

int main() {
int a = 5;

printf("%d", ~a);

return 0;

A) 5

B) -6

C) -5
D) 0

Answer: B

97. Choose correct output:

#include <stdio.h>
int main() {

char s[5] = "Hi";

printf("%s", s);

return 0;

A) Hi

B) H

C) Compilation error

D) Garbage

Answer: A

98. Output of the code:

#include <stdio.h>

int main() {

char *s = "abc";

printf("%c", *(s + 1));

return 0;

A) a

B) b

C) c
D) Compilation error

Answer: B

99. What is the output?


#include <stdio.h>

int main() {

int a = 5;

int *p = &a;

printf("%p", p);

return 0;

A) Address of a

B) 5

C) Error

D) 0

Answer: A

100. What will be printed?

#include <stdio.h>

int main() {
int x = 5;

int y = 2;

printf("%f", (float)(x / y));

return 0;

A) 2.0

B) 2.5

C) 5.0

D) Compilation error

Answer: A

Here’s Part 5 (Questions 101–125) of your C Programming MCQ Question Bank.

Focus: Pointers, Arrays, Strings, Loops, Difficulty: Moderate to Difficult.

101. What will this code output?


#include <stdio.h>

int main() {
int arr[] = {10, 20, 30};

printf("%d", *(arr + 1));

return 0;

A) 10

B) 20

C) 30

D) Compilation error

Answer: B

102. Result of execution:

#include <stdio.h>

int main() {

char s[] = "abcde";

printf("%c", s[5]);

return 0;

A) e

B) Null character

C) Garbage

D) Compilation error
Answer: B

103. What does the code output?

#include <stdio.h>

int main() {

int a = 5;

int *ptr = &a;

printf("%d", *ptr + 1);


return 0;

A) 5

B) 6

C) Compilation error
D) Garbage

Answer: B

104. What happens here?

#include <stdio.h>

int main() {

int x = 2;

printf("%d", x++ * ++x);

return 0;

A) 6

B) 8

C) Undefined

D) 4

Answer: C

105. Choose output:

#include <stdio.h>

int main() {

int i = 0;

do {
printf("%d", i);

} while(i < 3);

return 0;

}
A) 012

B) 0

C) Infinite loop

D) 000…

Answer: C

106. What is the result?

#include <stdio.h>

int main() {

int i = 3;

int j = i++;

printf("%d %d", i, j);

return 0;
}

A) 4 3

B) 3 4
C) 4 4

D) 3 3

Answer: A

107. What is printed?

#include <stdio.h>

int main() {

int a = 5;

printf("%d", ++a + a++);

return 0;

A) 10

B) 11

C) 12
D) Undefined

Answer: D

108. Output of:

#include <stdio.h>

int main() {

int arr[3] = {1};

printf("%d %d %d", arr[0], arr[1], arr[2]);

return 0;

A) 1 0 0

B) 1 1 1

C) Garbage values

D) Compilation error

Answer: A

109. Output of this code:

#include <stdio.h>

int main() {
char s1[10] = "abc";

char s2[] = "def";

strcat(s1, s2);

printf("%s", s1);

return 0;

A) abc

B) def

C) abcdef

D) Compilation error

Answer: C
110. What will be printed?

#include <stdio.h>

int main() {

int a = 10;

int b = 4;
printf("%d", a / b);

return 0;

A) 2

B) 2.5

C) 3

D) 10

Answer: A

111. What is the output?

#include <stdio.h>

int main() {

char s[] = "abc";

printf("%c", s[3]);

return 0;

A) c

B) Garbage

C) Null character

D) Compilation error

Answer: C

112. Identify the result:

#include <stdio.h>
int main() {
char *s = "hello";

printf("%c", *s++);

return 0;

A) h

B) e

C) Compilation error

D) Undefined

Answer: A

113. What is the output?

#include <stdio.h>
int main() {

int x = 0;

if (x = 5)

printf("Yes");

else

printf("No");

return 0;

A) Yes

B) No

C) Compilation error

D) Runtime error

Answer: A

114. Output of this:

#include <stdio.h>

int main() {

char ch = 255;
printf("%d", ch);
return 0;

A) 255

B) -1

C) Compilation error

D) Garbage

Answer: B

115. What will be printed?

#include <stdio.h>

int main() {

char str[] = "C Prog";

str[1] = '\0';

printf("%s", str);

return 0;

A) C

B) Prog

C) C Prog
D) Empty

Answer: A

116. What is printed?

#include <stdio.h>

int main() {

int a = 3;

int b = 5;

a ^= b;

b ^= a;

a ^= b;

printf("%d %d", a, b);


return 0;

A) 3 5

B) 5 3

C) Compilation error
D) 8 8

Answer: B

117. Output?

#include <stdio.h>

int main() {

printf("%d", sizeof('A'));

return 0;

A) 1

B) 2

C) 4

D) 8

Answer: C

118. What is the output?

#include <stdio.h>

int main() {

int a = 10;

int b = 0;

if (b && (a / b))
printf("Yes");

else

printf("No");

return 0;

}
A) Yes

B) No

C) Runtime error

D) Compilation error

Answer: B

119. Output of:

#include <stdio.h>

int main() {

int a = 4;

printf("%d", a << 1);

return 0;

A) 8

B) 2

C) 4
D) 0

Answer: A

120. What does this output?

#include <stdio.h>

int main() {

int a = 5;

printf("%d", a == 5 && a == 6);

return 0;

A) 0

B) 1

C) 5

D) 6

Answer: A
121. Choose correct output:

#include <stdio.h>

int main() {

char ch = 'A' + 1;

printf("%c", ch);
return 0;

A) A
B) B

C) C

D) Compilation error

Answer: B

122. What will be printed?

#include <stdio.h>

int main() {

char str[] = "abcde";

str[2] = '\0';

printf("%s", str);

return 0;

A) abcde

B) ab

C) abc

D) a

Answer: B

123. Output?

#include <stdio.h>
int main() {
int a = 1, b = 2;

int c = (a, b);


printf("%d", c);

return 0;

A) 1

B) 2

C) 3

D) Compilation error

Answer: B

124. What is the result?

#include <stdio.h>

int main() {

char s1[10] = "GLA";

char s2[] = "TCS";

strcat(s1, s2);

printf("%s", s1);

return 0;

A) GLATCS

B) GLA

C) TCS
D) Compilation error

Answer: A

125. Choose output:

#include <stdio.h>

int main() {

int arr[3] = {10, 20, 30};

printf("%d", *(arr + 3));


return 0;

A) 30

B) 0

C) Garbage

D) Compilation error

Answer: C

126. What will this print?

#include <stdio.h>

int main() {

int a = 10;
int *p = &a;

printf("%p", p);

return 0;

A) Address of a in hexadecimal

B) Value of a

C) Compilation error

D) Garbage

Answer: A

127. What is the output?

#include <stdio.h>

int main() {

char str[] = "Hello";

str[0] = 'M';

printf("%s", str);

return 0;

}
A) Hello

B) Mello
C) H

D) Compilation error

Answer: B

128. What will be printed?

#include <stdio.h>

int main() {

int a = 5;

printf("%d", a+++a);

return 0;

A) 10

B) 9

C) Compilation error

D) Undefined

Answer: B

129. Output of:

#include <stdio.h>

int main() {

char s[] = "abc";


printf("%d", sizeof(s));

return 0;

A) 3

B) 4

C) 5

D) Compilation error

Answer: B
130. Identify the result:

#include <stdio.h>

int main() {

int arr[5] = {0};

printf("%d", arr[4]);

return 0;

A) 0

B) Garbage

C) Compilation error

D) Undefined

Answer: A

131. What happens here?

#include <stdio.h>
int main() {

int a = 0;

if (!a)

printf("Zero");

else

printf("Non-zero");

return 0;

A) Zero

B) Non-zero

C) Compilation error

D) No output

Answer: A

132. Output of:


#include <stdio.h>

int main() {

char *str = "C Programming";

printf("%c", *(str + 2));

return 0;

A) C

B) Space

C) o

D) P

Answer: B

133. What will be printed?

#include <stdio.h>

int main() {

int x = 5;
int y = x++ + ++x;

printf("%d", y);

return 0;

A) 11

B) 10

C) 12

D) Undefined

Answer: C

134. What is the result?

#include <stdio.h>

int main() {

int arr[] = {1, 2, 3, 4};

printf("%d", *(arr + 2));


return 0;

A) 2

B) 3

C) 4

D) Compilation error

Answer: B

135. Choose output:

#include <stdio.h>

int main() {

char str1[10] = "abc";

char str2[] = "xyz";

strcpy(str1, str2);

printf("%s", str1);

return 0;
}

A) abc

B) xyz
C) abcxyz

D) Compilation error

Answer: B

136. What does this code print?

#include <stdio.h>

int main() {

int a = 3;

printf("%d", a << 2);

return 0;

}
A) 3

B) 6

C) 12

D) 1

Answer: C

137. Output?

#include <stdio.h>

int main() {
int i = 0;

while (i++ < 3)

printf("%d", i);

return 0;

A) 123

B) 012

C) 134

D) 1234

Answer: A

138. What is printed?

#include <stdio.h>

int main() {

int x = 5, y = 10;

printf("%d", x > y ? x : y);

return 0;

A) 5

B) 10

C) 15
D) Compilation error

Answer: B

139. Result of this code:

#include <stdio.h>

int main() {

int arr[] = {1, 2, 3};

printf("%lu", sizeof(arr)/sizeof(arr[0]));

return 0;
}

A) 2

B) 3
C) 4

D) 12

Answer: B

140. Output of:

#include <stdio.h>

int main() {

char str[] = "abcd";

printf("%c", *(str + 2));

return 0;

A) a

B) b

C) c

D) d

Answer: C

141. What will be printed?


#include <stdio.h>

int main() {
int a = 1;

int b = 2;

int c = a++ + b++;

printf("%d %d %d", a, b, c);

return 0;

A) 1 2 3

B) 2 3 3

C) 2 2 4

D) 2 3 4

Answer: B

142. What does this result in?

#include <stdio.h>

int main() {

int x = 2;

printf("%d", x * (x + 1));

return 0;
}

A) 2

B) 4
C) 6

D) 8

Answer: C

143. Output of this:

#include <stdio.h>

int main() {

int arr[3] = {5, 10, 15};


printf("%d", arr[3]);

return 0;
}

A) 15

B) 0
C) Garbage

D) Compilation error

Answer: C

144. What will be printed?

#include <stdio.h>

int main() {

char s[] = "123";

int i = atoi(s);

printf("%d", i);

return 0;

A) 123

B) 0

C) Compilation error

D) Garbage

Answer: A

145. Identify output:

#include <stdio.h>

int main() {
int x = 10;

if (x > 5)

if (x < 20)

printf("Yes");

else

printf("No");
return 0;

A) Yes

B) No

C) Compilation error

D) Nothing

Answer: A

146. Output?

#include <stdio.h>

int main() {

char s1[] = "abc";


char s2[] = "abc";

if (s1 == s2)

printf("Equal");

else

printf("Not Equal");

return 0;

A) Equal

B) Not Equal

C) Compilation error

D) Depends

Answer: B

147. What is printed?

#include <stdio.h>

int main() {

char *s = "hello";

s++;
printf("%s", s);
return 0;

A) hello

B) ello

C) llo

D) Compilation error

Answer: B

148. Result of this code:

#include <stdio.h>

int main() {

int i = 10;

int *p = &i;

*p = 20;

printf("%d", i);

return 0;
}

A) 10

B) 20

C) Garbage
D) Compilation error

Answer: B

149. What will be printed?

#include <stdio.h>

int main() {

char s[] = "hello";

s[1] = '\0';

printf("%s", s);

return 0;

}
A) hello

B) h

C) he

D) Empty

Answer: B

150. Output of:

#include <stdio.h>

int main() {
int x = 1;

int y = 0;

printf("%d", x || y && x);

return 0;

A) 1

B) 0

C) Compilation error

D) Undefined

Answer: A

151. What is the output?

#include <stdio.h>

int main() {

char str[] = "abcdef";

printf("%c", *(str + 4));

return 0;

A) a

B) d

C) e
D) f

Answer: C

152. What does this program print?

#include <stdio.h>

int main() {

int x = 5;

printf("%d", ++x + x++);

return 0;
}

A) 10

B) 11
C) 12

D) Undefined

Answer: C

153. Output?

#include <stdio.h>

int main() {

char *p = "abcde";

printf("%c", *(p + 3));

return 0;

A) c

B) d

C) e

D) b

Answer: B

154. What happens here?


#include <stdio.h>

int main() {
char str[] = "123";

printf("%d", atoi(str) + 10);

return 0;

A) 123

B) 133

C) Compilation error

D) Runtime error

Answer: B

155. Output of:

#include <stdio.h>

int main() {

int x = 10;

int y = 20;

printf("%d", x & y);

return 0;

A) 10

B) 0

C) 20
D) 8

Answer: D

156. What will be the output?

#include <stdio.h>

int main() {

int arr[5] = {1, 2, 3, 4, 5};

int *p = arr;
printf("%d", *(p + 3));

return 0;
}

A) 1

B) 3
C) 4

D) 5

Answer: C

157. What is printed?

#include <stdio.h>

int main() {

int a = 5;

printf("%d", a *= 2 + 3);

return 0;

A) 10

B) 15

C) 25

D) 30

Answer: B

158. Output of:

#include <stdio.h>

int main() {

int i;
for (i = 0; i < 5; i++) {

if (i == 2) break;

printf("%d", i);

}
return 0;

A) 0 1 2

B) 0 1

C) 0

D) 1 2

Answer: B

159. Output?

#include <stdio.h>

int main() {

char str[5] = "ABCD";


printf("%s", str);

return 0;

A) ABCD
B) ABCDE

C) AB

D) Compilation error

Answer: A

160. Identify the result:

#include <stdio.h>

int main() {

char s[] = "hello";

printf("%d", sizeof(s));

return 0;

A) 5

B) 6
C) 10

D) Undefined

Answer: B

161. Output of this program:

#include <stdio.h>

int main() {

int arr[3] = {10, 20, 30};

printf("%d", arr[-1]);

return 0;

A) 10

B) 0

C) Garbage

D) Compilation error

Answer: C

162. What will it print?

#include <stdio.h>
int main() {

char *p = "world";

p++;

printf("%s", p);

return 0;

A) world

B) orld

C) rld

D) Compilation error

Answer: B
163. Result of:

#include <stdio.h>

int main() {

int a = 5;

printf("%d", a++ + ++a);


return 0;

A) 10

B) 11
C) 12

D) Undefined

Answer: C

164. What is the output?

#include <stdio.h>

int main() {

char str[] = "xyz";

str[1] = '\0';

printf("%s", str);

return 0;

A) x

B) xy

C) y

D) xyz

Answer: A

165. Output of this:

#include <stdio.h>
int main() {
int x = 4;

int y = 2;

printf("%d", x >> y);

return 0;

A) 1

B) 0

C) 2

D) Compilation error
Answer: A

166. What is printed?

#include <stdio.h>

int main() {

int a = 1;

if (a == 1 && printf("Hi"))

printf("Bye");

return 0;

A) HiBye

B) Hi

C) Bye

D) Nothing

Answer: A

167. Output?

#include <stdio.h>

int main() {

char s[10];

scanf("%s", s);
printf("%s", s);
return 0;

Input: hello

A) hello

B) h

C) Error

D) Nothing

Answer: A

168. Output:

#include <stdio.h>

int main() {

char *s = "CSE";

s[0] = 'M';

printf("%s", s);

return 0;
}

A) MSE

B) CSE

C) Compilation error
D) Runtime error

Answer: D

169. What is printed?

#include <stdio.h>

int main() {

int a = 10, b = 20;

a = a ^ b;

b = a ^ b;

a = a ^ b;

printf("%d %d", a, b);


return 0;

A) 10 20

B) 20 10

C) 0 0
D) Compilation error

Answer: B

170. Choose the output:

#include <stdio.h>

int main() {

char str1[] = "abc";

char str2[] = "abc";

printf("%d", strcmp(str1, str2));

return 0;

A) 0

B) 1

C) -1

D) Compilation error

Answer: A

171. What does this print?

#include <stdio.h>

int main() {

int x = 10;
int y = x++ * ++x;

printf("%d", y);

return 0;

}
A) 100

B) 110

C) 120

D) Undefined

Answer: B

172. Output of:

#include <stdio.h>

int main() {

int arr[] = {3, 6, 9};

printf("%d", 2[arr]);

return 0;

A) 3

B) 6

C) 9
D) Compilation error

Answer: C

173. Result:

#include <stdio.h>

int main() {

int x = 5;

printf("%d", x++ + x++);

return 0;

A) 10

B) 11

C) 12

D) Undefined

Answer: B
174. What will be printed?

#include <stdio.h>

int main() {

int i = 1;

while (i <= 5)
printf("%d", i++);

return 0;

A) 1234

B) 12345

C) 01234

D) Infinite loop

Answer: B

175. Output:

#include <stdio.h>

int main() {

char ch = 'A' + 1;

printf("%c", ch);

return 0;

A) A

B) B

C) C

D) Compilation error

Answer: B

176. What is the output?

#include <stdio.h>
int main() {
int a = 2;

int b = 3;
printf("%d", a+++b);

return 0;

A) 5

B) 6

C) 7

D) Compilation error

Answer: A

177. Output of the code:

#include <stdio.h>

int main() {

char str[] = "CProgramming";

printf("%c", *(&str[4]));

return 0;

A) P

B) o

C) r

D) g

Answer: C

178. What does this print?

#include <stdio.h>
int main() {

int a = 5;

printf("%d %d", a++, ++a);

return 0;

}
A) 5 6

B) 6 6

C) 6 7

D) Undefined

Answer: D

179. What is the output?

#include <stdio.h>

int main() {

char *p = "abc";

while (*p)

printf("%c", *p++);

return 0;
}

A) abc

B) cba
C) a

D) Error

Answer: A

180. Output:

#include <stdio.h>

int main() {

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

printf("%p %p", (void*)a, (void*)(a+1));

return 0;

A) Same address

B) Different by 2

C) Different by 4 or 8 (system dependent)


D) Compilation error

Answer: C

181. What will be printed?

#include <stdio.h>

int main() {

char s[5] = "Hi";

printf("%d", sizeof(s));

return 0;

A) 2

B) 3

C) 4

D) 5

Answer: D

182. What happens here?

#include <stdio.h>

int main() {
int x = 5;

printf("%d %d", x++, x++);

return 0;

A) 5 5

B) 5 6

C) 6 6

D) Undefined

Answer: D

183. Output:
#include <stdio.h>

int main() {

int arr[] = {1, 2, 3, 4};

printf("%d", *(arr + 2));

return 0;

A) 2

B) 3

C) 4

D) Compilation error
Answer: B

184. What does this print?

#include <stdio.h>

int main() {

int i = 10;

printf("%d", i = i++);

return 0;

A) 10

B) 11

C) Undefined

D) Error

Answer: C

185. Output?

#include <stdio.h>

int main() {

char *p = "hello";

printf("%c", *(p+strlen(p)-1));
return 0;

A) h

B) o

C) e

D) l

Answer: B

186. What is the output?

#include <stdio.h>

int main() {

int arr[5] = {5, 4, 3, 2, 1};


int i;

for (i = 0; i < 5; i++) {

if (arr[i] == i)

break;

printf("%d", i);

return 0;

A) 0

B) 1

C) 2

D) 3

Answer: C

187. Output of this program?

#include <stdio.h>

int main() {

char a[] = "abc";

printf("%c", a[3]);
return 0;

A) a

B) c

C) NULL character

D) Garbage

Answer: C

188. Result of:

#include <stdio.h>
int main() {
int x = 10;

if (x = 0)
printf("Yes");

else
printf("No");

return 0;
}

A) Yes
B) No

C) Compilation error
D) Infinite loop

Answer: B

189. What is printed?

#include <stdio.h>
int main() {

char *s = "CS50";
while (*s) {
printf("%c-", *s++);

}
return 0;
}

A) C-S-5-0-

B) CS50
C) C S 5 0

D) C+S+5+0
Answer: A

190. Output:

#include <stdio.h>

int main() {
char *p = "12345";

printf("%c", *(p + 5));


return 0;
}

A) Garbage

B) ‘\0’
C) Compilation error
D) Runtime error

Answer: B

191. What will be output?

#include <stdio.h>
int main() {

int i = 0;
while (++i <= 5)

printf("%d", i);
return 0;

}
A) 1234

B) 12345
C) 123456

D) 01234
Answer: C

192. Choose the correct output:

#include <stdio.h>
int main() {

int i = 0;
do {

printf("%d", i);
} while (i-- > 0);

return 0;
}

A) Infinite loop
B) 0

C) 01
D) 0-1

Answer: B

193. Output?

#include <stdio.h>
int main() {

int a = 1;
if (a && printf("Hello"))
printf(" World");

return 0;
}

A) Hello

B) Hello World
C) World

D) Compilation error
Answer: B

194. Result:

#include <stdio.h>

int main() {
int arr[] = {0, 1, 2, 3};
printf("%d", 3[arr]);

return 0;
}

A) 0

B) 1
C) 2

D) 3
Answer: D

195. What is the output?

#include <stdio.h>

int main() {
int i;

for (i = -1; i <= 1; i++)


if (i)

printf("X");
else
printf("Y");

return 0;
}

A) XYX
B) YXX

C) YXY
D) Compilation error
Answer: B

196. Output:

#include <stdio.h>

int main() {
int x = 4;

int y = 3;
printf("%d", x | y);

return 0;
}

A) 7

B) 3
C) 1
D) 4

Answer: A

197. What is the result?

#include <stdio.h>
int main() {

char s[] = "data";


s[0] = '\0';

printf("%s", s);
return 0;

A) data

B) d
C) Empty output

D) Error
Answer: C
198. What will be printed?

#include <stdio.h>
int main() {
char str[] = "quiz";

printf("%c", *(str + 1));


return 0;

A) q

B) u
C) i

D) z
Answer: B

199. Output:

#include <stdio.h>

int main() {
char *s = "abcde";

printf("%c", *(s + 5));


return 0;

A) ‘\0’
B) e

C) Garbage
D) Compilation error

Answer: A

200. What is printed?

#include <stdio.h>

int main() {
int i = 3;
printf("%d %d %d", i, i--, --i);

return 0;
}

A) 3 3 1

B) 3 2 1
C) Undefined

D) 3 3 2
Answer: C

You might also like