0% found this document useful (0 votes)
14 views25 pages

C Certification Sample Questions (For Students)

The document contains a series of multiple-choice questions and coding exercises related to C programming fundamentals, including variable naming, data types, operators, memory management, and functions. It covers topics such as problem-solving, counting, sorting, searching, text processing, and user-defined types. Each question tests knowledge of C syntax, semantics, and best practices.

Uploaded by

Instinct 69
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)
14 views25 pages

C Certification Sample Questions (For Students)

The document contains a series of multiple-choice questions and coding exercises related to C programming fundamentals, including variable naming, data types, operators, memory management, and functions. It covers topics such as problem-solving, counting, sorting, searching, text processing, and user-defined types. Each question tests knowledge of C syntax, semantics, and best practices.

Uploaded by

Instinct 69
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/ 25

C Cer ca on-Sample Ques ons for prac ce

Unit 1: Problem Solving Fundamentals

1. Which of the following is not a valid C variable name?


a) int 1var;
b) int _var;
c) int var1;
d) int Var;

2. What is the output of printf("%d", sizeof('A')); in a 32-bit C compiler?


a) 1
b) 2
c) 4
d) Depends on the compiler

3. Which operator has the highest precedence in C?


a) *
b) ()
c) ++
d) =

4. What is the range of a signed char in C?


a) 0 to 255
b) -128 to 127
c) -127 to 128
d) -32768 to 32767

5. Which of the following is not a valid storage class in C?


a) auto
b) register
c) static
d) extern
e) dynamic

6. What is the output of printf("%d", 5 + 2 * 3 - 1);?


a) 10
b) 12
c) 14
d) 16

7. Which function is used to read a single character from stdin in C?


a) scanf()
b) getchar()
c) gets()
d) fgets()

8. What does the break statement do in a loop?


a) Skips the current iteration
b) Terminates the loop
ti
fi
ti
ti
ti
c) Continues to the next iteration
d) None of the above

9. Which header ile is required for printf() and scanf()?


a) <conio.h>
b) <stdlib.h>
c) <stdio.h>
d) <math.h>

10. What is the output of printf("%d", 10 ? 0 ? 5 : 3 : 8);?


a) 5
b) 3
c) 0
d) 8

11. Predict the output:

int main()

int x = 5;

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

return 0;

11. Fill in the blank:


The ________ quali ier prevents a variable from being modi ied.

12. What is wrong with this code?

int main()

int a = 10, b = 20;

if (a = b) printf("Equal");

else printf("Not Equal");

return 0;

13. Predict the output:

int main()

{
f
f
f
int i = 0;

while (i < 5) {

printf("%d ", i);

if (i == 3) break;

i++;

return 0;

14. What is the output of:

printf("%d", sizeof(3.14f));

15. Correct the code:

int main()

char *str = "Hello";

str[0] = 'h';

printf("%s", str);

return 0;

16. Predict the output:

int main() {

int x = 5, y = 10;

x ^= y ^= x ^= y;

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

return 0;

17. What is the value of i after:

int i = 5;

i = i++ + ++i;
18. Fill in the blank:
The ________ directive is used to include a header ile.

19. What is the output?

int main() {

int a = 0;

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

else printf("Non-zero");

return 0;

Unit 2: Counting, Sorting, and Searching

21. What is the output of:

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

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

22. Which of the following is not a correct way to pass an array to a function?
a) func(int arr[])
b) func(int *arr)
c) func(int arr[5])
d) func(int arr)

23. What is the time complexity of binary search?


a) O(n)
b) O(log n)
c) O(n²)
d) O(1)

24. Which of the following is not a storage class in C?


a) auto
b) register
c) static
d) volatile

25. What is the output of:

int main() {

int *ptr = NULL;

printf("%d", *ptr);
f
return 0;

26. Which of the following is not a valid way to declare a pointer?


a) int *p;
b) int* p;
c) int * p;
d) int p*;

27. What is the output of:

int main() {

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

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

return 0;

28. What is the output of:

int main() {

int a = 5, b = 10;

int *p = &a;

*p = b;

printf("%d", a);

return 0;

29. Which of the following is true about recursion?


a) It always improves performance
b) It requires a base case
c) It cannot cause stack over low
d) It is faster than iteration

31. Predict the output:

int main() {

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

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

}
f
32. What is wrong with this code?

int main() {

int *p;

*p = 10;

printf("%d", *p);

return 0;

33. Fill in the blank:


The ________ keyword is used to de ine a recursive function.

34. What is the output?

int main() {

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

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

35. Predict the output:

int main() {

int x = 5;

int *p = &x;

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

36. What is the output of:

int main() {

int arr[3] = {1};

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

37. Correct the code:

int main() {

int *p = malloc(sizeof(int));
f
*p = 10;

free(p);

printf("%d", *p);

38. What is the output of:

int main() {

int a = 5, b = 10;

swap(&a, &b);

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

(Assume swap is correctly implemented)

39. Fill in the blank:


The ________ sorting algorithm is in-place and has O(n²) worst-case time complexity.

40. Predict the output:

int main() {

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

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

Unit 3: Text Processing & User-De ined Types

41. Which function is used to compare two strings in C?


a) strcmp()
b) strcat()
c) strcpy()
d) strlen()

42. What is the output of:

printf("%d", strlen("Hello\n"));

43. Which of the following is not a valid way to declare a string?


a) char str[] = "Hello";
b) char *str = "Hello";
c) char str[5] = "Hello";
d) char str[6] = "Hello";
f
44. What is the output of:

int main() {

struct { int x; } s1 = {5}, s2 = s1;

printf("%d", s2.x);

45. Which of the following is not a dynamic memory allocation function?


a) malloc()
b) calloc()
c) realloc()
d) alloc()

46. What is the output of:

int main() {

union { int a; char b; } u;

u.a = 65;

printf("%c", u.b);

47. What is the output of:

int main() {

enum { A, B = 5, C } e;

printf("%d", C);

48. Which of the following is not a valid way to pass a structure to a function?
a) Pass by value
b) Pass by reference
c) Pass by pointer
d) Pass by address

49. What is the output of:

int main() {

char str[10] = "Hello";

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

}
50. Which of the following is not a valid bitwise operator?
a) &
b) |
c) ^
d) &&

51. Predict the output:

int main() {

char *str = "Hello";

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

52. What is wrong with this code?

int main() {

char *str;

strcpy(str, "Hello");

printf("%s", str);

53. Fill in the blank:


The ________ function is used to concatenate two strings.

54. What is the output of:

int main() {

printf("%d", sizeof("A\0B"));

55. Correct the code:

int main() {

char *str = malloc(5);

str = "Hello";

printf("%s", str);

56. Predict the output:


int main() {

struct { int x; char c; } s = {1, 'A'};

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

57. What is the output of:

int main() {

enum { A = 1, B, C = 0 } e;

printf("%d %d", B, C);

58. Fill in the blank:


The ________ directive is used to pack structures without padding.

59. What is the output of:

int main() {

int *p = malloc(sizeof(int));

*p = 5;

free(p);

printf("%d", *p);

61. function is used to read a line from a ile?


a) fgets()
b) fread()
c) fscanf()
d) getline()

62. What is the output of:

int main() {

FILE *fp = fopen("test.txt", "w");

fprintf(fp, "Hello");

fclose(fp);

fp = fopen("test.txt", "r");
f
char ch = fgetc(fp);

printf("%c", ch);

63. Which directive is used for conditional compilation?


a) #ifdef
b) #include
c) #de ine
d) #pragma

64. What is the output of:

#de ine SQUARE(x) x * x

int main() {

printf("%d", SQUARE(2 + 3));

65. Which function is used to dynamically allocate an array?


a) malloc()
b) calloc()
c) realloc()
d) All of the above
`

66. What is the output of:

int main() {

printf("%s", __FILE__);

67. Which of the following is not a valid ile opening mode?


a) "r"
b) "w"
c) "a"
d) "x"

68. What is the output of:

int main() {

#ifdef DEBUG

printf("Debug");

#else
f
f
f
printf("Release");

#endif

71. Predict the output:

int main() {

FILE *fp = fopen("test.txt", "w");

fputs("Hello", fp);

fclose(fp);

fp = fopen("test.txt", "r");

char str[10];

fgets(str, 3, fp);

printf("%s", str);

72. What is wrong with this code?

int main() {

FILE *fp;

fp = fopen("test.txt", "r");

char ch = fgetc(fp);

printf("%c", ch);

73. Fill in the blank:


The ________ function is used to change the ile position indicator.

74. What is the output of:

int main() {

printf("%d", __LINE__);

75. Correct the code:


f
int main() {

FILE *fp = fopen("test.txt", "r");

char ch = fgetc(fp);

printf("%c", ch);

76. Predict the output:

int main() {

printf("%d", (5, 3));

77. What is the output of:

#de ine MIN(a,b) a < b ? a : b

int main() {

printf("%d", MIN(2, 3 < 4 ? 3 : 4));

78. Fill in the blank:


The ________ directive is used to de ine a macro.

79. What is the output of:

int main() {

int a = 5;

#if a == 5

printf("Five");

#else

printf("Not Five");

#endif

80. Predict the output:

int main() {

printf("%d", sizeof(void));
f
f
}

Additional Questions

81. Which of the following is not a valid escape sequence in C?


a) \n
b) \t
c) \e
d) \\

82. What is the output of printf("%d", 10 + 5 / 2 * 3);?


a) 12
b) 14
c) 15
d) 17

83. Which of the following is not a valid format speci ier in printf?
a) %d
b) %f
c) %c
d) %e
e) %s
f) %p
g) %b

84. What is the output of printf("%d", sizeof(3.14));?


a) 4
b) 8
c) 16
d) Compiler-dependent

85. Which of the following is not a valid way to initialize a variable?


a) int x = 5;
b) int x(5);
c) int x{5};
d) int x; x = 5;

86. What is the output of printf("%d", 1 && 0 || 1);?


a) 0
b) 1
c) Syntax error
d) Unde ined behavior

87. Which of the following is not a valid main() function declaration in C?


a) int main() {}
f
f
b) int main(void) {}
c) void main() {}
d) main() {}

88. What is the output of printf("%d", 1 << 3);?


a) 1
b) 3
c) 8
d) 9

89. Which of the following is not a valid comment style in C?


a) // Comment
b) /* Comment */
c) <!-- Comment -->
d) # Comment

90. What is the output of printf("%d", ~5); (assuming 32-bit int)?


a) -6
b) 6
c) 5
d) Unde ined

91. Predict the output:

int main() {

int x = 5;

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

92. What is wrong with this code?

int main() {

const int x = 5;

x = 10;

printf("%d", x);

93. Fill in the blank:


The ________ operator returns the address of a variable.

94. What is the output?


f
int main() {

int x = 5;

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

printf("%d", x);

95. Correct the code:

int main() {

int x = 5;

if (x == 5);

printf("Five");

96. Predict the output:

int main() {

int x = 0;

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

else printf("Non-zero");

97. What is the output?

int main() {

printf("%d", 1 + 2 * 3 / 4);

98. Fill in the blank:


The ________ function reads formatted input from stdin.

99. What is the output?

int main() {

int x = 5, y = 10;

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

}
100.Predict the output:
int main() { printf("%d", 1 ? 0 ? 5 : 3 : 8); }

101.What is the output of:

int main() {

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

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

102.Which of the following is not a valid pointer declaration?


a) int *p;
b) int* p, q;
c) int *p, *q;
d) int* p; int* q;

103.What is the output of:

int main() {

int x = 5;

int *p = &x;

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

104.Which function is used to dynamically allocate memory?


a) malloc()
b) calloc()
c) realloc()
d) All of the above

105.What is the output of:

int main() {

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

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

106.Which of the following is not a valid way to pass an array to a function?


a) func(int arr[])
b) func(int *arr)
c) func(int arr[5])
d) func(int arr)

107.What is the output of:

int main() {

int a = 5, b = 10;

int *p = &a;

*p = b;

printf("%d", a);

108.Which of the following is true about recursion?


a) It always improves performance
b) It requires a base case
c) It cannot cause stack over low
d) It is faster than iteration

111.Predict the output:

int main() {

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

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

112.What is wrong with this code?

int main() {

int *p;

*p = 10;

printf("%d", *p);

113.Fill in the blank:


The ________ keyword is used to de ine a recursive function.

114.What is the output?

int main() {

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


f
f
printf("%d", a[a[1]]);

115.Correct the code:

int main() {

int *p = malloc(sizeof(int));

*p = 10;

free(p);

printf("%d", *p);

116.Predict the output:

int main() {

int x = 5;

int *p = &x;

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

117.What is the output of:

int main() {

int arr[3] = {1};

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

118.Fill in the blank:


The ________ sorting algorithm is in-place and has O(n²) worst-case time complexity.

119.What is the output of:

int main() {

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

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

120.Predict the output:


int main() {

int a = 5, b = 10;

swap(&a, &b);

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

(Assume swap is correctly implemented)

121.Which function is used to compare two strings?


a) strcmp()
b) strcat()
c) strcpy()
d) strlen()

122.What is the output of:

printf("%d", strlen("Hello\n"));

123.Which of the following is not a valid way to declare a string?


a) char str[] = "Hello";
b) char *str = "Hello";
c) char str[5] = "Hello";
d) char str[6] = "Hello";

124.What is the output of:

int main() {

struct { int x; } s1 = {5}, s2 = s1;

printf("%d", s2.x);

125.Which of the following is not a dynamic memory allocation function?


a) malloc()
b) calloc()
c) realloc()
d) alloc()

126.What is the output of:

int main() {

union { int a; char b; } u;


u.a = 65;

printf("%c", u.b);

127.What is the output of:

int main() {

enum { A, B = 5, C } e;

printf("%d", C);

128.Which of the following is not a valid way to pass a structure to a function?


a) Pass by value
b) Pass by reference
c) Pass by pointer
d) Pass by address

129.What is the output of:

int main() {

char str[10] = "Hello";

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

130.Which of the following is not a valid bitwise operator?


a) &
b) |
c) ^
d) &&

131.Predict the output:

int main() {

char *str = "Hello";

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

132.What is wrong with this code?

int main() {

char *str;
strcpy(str, "Hello");

printf("%s", str);

133.Fill in the blank:


The ________ function is used to concatenate two strings.

134.What is the output of:

int main() {

printf("%d", sizeof("A\0B"));

135.Correct the code:

int main() {

char *str = malloc(5);

str = "Hello";

printf("%s", str);

136.Predict the output:

int main() {

struct { int x; char c; } s = {1, 'A'};

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

137.What is the output of:

int main() {

enum { A = 1, B, C = 0 } e;

printf("%d %d", B, C);

138.Fill in the blank:


The ________ directive is used to pack structures without padding.

139.What is the output of:


int main() {

int *p = malloc(sizeof(int));

*p = 5;

free(p);

printf("%d", *p);

140.Predict the output:

int main() {

char str[] = "Hello";

printf("%d %d", sizeof(str), strlen(str));

141.Which function is used to open a ile?


a) fopen()
b) open()
c) ileopen()
d) read ile()

142.What is the correct way to open a ile in read mode?


a) fopen(" ile.txt", "r");
b) fopen(" ile.txt", "w");
c) fopen(" ile.txt", "a");
d) fopen(" ile.txt", "r+");

143.Which function is used to read a line from a ile?


a) fgets()
b) fread()
c) fscanf()
d) getline()

144.What is the output of:

int main() {

FILE *fp = fopen("test.txt", "w");

fprintf(fp, "Hello");

fclose(fp);
f
f
f
f
f
f
f
f
f
fp = fopen("test.txt", "r");

char ch = fgetc(fp);

printf("%c", ch);

145.Which directive is used for conditional compilation?


a) #ifdef
b) #include
c) #de ine
d) #pragma

146.What is the output of:

#de ine SQUARE(x) x * x

int main() {

printf("%d", SQUARE(2 + 3));

147.Which function is used to dynamically allocate an array?


a) malloc()
b) calloc()
c) realloc()
d) All of the above

148.What is the output of:

int main() {

printf("%s", __FILE__);

149.Which of the following is not a valid ile opening mode?


a) "r"
b) "w"
c) "a"
d) "x"

150.What is the output of:

int main() {

#ifdef DEBUG

printf("Debug");
f
f
f
#else

printf("Release");

#endif

You might also like