INTRODUCTION TO PROGRAMMING IN C
BASIC:
Q1. Which of the following is a valid C identifier?
a) 123name
b) name_123
c) int
d) a-b
✅ Answer: b) name_123
Q2. What is the default return type of the main() function in C?
a) void
b) int
c) float
d) char
✅ Answer: b) int
Q3. Which of the following is used to include header files in C?
a) #define
b) #include
c) import
d) header
✅ Answer: b) #include
Q4. Which of the following is not a valid data type in C?
a) int
b) double
c) real
d) char
✅ Answer: c) real
Q5. What will be the output of this code?
#include <stdio.h>
int main() {
printf("Hello C");
return 0;
}
a) Hello
b) Hello C
c) Error
d) None
✅ Answer: b) Hello C
Concept 1 — C Basics & Syntax — 70
MCQs (with answers)
1. Which of these is a valid C identifier?
a) 2ndValue b) _value c) break d) first-name
✅ Answer: b) _value
2. Which of the following is a C keyword?
a) main b) return c) printf d) NUMBER
✅ Answer: b) return
3. What is the size (in bytes) of char in standard C on most platforms?
a) 1 b) 2 c) 4 d) depends on compiler
✅ Answer: a) 1
4. Which header file is required for printf and scanf?
a) <stdlib.h> b) <stdio.h> c) <string.h> d) <math.h>
✅ Answer: b) <stdio.h>
5. What is the default return type of main() in standard C?
a) void b) int c) char d) float
✅ Answer: b) int
6. Which operator is used for assignment?
a) == b) = c) := d) ===
✅ Answer: b) =
7. What does // denote in C?
a) Start of a block comment b) Start of a single-line comment c) Division operator d)
Bitwise operator
✅ Answer: b) Start of a single-line comment
8. Which is the correct way to include a user header file my.h?
a) #include <my.h> b) #include "my.h" c) include my.h d) import "my.h"
✅ Answer: b) #include "my.h"
9. Which of these is not a valid integer constant?
a) 077 b) 0x1A c) 123u d) 12.3
✅ Answer: d) 12.3
10. What is the result type of the expression 5 / 2 in C (both operands ints)?
a) 2.5 b) 2 c) 3 d) Compiler error
✅ Answer: b) 2
11. Which escape sequence represents newline?
a) \t b) \n c) \ d) \r
✅ Answer: b) \n
12. Which printf specifier prints a double?
a) %f b) %lf c) %d d) %c
✅ Answer: a) %f
(Note: in printf both float promoted to double and double are printed with %f.)
13. What does sizeof(int) return (on typical 32/64-bit platforms)?
a) 1 b) 2 c) 4 d) 8
✅ Answer: c) 4
14. Which storage class gives a variable internal linkage by default?
a) extern b) static c) auto d) register
✅ Answer: b) static
15. Which of these identifiers is illegal?
a) _sum b) total3 c) float d) price_inr
✅ Answer: c) float
16. Which operator has higher precedence?
a) + b) * c) = d) ==
✅ Answer: b) *
17. What is the value of ++i if i was 5 before?
a) 4 b) 5 c) 6 d) Undefined
✅ Answer: c) 6
18. Which of the following is a valid floating constant?
a) 1.2e3 b) 12f c) 09.1 d) 1..2
✅ Answer: a) 1.2e3
19. What is the effect of #define PI 3.14?
a) Creates a variable PI b) Replaces PI with 3.14 at compile time c) Declares a
constant at runtime d) No effect
✅ Answer: b) Replaces PI with 3.14 at compile time
20. Which function reads a single character from stdin?
a) getch() b) getchar() c) gets() d) getschar()
✅ Answer: b) getchar()
21. Which of these will cause undefined behavior?
a) Accessing array out of bounds b) Using uninitialized automatic variable c)
Dividing by zero d) All of the above
✅ Answer: d) All of the above
22. Which symbol starts a preprocessor directive?
a) $ b) @ c) # d) %
✅ Answer: c) #
23. Which of these is a valid comment in C?
a) /* comment */ b) <!-- comment --> c) // comment d) a and c
✅ Answer: d) a and c
24. What is the meaning of extern int x;?
a) Define x b) Declare x defined elsewhere c) Make x local d) Make x static
✅ Answer: b) Declare x defined elsewhere
25. Which header defines NULL?
a) <stddef.h> b) <stdio.h> c) <string.h> d) <math.h>
✅ Answer: a) <stddef.h> (Also commonly in <stdio.h>, <stdlib.h>)
26. What is the output of printf("%d", 'A');?
a) A b) 65 c) 'A' d) Compiler error
✅ Answer: b) 65 (ASCII value)
27. Which of these is used to compile a C program?
a) interpreter b) compiler c) bytecode d) assembler
✅ Answer: b) compiler
28. Which operator is bitwise AND?
a) && b) & c) and d) |
✅ Answer: b) &
29. Which of the following is true about const?
a) const int x; creates a mutable variable b) const prevents modification through that
name c) const allocates constant memory always in ROM d) const is the same as
#define
✅ Answer: b) const prevents modification through that name
30. Which format specifier prints a long int?
a) %d b) %ld c) %f d) %li
✅ Answer: b) %ld
31. What does the register keyword suggest?
a) Store variable in disk b) Store variable in CPU register c) Variable is global d) No
effect (compiler may ignore)
✅ Answer: b) Store variable in CPU register (compiler may ignore)
32. Which of the following is promoted in variadic functions (like printf)?
a) float -> double b) char -> int c) short -> int d) All of the above
✅ Answer: d) All of the above
33. Which is true about identifier names in C?
a) Case-insensitive b) Must start with a letter or underscore c) Can contain spaces d)
Cannot contain digits
✅ Answer: b) Must start with a letter or underscore
34. Which of these is not a valid storage class in C?
a) auto b) static c) mutable d) extern
✅ Answer: c) mutable
35. What is the result of 0 && (1/0)?
a) runtime error b) 0 (no divide-by-zero because short-circuit) c) 1 d) undefined
behavior
✅ Answer: b) 0 (left operand false, right not evaluated)
36. Which header contains malloc?
a) <malloc.h> b) <stdlib.h> c) <memory.h> d) <stdio.h>
✅ Answer: b) <stdlib.h>
37. Which constant type is 123u?
a) signed int b) unsigned int c) long d) float
✅ Answer: b) unsigned int
38. Which of these is used to concatenate two string literals in C?
a) + b) ,, c) placing side by side with space d) strcat at compile time
✅ Answer: c) placing side by side with space (e.g., "Hello" "World" ->
"HelloWorld")
39. What does the expression (a = 5) == 5 evaluate to (assuming a exists)?
a) true (1) b) false (0) c) undefined d) compiler error
✅ Answer: a) true (1)
40. Which of these scanf format specifiers reads an integer?
a) "%f" b) "%d" c) "%s" d) "%c"
✅ Answer: b) "%d"
41. Which of following is true about return 0; in main?
a) Signals successful termination to OS b) Mandatory in all programs c) Returns a
character d) Causes a compile-time error if missing
✅ Answer: a) Signals successful termination to OS
42. What is the value of the expression 5 % 2?
a) 0 b) 1 c) 2 d) 2.5
✅ Answer: b) 1
43. Which of these is the correct prototype for main with command-line args?
a) int main() b) int main(int argc, char *argv[]) c) void main() d) main(argc, argv)
✅ Answer: b) int main(int argc, char *argv[])
44. Which operator tests equality?
a) = b) == c) === d) :=
✅ Answer: b) ==
45. Which type holds true/false in standard C (pre C99)?
a) bool b) _Bool (C99) or int in older code c) boolean d) truth
✅ Answer: b) _Bool (C99) or int in older code
46. Which of the following is not allowed in an identifier?
a) letters b) digits after first char c) underscore d) hyphen (-)
✅ Answer: d) hyphen (-)
47. What happens when you compile code with missing semicolon at end of
statement?
a) Warning only b) Syntax error c) Program runs but prints semicolon d) Undefined
behavior at runtime
✅ Answer: b) Syntax error
48. Which operator shifts bits to the left?
a) >> b) << c) >>> d) ><
✅ Answer: b) <<
49. Which of the following constants is octal?
a) 075 b) 0x75 c) 75 d) 075uF
✅ Answer: a) 075
50. Which header file provides exit() function?
a) <stdio.h> b) <stdlib.h> c) <unistd.h> d) <string.h>
✅ Answer: b) <stdlib.h>
51. What is wrong with this printf call: printf("%d", 3.14);?
a) Nothing b) Using wrong format specifier (double passed, %d expects int) c) 3.14 is
not allowed d) Compiler will convert to int automatically
✅ Answer: b) Using wrong format specifier (undefined behavior)
52. Which literal denotes a wide-character constant?
a) "a" b) L'a' c) u'a' d) U'a'
✅ Answer: b) L'a'
53. Which of the following yields integer promotions?
a) unsigned char to int b) short to int c) char to int d) All of the above
✅ Answer: d) All of the above
54. Which function reads a string from stdin (unsafe)?
a) fgets b) gets c) scanf("%s") d) gets_s
✅ Answer: b) gets (unsafe and removed in C11)
55. What is the precedence between && and ||?
a) || higher than && b) && higher than || c) same precedence evaluated left to right d)
undefined
✅ Answer: b) && higher than ||
56. Which of these is true about #include <stdio.h> and #include "stdio.h"?
a) No difference b) Angle brackets search in system directories, quotes search local
first c) Quotes search system only d) Angle brackets for macros only
✅ Answer: b) Angle brackets search in system directories, quotes search local first
57. Which is correct to declare a constant integer?
a) #define CONST 10 b) const int c = 10; c) both a and b d) None
✅ Answer: c) both a and b
58. What is an lvalue?
a) value that can appear on left side of assignment b) literal only c) temporary only d)
pointer only
✅ Answer: a) value that can appear on left side of assignment
59. Which operator gives address of variable?
a) * b) & c) -> d) .
✅ Answer: b) &
60. Which of these is not a valid format specifier?
a) %s b) %p c) %q d) %x
✅ Answer: c) %q
61. What is the type of string literal "hello"?
a) char * b) const char[] (array of char) c) char[] d) void*
✅ Answer: b) const char[] (conceptually array of char with static storage; modifying
is undefined)
62. Which command compiles C code to object file using GCC?
a) gcc -S file.c b) gcc -c file.c c) gcc -o file file.c d) gcc -E file.c
✅ Answer: b) gcc -c file.c
63. Which of the following is true about implicit conversions?
a) They never happen b) Compiler can convert smaller integer to larger type c) float
automatically converts to int without loss d) char to float is not allowed
✅ Answer: b) Compiler can convert smaller integer to larger type
64. Which of following is a valid string escape representing tab?
a) \n b) \t c) \b d) \a
✅ Answer: b) \t
65. Which of these integer types is guaranteed to be at least 16 bits?
a) char b) short c) int d) long long
✅ Answer: b) short
66. What is the value of !0?
a) 0 b) 1 c) -1 d) undefined
✅ Answer: b) 1
67. Which of the following is true about sizeof operator?
a) Evaluates its operand always at runtime b) Returns size in bits c) Returns size in
bytes and operand may not be evaluated if it's an expression d) Only works on types,
not variables
✅ Answer: c) Returns size in bytes and operand may not be evaluated if it's an
expression
68. Which of the following statements about volatile is true?
a) Prevents compiler optimizations for that variable b) Makes variable constant c)
Allocates variable in ROM d) Forces variable to be in register
✅ Answer: a) Prevents compiler optimizations for that variable
69. Which of the following is true about if (x = 0)?
a) Compares x to 0 b) Assigns 0 to x and tests value (false) c) Syntax error d)
Compiler will convert to == automatically
✅ Answer: b) Assigns 0 to x and tests value (false)
70. Which of following headers is required for memcpy?
a) <stdio.h> b) <string.h> c) <stdlib.h> d) <memory.h>
✅ Answer: b) <string.h>
Concept 2 — Control Structures — 70
MCQs (with answers)
If–Else & Switch
1. Which of these is the correct syntax for an if statement?
a) if { condition }
b) if (condition) { statements }
c) if condition: statements
d) if (condition);
✅ Answer: b) if (condition) { statements }
2. What happens if no braces {} are used after an if statement?
a) Compiler error
b) Only the first statement after if is executed conditionally
c) All statements until else are conditional
d) Undefined behavior
✅ Answer: b) Only the first statement after if is executed conditionally
3. Which of the following evaluates to true in C?
a) if (0)
b) if (1)
c) if (-1)
d) b and c
✅ Answer: d) b and c
4. What is the output of:
int x = 5;
if (x = 0) printf("Zero");
else printf("Non-zero");
a) Zero
b) Non-zero
c) Error
d) Nothing
✅ Answer: b) Non-zero (because assignment makes x=0, condition is false → else executed)
5. Which of these is true about switch?
a) It can test integers and characters
b) It can test floating-point directly
c) It allows ranges of values in one case
d) It doesn’t allow break statements
✅ Answer: a) It can test integers and characters
6. Which keyword is optional in switch but recommended to avoid fall-through?
a) case
b) break
c) continue
d) default
✅ Answer: b) break
7. What is the default section of a switch used for?
a) To end the switch
b) To handle unmatched cases
c) To restart switch evaluation
d) To declare variables
✅ Answer: b) To handle unmatched cases
8. Which of these is invalid inside a switch case label?
a) case 1:
b) case 'a':
c) case x: (where x is a variable)
d) default:
✅ Answer: c) case x: (must be constant expression)
9. Which statement is true?
a) switch can replace if–else ladder in all situations
b) switch supports only equality checking
c) switch can test logical conditions
d) switch can use floats as case labels
✅ Answer: b) switch supports only equality checking
10. What happens if break is missing in a switch case?
a) Compile error
b) Execution falls through to the next case
c) Switch exits automatically
d) Program terminates
✅ Answer: b) Execution falls through to the next case
Loops
11. Which of these is an entry-controlled loop?
a) for
b) while
c) do–while
d) a and b
✅ Answer: d) a and b
12. Which of these is an exit-controlled loop?
a) for
b) while
c) do–while
d) switch
✅ Answer: c) do–while
13. What is the output?
int i=0;
while(i<3) {
printf("%d ", i);
i++;
}
a) 0 1 2
b) 1 2 3
c) Infinite loop
d) 0 1 2 3
✅ Answer: a) 0 1 2
14. Which loop is best when number of iterations is known?
a) for
b) while
c) do–while
d) switch
✅ Answer: a) for
15. Which of these loops always executes at least once?
a) for
b) while
c) do–while
d) nested for
✅ Answer: c) do–while
16. What is the output?
for(int i=0; i<3; i++);
printf("Hi");
a) HiHiHi
b) Hi
c) Nothing
d) Compile error
✅ Answer: b) Hi (because of semicolon, loop body is empty)
17. Which statement is used to skip the current iteration of a loop?
a) break
b) continue
c) goto
d) pass
✅ Answer: b) continue
18. Which statement is used to exit the entire loop immediately?
a) stop
b) break
c) continue
d) exitloop
✅ Answer: b) break
19. Which of these loops can be infinite if condition never becomes false?
a) for
b) while
c) do–while
d) all of the above
✅ Answer: d) all of the above
20. Which of these is correct loop syntax?
a) for (i=0; i<5) printf("%d",i);
b) for (i=0; i<5; i++) printf("%d",i);
c) for (i=0, i<5, i++) printf("%d",i);
d) for (i=0; i<5, i++) printf("%d",i);
✅ Answer: b) for (i=0; i<5; i++) printf("%d",i);
Break, Continue & Goto
21. Where can break be used?
a) Loops only
b) switch only
c) Loops and switch
d) Anywhere
✅ Answer: c) Loops and switch
22. What happens with continue in a for loop?
a) Skips to condition check, then increments counter
b) Ends loop immediately
c) Goes to default case
d) Restarts loop from beginning
✅ Answer: a) Skips to condition check, then increments counter
23. Which is discouraged in structured programming but supported in C?
a) break
b) continue
c) goto
d) switch
✅ Answer: c) goto
24. What is the output?
int i=0;
do {
i++;
if(i==2) continue;
printf("%d", i);
} while(i<3);
a) 1 2 3
b) 1 3
c) 2 3
d) Infinite loop
✅ Answer: b) 1 3
25. Which is the output?
for (int i=1; i<=5; i++) {
if(i==3) break;
printf("%d ", i);
}
a) 1 2 3 4 5
b) 1 2 3
c) 1 2
d) None
✅ Answer: c) 1 2
26. What is the output?
int i=1;
while(i<1) {
printf("Hello");
i++;
}
a) Hello
b) Hello (infinite)
c) Nothing
d) Error
✅ Answer: c) Nothing
27. How many times will this loop run?
for(int i=0; i<10; i+=2) { }
a) 5
b) 10
c) Infinite
d) 9
✅ Answer: a) 5
28. Which keyword can make an infinite loop exit safely?
a) end
b) break
c) continue
d) stop
✅ Answer: b) break
29. What is the output?
int i=0;
while(++i < 3) printf("%d", i);
a) 012
b) 123
c) 12
d) 23
✅ Answer: c) 12
30. Which loop is most suitable for menu-driven programs?
a) while
b) do–while
c) for
d) goto
✅ Answer: b) do–while
31. How many times will this run?
for(int i=1; i<=5; i=i+2);
a) 2
b) 3
c) 5
d) 0
✅ Answer: b) 3
32. Which loop condition is always true?
a) while(1)
b) while(0)
c) do { } while(0)
d) for( ; 0 ; )
✅ Answer: a) while(1)
33. What is the output?
for(int i=0; i<3; i++) {
for(int j=0; j<2; j++) {
printf("*");
}
}
a) ***
b) ******
c) *****
d) None
✅ Answer: b) ******
34. Which loop runs fastest?
a) while
b) for
c) do–while
d) All same (depends on compiler optimization)
✅ Answer: d) All same (depends on compiler optimization)
35. What is the output?
int i=0;
do {
printf("%d", i);
} while(i!=0);
a) Nothing
b) 0 (once)
c) Infinite 0
d) Error
✅ Answer: b) 0 (once)
Nested Control Structures
36. What is the output?
int x=1, y=0;
if(x)
if(y) printf("A");
else printf("B");
a) A
b) B
c) Nothing
d) Error
✅ Answer: b) B
37. Which rule is applied to resolve nested if–else ambiguity?
a) Else pairs with first if
b) Else pairs with nearest unmatched if
c) Else pairs with last if
d) None
✅ Answer: b) Else pairs with nearest unmatched if
38. What is the output?
int a=2;
switch(a) {
case 1: printf("One"); break;
case 2: printf("Two");
case 3: printf("Three"); break;
default: printf("Other");
}
a) Two
b) TwoThree
c) Other
d) Three
✅ Answer: b) TwoThree
39. Can switch be nested inside another switch?
a) No
b) Yes
c) Only inside loops
d) Only if using enums
✅ Answer: b) Yes
40. Which is invalid in switch-case?
a) case 1+2:
b) case 'A':
c) case 2.5:
d) case 0:
✅ Answer: c) case 2.5:
Break, Continue, Goto (continued)
41. Which is true about continue in a while loop?
a) Goes to start of loop and checks condition again
b) Exits loop
c) Skips loop entirely
d) Ends program
✅ Answer: a) Goes to start of loop and checks condition again
42. Which is true about goto?
a) Must always jump forward
b) Can jump forward or backward in same function
c) Can jump between functions
d) Illegal in C
✅ Answer: b) Can jump forward or backward in same function
43. What is the output?
int i=1;
loop:
printf("%d ", i);
i++;
if(i<=3) goto loop;
a) 1 2
b) 1 2 3
c) 1 2 3 4
d) Infinite loop
✅ Answer: b) 1 2 3
44. Which is more structured alternative to goto?
a) switch
b) break
c) loops
d) recursion
✅ Answer: d) recursion
45. Can goto cross variable initialization scopes?
a) Yes, always safe
b) No, may cause undefined behavior
c) Allowed only in main
d) Compiler prevents it
✅ Answer: b) No, may cause undefined behavior
Output-based Questions
46. What is the output?
int i=0;
for( ; i<3; ) {
printf("%d", i);
i++;
}
a) 0 1 2
b) 1 2 3
c) Infinite loop
d) Error
✅ Answer: a) 0 1 2
47. Output?
int x=0;
if(x=10) printf("Yes");
else printf("No");
a) Yes
b) No
c) Error
d) Undefined
✅ Answer: a) Yes (assignment makes x=10 → true)
48. Output?
for(int i=0; i<2; i++)
for(int j=0; j<2; j++)
if(i==j) continue;
else printf("%d%d ", i,j);
a) 01 10 11
b) 01 10
c) 00 11
d) None
✅ Answer: b) 01 10
49. Output?
switch(2) {
case 1: printf("One");
case 2: printf("Two");
case 3: printf("Three");
}
a) Two
b) TwoThree
c) OneTwoThree
d) Nothing
✅ Answer: b) TwoThree
50. Output?
int i=1;
while(i<=3)
printf("%d", i++);
a) 123
b) 012
c) 111
d) 0 1 2 3
✅ Answer: a) 123
More Conceptual MCQs
51. Which is more efficient for checking multiple ranges?
a) if–else ladder
b) switch
c) goto
d) continue
✅ Answer: a) if–else ladder
52. Which of these loops can be written without all 3 parts?
a) for
b) while
c) do–while
d) switch
✅ Answer: a) for (all expressions optional)
53. Which statement is true?
a) Loops must contain a break
b) Loops must contain continue
c) Loops can be infinite if not controlled
d) Loops cannot be nested
✅ Answer: c) Loops can be infinite if not controlled
54. Which control structure is known as a multi-way branch?
a) if–else
b) switch
c) while
d) goto
✅ Answer: b) switch
55. What is the output?
int n=5;
if(n%2==0)
printf("Even");
else
printf("Odd");
a) Even
b) Odd
c) Error
d) None
✅ Answer: b) Odd
56. Which loop can decrement automatically in syntax?
a) for(i=n; i>0; i--)
b) while(i--)
c) do–while(i--)
d) All of the above
✅ Answer: d) All of the above
57. Which is invalid?
a) break 2;
b) break;
c) continue;
d) goto label;
✅ Answer: a) break 2; (not in C, only in some languages)
58. Which statement about for loop is false?
a) Initialization can have multiple variables
b) Condition can be empty
c) Increment can be empty
d) Body cannot be empty
✅ Answer: d) Body cannot be empty (it can be empty with ;)
59. Which is true about nested loops?
a) Only one break exits all loops
b) break only exits current loop
c) continue exits all loops
d) continue exits program
✅ Answer: b) break only exits current loop
60. Which keyword ensures at least one execution?
a) do
b) while
c) for
d) goto
✅ Answer: a) do
Trickier Questions
61. What is the output?
int i=0;
for(; ; ) {
if(i==3) break;
printf("%d", i);
i++;
}
a) 012
b) 123
c) Infinite loop
d) Error
✅ Answer: a) 012
62. What is the output?
int i=2;
switch(i) {
case 1: printf("One");
default: printf("Default");
case 2: printf("Two");
}
a) DefaultTwo
b) OneDefaultTwo
c) Two
d) Default
✅ Answer: a) DefaultTwo (fall-through)
63. What is the output?
int x=5;
if(x>0)
if(x<10) printf("Small");
else printf("Big");
a) Small
b) Big
c) Error
d) None
✅ Answer: a) Small
64. What happens if both if and else are missing?
a) Error
b) Code executes normally without branching
c) Program crashes
d) Undefined behavior
✅ Answer: b) Code executes normally without branching
65. Which of these is not valid loop control variable?
a) int i
b) float f
c) char c
d) double d
✅ Answer: b) float f (floating comparisons may cause problems)
66. Which is better for checking string values?
a) switch
b) if with strcmp
c) goto
d) continue
✅ Answer: b) if with strcmp
67. Which is the output?
for(int i=0; i<2; i++) {
for(int j=0; j<2; j++) {
if(i+j==1) break;
printf("%d%d ", i,j);
}
}
a) 00 10
b) 00 01 10
c) 00
d) None
✅ Answer: c) 00
68. Which type of control structure reduces code repetition?
a) Loops
b) goto
c) if
d) break
✅ Answer: a) Loops
69. Which is true about conditional operator ?:?
a) Alternative to if–else
b) Can return a value
c) Right-associative
d) All of the above
✅ Answer: d) All of the above
70. Which is the output?
int a=1, b=2;
printf("%d", (a>b)?a:b);
a) 1
b) 2
c) Error
d) None
✅ Answer: b) 2
Basics of Functions
1. Which keyword is used to declare a function in C?
a) def
b) func
c) void/int/char etc.
d) function
✅ Answer: c) void/int/char etc.
2. Which part defines the return type of a function?
a) Function name
b) Function parameters
c) Data type before function name
d) Function body
✅ Answer: c) Data type before function name
3. What is a function prototype?
a) Function without body
b) Function with body
c) Function returning void
d) Function inside main
✅ Answer: a) Function without body
4. Where should a prototype usually be placed?
a) After main
b) Before main
c) Inside main
d) In printf
✅ Answer: b) Before main
5. Which of these is a valid prototype?
a) int add(a, b);
b) int add(int, int);
c) int add();
d) All of the above
✅ Answer: b) int add(int, int);
6. Can main() return a value?
a) No
b) Yes
c) Only in C++
d) Only if void main()
✅ Answer: b) Yes
7. Which is the default return type if not specified? (in old C)
a) void
b) int
c) char
d) float
✅ Answer: b) int
8. What happens if a function doesn’t return a value but has int return type?
a) Compiler error
b) Warning / undefined behavior
c) Executes normally
d) Skips function
✅ Answer: b) Warning / undefined behavior
9. Which is a correct function call?
a) add;
b) add();
c) add;();
d) call add();
✅ Answer: b) add();
10. Which keyword is used to return a value?
a) return
b) exit
c) break
d) continue
✅ Answer: a) return
Parameters and Arguments
11. Which are the two methods of parameter passing?
a) by value & by reference
b) by call & by goto
c) by stack & by heap
d) by copy & by paste
✅ Answer: a) by value & by reference
12. Which method does C use by default?
a) Call by reference
b) Call by value
c) Both
d) None
✅ Answer: b) Call by value
13. If a function modifies its arguments, will changes reflect in caller?
a) Always
b) Never (in call by value)
c) Only if passed by reference
d) Only if global
✅ Answer: b) Never (in call by value)
14. Which is valid?
a) void f(int a, b);
b) void f(int a, int b);
c) void f(a, b);
d) void f(int, int);
✅ Answer: b) void f(int a, int b);
15. Which is valid function declaration?
a) int f();
b) int f(void);
c) Both a & b
d) None
✅ Answer: c) Both a & b
16. Can function parameters have default values in C?
a) Yes
b) No
c) Only in C++
d) Only in macros
✅ Answer: b) No
17. What is the output?
void f(int x) {
x = x + 5;
printf("%d", x);
}
int main() {
int a=10;
f(a);
printf("%d", a);
}
a) 1510
b) 1015
c) 1010
d) 1515
✅ Answer: a) 1510
18. Which allows permanent change of arguments?
a) Call by value
b) Call by reference using pointers
c) Passing literals
d) Global constants
✅ Answer: b) Call by reference using pointers
19. Which is not allowed in function parameters?
a) int *p
b) char arr[]
c) int &x
d) float x
✅ Answer: c) int &x (reference not in C, only C++)
20. What happens if too few arguments are passed?
a) Compiler error
b) Garbage values used for missing arguments
c) Function executes partially
d) Program crashes
✅ Answer: a) Compiler error
Scope and Storage Classes
21. Which variable is local to a function?
a) Declared inside function
b) Declared outside function
c) Declared with extern
d) Declared with static
✅ Answer: a) Declared inside function
22. What is the lifetime of a local variable?
a) Entire program
b) Until function ends
c) Infinite
d) Until compiler ends
✅ Answer: b) Until function ends
23. Which keyword makes a variable retain its value between calls?
a) const
b) static
c) register
d) extern
✅ Answer: b) static
24. Which keyword makes a variable global across files?
a) static
b) extern
c) global
d) share
✅ Answer: b) extern
25. Which storage class requests CPU registers for variables?
a) auto
b) static
c) register
d) extern
✅ Answer: c) register
26. Which is default storage class for local variables?
a) auto
b) static
c) register
d) extern
✅ Answer: a) auto
27. Which keyword defines scope inside file only?
a) static
b) extern
c) global
d) local
✅ Answer: a) static
28. Can static variables be initialized inside a function?
a) Yes
b) No
c) Only once globally
d) Only with extern
✅ Answer: a) Yes
29. Which is the default initial value of static variables?
a) 0
b) Garbage
c) Null
d) Compiler dependent
✅ Answer: a) 0
30. Which storage class has highest life span?
a) auto
b) register
c) static
d) extern
✅ Answer: d) extern (global variables)
Recursion
31. What is recursion?
a) Function calling itself
b) Function calling main
c) Function calling printf
d) Function without return
✅ Answer: a) Function calling itself
32. Which must be present in recursion?
a) Infinite loop
b) Base condition
c) printf
d) goto
✅ Answer: b) Base condition
33. What happens if base condition is missing?
a) Compiler error
b) Infinite recursion → stack overflow
c) Executes once
d) Undefined but safe
✅ Answer: b) Infinite recursion → stack overflow
34. Which is true about recursion?
a) Always faster than loops
b) Uses stack memory
c) Cannot return values
d) Cannot pass arguments
✅ Answer: b) Uses stack memory
35. Which type of recursion calls itself last?
a) Head recursion
b) Tail recursion
c) Nested recursion
d) Indirect recursion
✅ Answer: b) Tail recursion
36. Which recursion happens if function calls itself before processing?
a) Head recursion
b) Tail recursion
c) Mutual recursion
d) Tree recursion
✅ Answer: a) Head recursion
37. Which recursion involves multiple calls in one function?
a) Linear recursion
b) Tree recursion
c) Indirect recursion
d) Nested recursion
✅ Answer: b) Tree recursion
38. Which recursion involves two or more functions calling each other?
a) Tail
b) Indirect
c) Nested
d) Head
✅ Answer: b) Indirect
39. Which recursion is hardest to optimize?
a) Tail
b) Head
c) Tree
d) Direct
✅ Answer: c) Tree
40. Which recursion is easiest to convert to iteration?
a) Tail recursion
b) Head recursion
c) Tree recursion
d) Indirect recursion
✅ Answer: a) Tail recursion
41. What is the output?
int fact(int n) {
if(n==0) return 1;
return n*fact(n-1);
}
int main() {
printf("%d", fact(3));
}
a) 3
b) 6
c) 0
d) Error
✅ Answer: b) 6
42. What is the output?
int fib(int n) {
if(n<=1) return n;
return fib(n-1)+fib(n-2);
}
int main() {
printf("%d", fib(4));
}
a) 2
b) 3
c) 5
d) 4
✅ Answer: b) 3
43. Which recursion uses more memory?
a) Iteration
b) Recursion
c) Both same
d) None
✅ Answer: b) Recursion
44. What is the output?
void f(int n) {
if(n==0) return;
printf("%d", n);
f(n-1);
}
int main() {
f(3);
}
a) 123
b) 321
c) 111
d) Error
✅ Answer: b) 321
45. What is the output?
void f(int n) {
if(n==0) return;
f(n-1);
printf("%d", n);
}
int main() {
f(3);
}
a) 321
b) 123
c) 111
d) Error
✅ Answer: b) 123
46. Which recursion can be optimized by compilers?
a) Tail recursion
b) Head recursion
c) Tree recursion
d) Nested recursion
✅ Answer: a) Tail recursion
47. Which function is typically implemented using recursion?
a) Factorial
b) Fibonacci
c) Tower of Hanoi
d) All of the above
✅ Answer: d) All of the above
48. What is the output of infinite recursion?
a) Normal termination
b) Program crash (stack overflow)
c) Compiler error
d) None
✅ Answer: b) Program crash (stack overflow)
49. Which recursion mimics depth-first search?
a) Head recursion
b) Tree recursion
c) Tail recursion
d) None
✅ Answer: b) Tree recursion
50. Which recursion can have multiple base cases?
a) Only head recursion
b) Only tail recursion
c) Any recursion
d) None
✅ Answer: c) Any recursion
Function Pointers
51. What is a function pointer?
a) Pointer to variable
b) Pointer to memory block
c) Pointer storing function address
d) None
✅ Answer: c) Pointer storing function address
52. Which is correct declaration of function pointer?
a) int f();
b) int (f)();
c) int f();
d) func int();
✅ Answer: b) int (*f)();
53. How to call function through pointer?
a) f();
b) (*f)();
c) f;();
d) &f();
✅ Answer: b) (*f)();
54. Which is the use of function pointers?
a) Callbacks
b) Dynamic function calls
c) Table-driven programs
d) All of the above
✅ Answer: d) All of the above
55. Can function pointers point to main()?
a) Yes
b) No
c) Only in C++
d) Only with extern
✅ Answer: a) Yes
56. Which is true about function pointers?
a) They can be stored in arrays
b) They can be passed to functions
c) They can be returned from functions
d) All of the above
✅ Answer: d) All of the above
57. Which operator is used to get function address?
a) &
b) *
c) ->
d) .
✅ Answer: a) &
58. Which function is often used with function pointers in C standard library?
a) malloc
b) qsort
c) printf
d) scanf
✅ Answer: b) qsort
59. Which type of variable can’t be pointed by a function pointer?
a) int
b) char
c) float
d) None (function pointer points to functions, not variables)
✅ Answer: d) None
60. Which is invalid?
a) void (*fp)();
b) int (*fp)(int);
c) char (fp)(char);
d) int &(*fp)();
✅ Answer: d) int &(*fp)(); (reference not in C)
Advanced Concepts
61. Can functions be nested in C?
a) Yes
b) No
c) Only inline functions
d) Only in C++
✅ Answer: b) No
62. What is an inline function in C (GNU extension)?
a) Function defined inside another
b) Function expanded like macro
c) Function with recursion
d) Function inside main
✅ Answer: b) Function expanded like macro
63. Which function is always called first in a C program?
a) printf
b) main
c) start
d) init
✅ Answer: b) main
64. Which function terminates a program immediately?
a) stop()
b) break()
c) exit()
d) end()
✅ Answer: c) exit()
65. Which header file defines exit()?
a) stdio.h
b) stdlib.h
c) conio.h
d) string.h
✅ Answer: b) stdlib.h
66. Which function is used to handle errors before exit?
a) perror()
b) printf()
c) scanf()
d) strcat()
✅ Answer: a) perror()
67. Which function can return multiple values?
a) Any function
b) By using pointers
c) By using arrays
d) By using structs
✅ Answer: b), c), and d) (not directly multiple returns, but indirectly)
68. Which function must be declared before calling?
a) User-defined functions
b) Built-in library functions
c) Both
d) None
✅ Answer: a) User-defined functions
69. Which function cannot be recursive?
a) main()
b) printf()
c) Any user-defined function can be recursive
d) None
✅ Answer: c) Any user-defined function can be recursive
70. Which recursion problem is classic for C programming?
a) Factorial
b) Fibonacci
c) Tower of Hanoi
d) All of the above
✅ Answer: d) All of the above
Basics of Arrays
1. What is an array?
a) Collection of different data types
b) Collection of similar data types stored in contiguous memory
c) Collection of functions
d) None
✅ Answer: b) Collection of similar data types stored in contiguous memory
2. Which is the correct declaration of an array in C?
a) int arr;
b) int arr[5];
c) int arr(5);
d) array int arr[5];
✅ Answer: b) int arr[5];
3. What is the index range of an array of size 10?
a) 0 to 10
b) 1 to 10
c) 0 to 9
d) 1 to 9
✅ Answer: c) 0 to 9
4. What is the default initial value of an array element in C (local scope)?
a) 0
b) Garbage value
c) Null
d) -1
✅ Answer: b) Garbage value
5. What is the default initial value of a static/global array element?
a) Garbage
b) 0
c) Null
d) Random
✅ Answer: b) 0
6. Which is valid initialization?
a) int a[3] = {1, 2, 3};
b) int a[3] = {1, 2};
c) int a[] = {1, 2, 3, 4};
d) All of the above
✅ Answer: d) All of the above
7. What is the size of this array?
int a[] = {1, 2, 3};
a) 2
b) 3
c) 4
d) Undefined
✅ Answer: b) 3
8. Which of these is invalid?
a) int a[5] = {0};
b) int a[5] = {1,2,3,4,5,6};
c) int a[] = {1,2,3};
d) int a[3] = {1};
✅ Answer: b) int a[5] = {1,2,3,4,5,6};
9. What will this output?
int a[5] = {1,2};
printf("%d", a[2]);
a) 0
b) 2
c) Garbage
d) Error
✅ Answer: a) 0
10. Which is true about arrays?
a) Size must be constant in C89
b) Size can be variable in C99 (VLA)
c) Name of array acts as pointer to first element
d) All of the above
✅ Answer: d) All of the above
Array and Memory
11. If int a[10]; and int = 4 bytes, what is sizeof(a)?
a) 10
b) 40
c) 4
d) Undefined
✅ Answer: b) 40
12. What does a represent in array context?
a) Base address (pointer to first element)
b) Last element
c) Size of array
d) None
✅ Answer: a) Base address (pointer to first element)
13. What is *(a+3) equal to?
a) a[3]
b) a+3
c) &a[3]
d) a[2]
✅ Answer: a) a[3]
14. Which is invalid?
a) a[i] = *(a+i)
b) i[a] = a[i]
c) *a = a[0]
d) a++
✅ Answer: d) a++
15. Which operator is used to find array size?
a) length
b) sizeof
c) count
d) size()
✅ Answer: b) sizeof
16. Which statement is true?
a) Arrays are passed by value
b) Arrays are passed by reference (actually pointer to first element)
c) Arrays cannot be passed
d) Arrays are copied fully
✅ Answer: b) Arrays are passed by reference (pointer)
17. Which is true about multi-dimensional arrays?
a) Stored row-major in C
b) Stored column-major in C
c) Stored randomly
d) User chooses storage
✅ Answer: a) Stored row-major in C
18. Which declaration is valid?
a) int a[2][3];
b) int a[][3] = {{1,2,3},{4,5,6}};
c) int a[2][3] = {1,2,3,4,5,6};
d) All of the above
✅ Answer: d) All of the above
19. Which is invalid for 2D array?
a) a[1][2]
b) ((a+1)+2)
c) a[1,2]
d) *(a[1]+2)
✅ Answer: c) a[1,2]
20. What is the size of int a[3][4]; if int=4 bytes?
a) 7
b) 12
c) 48
d) 16
✅ Answer: c) 48
Strings (Character Arrays)
21. How are strings stored in C?
a) As int arrays
b) As char arrays ending with '\0'
c) As objects
d) As structures
✅ Answer: b) As char arrays ending with '\0'
22. Which is valid string initialization?
a) char s[] = "Hello";
b) char s[6] = "Hello";
c) char s[10] = "Hello";
d) All of the above
✅ Answer: d) All of the above
23. What is the size of char s[]="Hi";?
a) 2
b) 3
c) 4
d) Undefined
✅ Answer: b) 3 (H,i,\0)
24. Which is invalid?
a) char s[]="Hi";
b) char *p="Hi";
c) char s[2]="Hi";
d) char s[3]={'H','i','\0'};
✅ Answer: c) char s[2]="Hi";
25. Which library handles string functions?
a) stdio.h
b) string.h
c) stdlib.h
d) conio.h
✅ Answer: b) string.h
26. Which function returns string length?
a) strlen
b) strcpy
c) strcat
d) strcmp
✅ Answer: a) strlen
27. What does strcmp("abc","abd") return?
a) 0
b) <0
c) >0
d) Error
✅ Answer: b) <0
28. Which copies one string to another?
a) strcpy
b) strcat
c) strlen
d) strdup
✅ Answer: a) strcpy
29. Which concatenates strings?
a) strcpy
b) strcat
c) strcmp
d) strjoin
✅ Answer: b) strcat
30. Which function compares two strings ignoring case?
a) strcmpi / strcasecmp
b) strcmp
c) strlen
d) stricmp only in C++
✅ Answer: a) strcmpi / strcasecmp (compiler dependent)
String Output
31. What is the output?
char s[]="C";
printf("%d", strlen(s));
a) 0
b) 1
c) 2
d) Error
✅ Answer: b) 1
32. Output?
char s[10]="Hi";
printf("%c", s[1]);
a) H
b) i
c) \0
d) Error
✅ Answer: b) i
33. Output?
char s[5]="Hi";
printf("%s", s);
a) Hi
b) Hi\0
c) H
d) Error
✅ Answer: a) Hi
34. Output?
char s[5]={'H','i'};
printf("%s", s);
a) Hi
b) Garbage
c) Error
d) None
✅ Answer: b) Garbage (no '\0')
35. Output?
char *p="Hello";
printf("%c", *(p+4));
a) H
b) e
c) o
d) \0
✅ Answer: c) o
36. Which is true about char *p="Hello";?
a) p points to string literal in read-only memory
b) Modifying is undefined
c) Safer: char arr[]="Hello";
d) All of the above
✅ Answer: d) All of the above
37. What is the output?
char s[]="ABC";
s[1]='X';
printf("%s",s);
a) ABC
b) AXC
c) XBC
d) Error
✅ Answer: b) AXC
38. Which is invalid string function?
a) strcpy
b) strcat
c) strcmp
d) stradd
✅ Answer: d) stradd
39. Which function finds substring?
a) strstr
b) strchr
c) strrchr
d) All
✅ Answer: a) strstr
40. Which finds first occurrence of char in string?
a) strchr
b) strrchr
c) strstr
d) strcmp
✅ Answer: a) strchr
41. Which function copies n characters?
a) strncpy
b) strcpy
c) memcpy
d) memmove
✅ Answer: a) strncpy
42. Which function sets memory with a character?
a) memset
b) memcpy
c) memchr
d) memfill
✅ Answer: a) memset
43. Which function compares n characters?
a) strcmp
b) strncmp
c) stricmp
d) strcompare
✅ Answer: b) strncmp
44. What is returned by strlen("C Programming")?
a) 11
b) 12
c) 13
d) 14
✅ Answer: b) 12 (no. of characters, excluding '\0')
45. What is stored in the last element of string array?
a) Last character
b) \0 (null character)
c) Garbage
d) Space
✅ Answer: b) \0
46. Which is correct?
a) "A" is a char constant
b) 'A' is a string constant
c) "A" is a string constant
d) 'A' is a string constant of length 1
✅ Answer: c) "A" is a string constant
47. What is the output?
char str1[]="Hi", str2[]="Hi";
if(str1==str2) printf("Equal");
else printf("Not Equal");
a) Equal
b) Not Equal
c) Error
d) Garbage
✅ Answer: b) Not Equal (arrays at different addresses)
48. What is the output?
char *s1="Hi", *s2="Hi";
if(s1==s2) printf("Equal");
else printf("Not Equal");
a) Equal
b) Not Equal
c) Error
d) Garbage
✅ Answer: a) Equal (string literals point to same location)
49. Which is safer for modifying string?
a) char *s="Hello";
b) char s[]="Hello";
c) Both
d) None
✅ Answer: b) char s[]="Hello";
50. Which is true about gets()?
a) Reads string until newline
b) Unsafe, may cause buffer overflow
c) Deprecated in C11
d) All of the above
✅ Answer: d) All of the above
Arrays and Functions
51. When passing array to function, what is passed?
a) Full array copy
b) Base address (pointer)
c) Size of array
d) None
✅ Answer: b) Base address (pointer)
52. Can function return array?
a) Yes, directly
b) No, but can return pointer
c) Only in C++
d) None
✅ Answer: b) No, but can return pointer
53. Which is valid parameter for function?
a) int a[]
b) int *a
c) Both
d) None
✅ Answer: c) Both
54. What is output?
void fun(int arr[]) {
printf("%d", sizeof(arr));
}
int main() {
int a[10];
fun(a);
}
a) 40
b) 10
c) 4 (or 8 depending on system)
d) Error
✅ Answer: c) 4 (or 8) → array decays to pointer
55. What is advantage of arrays?
a) Random access
b) Contiguous memory
c) Easy iteration
d) All
✅ Answer: d) All
56. Disadvantage of arrays?
a) Fixed size
b) Wastage of memory
c) Insertion/deletion costly
d) All
✅ Answer: d) All
57. Which is correct about array name in function?
a) Acts as pointer
b) Size info is lost
c) Cannot calculate no. of elements
d) All
✅ Answer: d) All
58. What is the output?
int a[5]={1,2,3,4,5};
printf("%d", *a+2);
a) 1
b) 2
c) 3
d) 4
✅ Answer: c) 3 ( *a = 1, 1+2=3 )
59. What is output?
int a[5]={1,2,3,4,5};
printf("%d", *(a+2));
a) 2
b) 3
c) 4
d) 5
✅ Answer: b) 3
60. What is output?
char s[]="CProg";
printf("%c", 2[s]);
a) r
b) o
c) g
d) P
✅ Answer: b) o (2[s] = s[2])
Advanced Concepts
61. Which keyword is used to allocate memory dynamically for arrays?
a) new
b) malloc
c) calloc
d) Both b & c
✅ Answer: d) Both b & c
62. Which allocates memory initialized to 0?
a) malloc
b) calloc
c) realloc
d) free
✅ Answer: b) calloc
63. Which frees memory?
a) free
b) delete
c) remove
d) clear
✅ Answer: a) free
64. Which reallocates memory size?
a) realloc
b) malloc
c) calloc
d) reassign
✅ Answer: a) realloc
65. Which is not string function?
a) strrev
b) strlen
c) strcpy
d) stricmp
✅ Answer: a) strrev (not standard C)
66. Which header defines memory functions like memcpy?
a) memory.h
b) string.h
c) stdlib.h
d) ctype.h
✅ Answer: b) string.h
67. What is output?
char s1[]="Hello", s2[10];
strcpy(s2,s1);
printf("%s",s2);
a) Hello
b) H
c) Garbage
d) Error
✅ Answer: a) Hello
68. What is output?
char s[]="Hello";
printf("%d", sizeof(s));
a) 5
b) 6
c) 7
d) Error
✅ Answer: b) 6 (includes '\0')
69. What is output?
char s[]="Hello";
printf("%d", strlen(s));
a) 5
b) 6
c) 7
d) Error
✅ Answer: a) 5 (excludes '\0')
70. Which of the following is true?
a) strlen counts '\0'
b) sizeof counts '\0'
c) Both count '\0'
d) None
✅ Answer: b) sizeof counts '\0'
Basics of Pointers
1. What is a pointer in C?
a) Variable that stores an integer
b) Variable that stores address of another variable
c) Special constant
d) Keyword in C
✅ Answer: b) Variable that stores address of another variable
2. Which symbol is used to declare a pointer?
a) *
b) &
c) ->
d) %
✅ Answer: a) *
3. Which operator is used to get the address of a variable?
a) *
b) &
c) ->
d) %
✅ Answer: b) &
4. What does the * operator do when applied to a pointer?
a) Address of variable
b) Value at the address (dereference)
c) Size of pointer
d) None
✅ Answer: b) Value at the address (dereference)
5. What is the size of a pointer on a 64-bit system?
a) 2 bytes
b) 4 bytes
c) 8 bytes
d) Depends on data type
✅ Answer: c) 8 bytes
6. What is the output?
int x=10;
int *p=&x;
printf("%d",*p);
a) 10
b) Address of x
c) Garbage
d) Error
✅ Answer: a) 10
7. Which declaration is correct?
a) int p;
b) int p;
c) *int p;
d) int &p;
✅ Answer: a) int *p;
8. Which statement is true?
a) Pointer size depends on data type it points to
b) Pointer size is fixed for architecture
c) Both
d) None
✅ Answer: b) Pointer size is fixed for architecture
9. What is NULL pointer?
a) Points to 0 address
b) Points to garbage
c) Points to undefined memory
d) Points to -1
✅ Answer: a) Points to 0 address
10. Which header defines NULL?
a) stdlib.h
b) stdio.h
c) string.h
d) stddef.h
✅ Answer: d) stddef.h
Pointer Arithmetic
11. If int *p; then p++ increments pointer by?
a) 1 byte
b) 2 bytes
c) sizeof(int)
d) Undefined
✅ Answer: c) sizeof(int)
12. If int=4 bytes, what happens when pointer to int is incremented?
a) Address increases by 1
b) Address increases by 4
c) Address increases by 8
d) Error
✅ Answer: b) Address increases by 4
13. If p points to a[0], what is p+1?
a) a[0]
b) a[1]
c) &a[0]
d) None
✅ Answer: b) a[1]
14. What is *(p+3) equal to?
a) p[3]
b) &p[3]
c) p+3
d) None
✅ Answer: a) p[3]
15. Which is valid?
a) p[i] = *(p+i)
b) i[p] = p[i]
c) Both
d) None
✅ Answer: c) Both
16. What is the output?
int a[]={10,20,30};
int *p=a;
printf("%d",*(p+1));
a) 10
b) 20
c) 30
d) Garbage
✅ Answer: b) 20
17. Can two pointers be subtracted?
a) Yes, gives difference in bytes
b) Yes, gives difference in elements
c) No
d) Only in C++
✅ Answer: b) Yes, gives difference in elements
18. Which is not allowed?
a) p++
b) p--
c) p+p
d) p-p
✅ Answer: c) p+p
19. What does pointer comparison check?
a) Value stored
b) Address stored
c) Both
d) None
✅ Answer: b) Address stored
20. What happens if pointer points to invalid memory and dereferenced?
a) Garbage
b) Error
c) Segmentation fault
d) All
✅ Answer: c) Segmentation fault
Pointer & Arrays
21. Array name acts as?
a) Address of first element
b) Size of array
c) Value of first element
d) None
✅ Answer: a) Address of first element
22. What is equivalent to a[i]?
a) *(a+i)
b) i[a]
c) Both
d) None
✅ Answer: c) Both
23. What is output?
int a[3]={1,2,3};
printf("%d",2[a]);
a) 1
b) 2
c) 3
d) Error
✅ Answer: c) 3
24. Which is invalid?
a) a++
b) p++
c) *(a+1)
d) *(p+1)
✅ Answer: a) a++
25. What is output?
int a[5]={10,20,30,40,50};
int *p=a;
printf("%d",*(p+3));
a) 20
b) 30
c) 40
d) 50
✅ Answer: c) 40
26. What is the base type of array pointer?
a) int
b) float
c) Depends on array type
d) None
✅ Answer: c) Depends on array type
27. Can array be assigned to another directly?
a) Yes
b) No
c) Sometimes
d) Only strings
✅ Answer: b) No
28. Which is valid for 2D array access?
a) ((a+1)+2)
b) a[1][2]
c) Both
d) None
✅ Answer: c) Both
29. Pointer to 2D array declaration?
a) int **p;
b) int (*p)[3];
c) int *p[3];
d) All
✅ Answer: b) int (*p)[3];
30. **What is difference between int p[5] and int (p)[5]?
a) Both same
b) First is array of pointers, second is pointer to array
c) Both invalid
d) None
✅ Answer: b) First is array of pointers, second is pointer to array
Pointer to Pointer
31. What is a pointer to pointer?
a) Pointer storing int
b) Pointer storing address of another pointer
c) Pointer storing two addresses
d) None
✅ Answer: b) Pointer storing address of another pointer
32. Declaration of pointer to pointer to int?
a) int **p;
b) int p;
c) int &p;
d) int ***p;
✅ Answer: a) int **p;
33. If int x=5; int *p=&x; int **q=&p; what is **q?
a) Address of p
b) Address of x
c) Value of x
d) Error
✅ Answer: c) Value of x
34. What is output?
int x=10;
int *p=&x;
int **q=&p;
printf("%d",**q);
a) 10
b) Address of x
c) Address of p
d) Error
✅ Answer: a) 10
35. What is output?
int a=5;
int *p=&a;
int **q=&p;
**q=20;
printf("%d",a);
a) 5
b) 20
c) Garbage
d) Error
✅ Answer: b) 20
Pointers & Functions
36. When passing pointer to function, what is passed?
a) Copy of pointer
b) Address stored in pointer
c) Both a and b
d) None
✅ Answer: b) Address stored in pointer
37. What is call by reference in C?
a) Passing variable directly
b) Passing address using pointer
c) Both
d) None
✅ Answer: b) Passing address using pointer
38. Can function return pointer?
a) Yes
b) No
c) Only in C++
d) Only for int
✅ Answer: a) Yes
39. What is problem if function returns local variable’s address?
a) Works fine
b) Dangling pointer
c) Memory leak
d) Segmentation fault
✅ Answer: b) Dangling pointer
40. How to safely return array from function?
a) Return local array
b) Use malloc to allocate
c) Use static array
d) Both b and c
✅ Answer: d) Both b and c
41. What is output?
void fun(int *p){ *p=100; }
int main(){ int x=5; fun(&x); printf("%d",x); }
a) 5
b) 100
c) Garbage
d) Error
✅ Answer: b) 100
42. What is a function pointer?
a) Pointer to variable
b) Pointer to a function address
c) Array of functions
d) None
✅ Answer: b) Pointer to a function address
43. Declaration of pointer to function returning int and taking int?
a) int *f(int);
b) int (f)(int);
c) int f()(int);
d) int f(int *);
✅ Answer: b) int (*f)(int);
44. What is output?
int add(int x,int y){ return x+y; }
int main(){ int (*p)(int,int)=add; printf("%d",p(2,3)); }
a) 2
b) 3
c) 5
d) Error
✅ Answer: c) 5
45. What is use of function pointers?
a) Callbacks
b) Dynamic function call
c) Passing functions as arguments
d) All
✅ Answer: d) All
Void Pointer
46. What is a void pointer?
a) Pointer with unknown type
b) Null pointer
c) Dangling pointer
d) Pointer to void function
✅ Answer: a) Pointer with unknown type
47. Which operations are allowed on void pointers?
a) Arithmetic
b) Dereference directly
c) Typecast then dereference
d) None
✅ Answer: c) Typecast then dereference
48. What is output?
int x=10;
void *p=&x;
printf("%d",*(int*)p);
a) Error
b) Address of x
c) 10
d) Garbage
✅ Answer: c) 10
49. Why are void pointers useful?
a) For generic programming
b) For malloc return
c) For type independence
d) All
✅ Answer: d) All
50. Can we increment void pointer in C?
a) Yes
b) No
c) Only in C++
d) Only with typecast
✅ Answer: b) No
Dynamic Memory
51. Which allocates uninitialized memory?
a) malloc
b) calloc
c) realloc
d) free
✅ Answer: a) malloc
52. Which allocates zero-initialized memory?
a) malloc
b) calloc
c) realloc
d) free
✅ Answer: b) calloc
53. Which changes size of allocated memory?
a) realloc
b) malloc
c) calloc
d) free
✅ Answer: a) realloc
54. Which releases allocated memory?
a) delete
b) free
c) remove
d) clear
✅ Answer: b) free
55. What happens if memory not freed?
a) Nothing
b) Memory leak
c) Segmentation fault
d) Garbage values
✅ Answer: b) Memory leak
56. What is output?
int *p=malloc(3*sizeof(int));
p[0]=10; p[1]=20; p[2]=30;
printf("%d",p[1]);
a) 10
b) 20
c) 30
d) Error
✅ Answer: b) 20
57. What is returned by malloc on failure?
a) 0
b) -1
c) NULL
d) Undefined
✅ Answer: c) NULL
58. Which header includes malloc?
a) stdio.h
b) string.h
c) stdlib.h
d) memory.h
✅ Answer: c) stdlib.h
59. What is output?
int *p=calloc(4,sizeof(int));
printf("%d",p[2]);
a) 0
b) Garbage
c) NULL
d) Error
✅ Answer: a) 0
60. Which is safer to allocate memory?
a) malloc
b) calloc
c) Both same
d) None
✅ Answer: b) calloc (initialized)
Special Pointers
61. What is wild pointer?
a) Pointer initialized to 0
b) Pointer not initialized
c) Pointer to void
d) Pointer to pointer
✅ Answer: b) Pointer not initialized
62. What is dangling pointer?
a) Pointer not declared
b) Pointer pointing to freed memory
c) Null pointer
d) Pointer pointing to garbage
✅ Answer: b) Pointer pointing to freed memory
63. Which avoids dangling pointer?
a) Assign NULL after free
b) Use malloc always
c) Don’t free memory
d) None
✅ Answer: a) Assign NULL after free
64. What is far pointer?
a) Points within same segment
b) Points outside current segment (old DOS concept)
c) Null pointer
d) Void pointer
✅ Answer: b) Points outside current segment
65. What is near pointer?
a) 16-bit pointer in DOS
b) 32-bit pointer
c) 64-bit pointer
d) Void pointer
✅ Answer: a) 16-bit pointer in DOS
66. What is huge pointer?
a) 32-bit pointer in DOS
b) 64-bit pointer
c) 128-bit pointer
d) None
✅ Answer: a) 32-bit pointer in DOS
67. What is NULL pointer constant in C?
a) (void*)0
b) 0
c) Both
d) None
✅ Answer: c) Both
68. What is output?
int *p=NULL;
if(p) printf("Yes");
else printf("No");
a) Yes
b) No
c) Error
d) Garbage
✅ Answer: b) No
69. What is output?
int x=10;
int *p=&x;
int *q=p;
printf("%d",*q);
a) 10
b) Address
c) Garbage
d) Error
✅ Answer: a) 10
70. What is size of void pointer?
a) Depends on type
b) Same as other pointers
c) Undefined
d) 0
✅ Answer: b) Same as other pointers
31. What is a pointer to pointer?
a) Pointer storing another pointer’s value
b) Pointer storing an array
c) Pointer storing int
d) None
✅ Answer: a) Pointer storing another pointer’s value
32. Declaration of pointer to pointer to int:
a) int **p;
b) int p;
c) **int p;
d) int &&p;
✅ Answer: a) int **p;
33. What is output?
int x=5;
int *p=&x;
int **q=&p;
printf("%d",**q);
a) 5
b) Address of x
c) Address of p
d) Error
✅ Answer: a) 5
34. What does **q give?
a) Address of q
b) Address of p
c) Value stored in x
d) None
✅ Answer: c) Value stored in x
35. Can we have triple pointers?
a) Yes
b) No
✅ Answer: a) Yes
36. Which is correct?
a) int ***r;
b) int r;
c) int &&r;
d) *int r;
✅ Answer: a) int ***r;
37. What is output?
int a=10;
int *p=&a;
int **q=&p;
printf("%p",*q);
a) Address of a
b) Value of a
c) Garbage
d) Error
✅ Answer: a) Address of a
38. Use of pointer to pointer?
a) Passing pointer to function
b) Dynamic memory of 2D arrays
c) Both
✅ Answer: c) Both
39. What is equivalent to &p when p is pointer?
a) *p
b) **p
c) Address of pointer
d) None
✅ Answer: c) Address of pointer
40. Which is invalid?
a) *p
b) p
c) &p
d) p&
✅ Answer: d) p&
Dynamic Memory Allocation
41. Which header is needed for malloc()?
a) stdio.h
b) stdlib.h
c) string.h
d) malloc.h
✅ Answer: b) stdlib.h
42. What is malloc()?
a) Allocates memory at runtime
b) Allocates at compile time
c) Initializes memory
d) None
✅ Answer: a) Allocates memory at runtime
43. malloc() returns:
a) void *
b) int *
c) char *
d) Depends
✅ Answer: a) void *
44. calloc() initializes memory with:
a) Garbage
b) Zero
c) One
d) None
✅ Answer: b) Zero
45. Difference between malloc() and calloc()?
a) malloc() uninitialized, calloc() initialized to 0
b) malloc() for 1 block, calloc() for many
c) Both
✅ Answer: c) Both
46. free() function does what?
a) Allocates memory
b) Deallocates memory
c) Clears memory with 0
d) None
✅ Answer: b) Deallocates memory
47. Which is correct allocation for 10 ints?
a) malloc(10)
b) malloc(10sizeof(int))
c) malloc(int10)
d) None
✅ Answer: b) malloc(10*sizeof(int))
48. What is realloc()?
a) Reassigns pointer
b) Changes size of allocated block
c) Deallocates
d) None
✅ Answer: b) Changes size of allocated block
49. What happens if free() is not used?
a) Program runs faster
b) Memory leak
c) Error
d) None
✅ Answer: b) Memory leak
50. What is dangling pointer?
a) Pointer pointing to freed memory
b) Pointer not initialized
c) Pointer pointing NULL
d) None
✅ Answer: a) Pointer pointing to freed memory
Void & Function Pointers
51. What is a void pointer?
a) Pointer that points to int
b) Pointer without a data type
c) Null pointer
d) None
✅ Answer: b) Pointer without a data type
52. Can void pointer be dereferenced directly?
a) Yes
b) No, must be typecast
✅ Answer: b) No, must be typecast
53. What is output?
int x=100;
void *p=&x;
printf("%d",*(int*)p);
a) 100
b) Error
c) Garbage
d) Address
✅ Answer: a) 100
54. What is a function pointer?
a) Stores function name
b) Stores address of function
c) Calls a function
d) None
✅ Answer: b) Stores address of function
55. Declaration of function pointer to function returning int and taking two ints:
a) int (*fp)(int,int);
b) int *fp(int,int);
c) (*int fp)(int,int);
d) None
✅ Answer: a) int (*fp)(int,int);
56. What is output?
int add(int a,int b){ return a+b;}
int (*f)(int,int)=add;
printf("%d",f(2,3));
a) 2
b) 3
c) 5
d) Error
✅ Answer: c) 5
57. What is use of function pointer?
a) Callback functions
b) Passing function as argument
c) Both
✅ Answer: c) Both
58. What is pointer to function returning void?
a) void f();
b) void (*fp)();
c) void *fp();
d) None
✅ Answer: b) void (*fp)();
59. Which is correct?
a) *fp = function;
b) fp = function;
c) Both
✅ Answer: b) fp = function;
60. Can function pointer point to multiple functions?
a) Yes
b) No
✅ Answer: a) Yes
Miscellaneous
61. What is wild pointer?
a) Uninitialized pointer
b) Pointer to invalid memory
c) Both
✅ Answer: a) Uninitialized pointer
62. Which pointer always points to current function?
a) this
b) self
c) None in C
✅ Answer: c) None in C
63. What is output?
int arr[3]={1,2,3};
int *p=arr;
printf("%d",*++p);
a) 1
b) 2
c) 3
d) Error
✅ Answer: b) 2
64. What is output?
int arr[3]={1,2,3};
int *p=arr;
printf("%d",(*p)++);
a) 1
b) 2
c) 3
d) Error
✅ Answer: a) 1
65. Can we return pointer from function?
a) Yes
b) No
✅ Answer: a) Yes
66. Which is dangerous to return?
a) Pointer to local variable
b) Pointer to static variable
c) Pointer to global variable
✅ Answer: a) Pointer to local variable
67. What is output?
char *s="hello";
printf("%c",*(s+1));
a) h
b) e
c) l
d) o
✅ Answer: b) e
68. What is pointer constant?
a) Pointer cannot be modified
b) Value pointed cannot be modified
c) Both
✅ Answer: a) Pointer cannot be modified
69. What is constant pointer?
a) Pointer constant
b) Pointer to constant value
✅ Answer: b) Pointer to constant value
70. Which is correct?
a) const int *p; → value constant, pointer can change
b) int *const p; → pointer constant, value can change
c) Both
✅ Answer: c) Both
Structures Basics
1. What is a structure in C?
a) Collection of variables of same type
b) Collection of variables of different types
c) Pointer variable
d) None
✅ Answer: b) Collection of variables of different types
2. Which keyword is used to define a structure?
a) struct
b) struc
c) structure
d) record
✅ Answer: a) struct
3. Correct declaration of structure?
a) struct student { int id; char name[20]; };
b) student struct { int id; };
c) struct { int id; } student;
d) Both a & c
✅ Answer: d) Both a & c
4. What is default access in structures?
a) private
b) protected
c) public
d) Depends
✅ Answer: c) public
5. Can we declare structure inside another?
a) Yes
b) No
✅ Answer: a) Yes
6. Size of structure depends on?
a) Sum of members
b) Largest member size
c) Alignment & padding
d) None
✅ Answer: c) Alignment & padding
7. How to access structure members?
a) Dot operator (.)
b) Arrow operator (->)
c) Both
✅ Answer: c) Both
8. What is output?
struct st { int a; float b; };
struct st s={10,20.5};
printf("%d %.1f",s.a,s.b);
a) 10 20.5
b) 20.5 10
c) Error
d) Garbage
✅ Answer: a) 10 20.5
9. Which is correct?
a) struct st s;
b) st struct s;
c) struct s st;
✅ Answer: a) struct st s;
10. Can we assign one structure variable to another of same type?
a) Yes
b) No
✅ Answer: a) Yes
Structure with Pointers
11. How to access member via pointer to structure?
a) p.member
b) *p.member
c) p->member
d) (*p).member
✅ Answer: c) p->member
12. What is output?
struct st { int x; };
struct st s={100};
struct st *p=&s;
printf("%d",p->x);
a) 0
b) 100
c) Address
d) Error
✅ Answer: b) 100
13. Which is equivalent to p->x?
a) (*p).x
b) *(p.x)
c) *(p).x
✅ Answer: a) (*p).x
14. Can we pass structure to function?
a) Yes, by value
b) Yes, by pointer
c) Both
✅ Answer: c) Both
15. Which is efficient?
a) Passing structure by value
b) Passing structure by pointer
✅ Answer: b) Passing structure by pointer
16. What is output?
struct point { int x,y; };
struct point p1={1,2};
struct point p2=p1;
printf("%d %d",p2.x,p2.y);
a) 1 2
b) 0 0
c) Error
d) Garbage
✅ Answer: a) 1 2
17. What is sizeof(struct with only one char)?
a) 1
b) 2
c) Depends on compiler (padding)
✅ Answer: c) Depends on compiler (padding)
18. Structure can be nested?
a) Yes
b) No
✅ Answer: a) Yes
19. Structure inside union allowed?
a) Yes
b) No
✅ Answer: a) Yes
20. What is designated initializer in structure?
a) Initialize selectively
b) Initialize all
c) None
✅ Answer: a) Initialize selectively
Unions
21. What is union?
a) Stores multiple values simultaneously
b) Stores one value at a time
c) Stores array
d) None
✅ Answer: b) Stores one value at a time
22. Keyword for union?
a) union
b) struct
c) record
✅ Answer: a) union
23. Size of union is:
a) Sum of all members
b) Largest member size
c) Average size
d) None
✅ Answer: b) Largest member size
24. Which is correct?
a) union data { int a; float b; };
b) struct union { int a; };
✅ Answer: a) union data { int a; float b; };
25. What is output?
union u { int x; char y; };
union u u1;
u1.x=65;
printf("%c",u1.y);
a) A
b) 65
c) Error
d) Garbage
✅ Answer: a) A
26. Can union have array members?
a) Yes
b) No
✅ Answer: a) Yes
27. Which is difference between structure and union?
a) Structure stores all, union stores one at a time
b) Structure size ≥ sum, union size = largest
c) Both
✅ Answer: c) Both
28. Which operator used to access union members?
a) . and ->
b) Only .
c) Only ->
✅ Answer: a) . and ->
29. Can union have pointer members?
a) Yes
b) No
✅ Answer: a) Yes
30. What is default value of union?
a) Zero
b) Garbage
c) NULL
✅ Answer: b) Garbage
Enums
31. What is enum in C?
a) User-defined data type of named constants
b) Structure
c) Union
d) None
✅ Answer: a) User-defined data type of named constants
32. Which keyword defines enum?
a) enum
b) enumeration
c) enm
✅ Answer: a) enum
33. By default enum constants are:
a) Strings
b) Integers starting from 0
c) Integers starting from 1
✅ Answer: b) Integers starting from 0
34. Correct enum declaration:
a) enum color { RED, GREEN, BLUE };
b) color enum { RED, GREEN };
c) enum { RED=1, GREEN=2 };
d) a & c
✅ Answer: d) a & c
35. What is value of GREEN in enum {RED=3,GREEN,BLUE};
a) 3
b) 4
c) 5
✅ Answer: b) 4
36. Can enum have negative values?
a) Yes
b) No
✅ Answer: a) Yes
37. Can enum be typecast to int?
a) Yes
b) No
✅ Answer: a) Yes
38. What is output?
enum week { MON=1, TUE, WED };
printf("%d",WED);
a) 1
b) 2
c) 3
✅ Answer: c) 3
39. Can enums be used in switch?
a) Yes
b) No
✅ Answer: a) Yes
40. Enum constants are:
a) Variables
b) Compile-time constants
✅ Answer: b) Compile-time constants
Advanced (Structures, Unions, Enums Together)
41. Which is true about structures & unions?
a) Both user-defined
b) Both can have arrays & pointers
c) Both support nesting
d) All
✅ Answer: d) All
42. Can structure have enum as member?
a) Yes
b) No
✅ Answer: a) Yes
43. Can union have enum as member?
a) Yes
b) No
✅ Answer: a) Yes
44. Which is faster in memory usage?
a) Structure
b) Union
✅ Answer: b) Union
45. What is output?
enum status { ON=1, OFF=0 };
struct bulb { char name[10]; enum status st; };
struct bulb b1={"LED",ON};
printf("%d",b1.st);
a) 0
b) 1
c) Error
✅ Answer: b) 1
46. Can enums be stored in structures?
a) Yes
b) No
✅ Answer: a) Yes
47. Can unions be stored in structures?
a) Yes
b) No
✅ Answer: a) Yes
48. Can structures be stored in unions?
a) Yes
b) No
✅ Answer: a) Yes
49. What is output?
union data { int x; char y[2]; };
union data d;
d.x=512;
printf("%d",d.y[0]);
a) 0
b) 2
c) Garbage
d) Depends on endianness
✅ Answer: d) Depends on endianness
50. Which is safer for type checking?
a) enum
b) #define constants
✅ Answer: a) enum
Miscellaneous
51. Can structure contain itself directly?
a) Yes
b) No
✅ Answer: b) No
52. But can structure contain pointer to itself?
a) Yes
b) No
✅ Answer: a) Yes
53. What is self-referential structure used for?
a) Linked list
b) Trees
c) Stacks
d) All
✅ Answer: d) All
54. Which is correct?
a) struct node { int data; struct node *next; };
b) struct node { int data; node *next; };
✅ Answer: a) struct node { int data; struct node *next; };
55. What is output?
struct temp { unsigned int x:1; };
struct temp t;
t.x=2;
printf("%d",t.x);
a) 0
b) 1
c) 2
✅ Answer: b) 1
56. What is bit-field in structure?
a) Define exact bit width of members
b) Saves memory
c) Both
✅ Answer: c) Both
57. Can we use array of structures?
a) Yes
b) No
✅ Answer: a) Yes
58. Can we use pointer to array of structures?
a) Yes
b) No
✅ Answer: a) Yes
59. What is output?
struct s { int x; };
struct s arr[2]={{10},{20}};
printf("%d",arr[1].x);
a) 10
b) 20
c) Error
✅ Answer: b) 20
60. Which is valid?
a) struct A a={.x=5,.y=10};
b) struct A a={x:5,y:10};
✅ Answer: a) struct A a={.x=5,.y=10};
More MCQs (61–70)
61. Can structure members be static?
a) Yes
b) No
✅ Answer: b) No
62. Can union members be static?
a) Yes
b) No
✅ Answer: b) No
63. Which is default alignment of structure?
a) 1 byte
b) Depends on compiler & architecture
✅ Answer: b) Depends on compiler & architecture
64. What is flexible array member in structure?
a) Last member as array without size
b) Any member
✅ Answer: a) Last member as array without size
65. Which is correct flexible member?
a) struct s { int n; int arr[]; };
b) struct s { int n; int arr[0]; };
✅ Answer: a) struct s { int n; int arr[]; };
66. Can structure contain functions?
a) No in C, Yes in C++
b) Yes always
✅ Answer: a) No in C, Yes in C++
67. Can we typedef structure?
a) Yes
b) No
✅ Answer: a) Yes
68. Can enum be forward declared?
a) Yes
b) No
✅ Answer: a) Yes
69. What is output?
enum { A=1, B, C=5, D };
printf("%d %d",B,D);
a) 2 5
b) 2 6
c) 1 2
✅ Answer: b) 2 6
70. Which is true?
a) struct = heterogeneous, union = heterogeneous
b) enum = homogeneous named constants
c) All are user-defined
✅ Answer: c) All are user-defined
Basics of File Handling
1. Which header file is required for file handling?
a) stdlib.h
b) stdio.h
c) string.h
d) files.h
✅ Answer: b) stdio.h
2. Which function is used to open a file?
a) fopen()
b) open()
c) file_open()
d) ffile()
✅ Answer: a) fopen()
3. What is the return type of fopen()?
a) int
b) FILE *
c) void
d) char *
✅ Answer: b) FILE *
4. Which data type is used for file pointers?
a) struct file
b) FILE
c) file_t
d) stream
✅ Answer: b) FILE
5. Which mode is used to read a file?
a) "w"
b) "r"
c) "a"
d) "rw"
✅ Answer: b) "r"
6. Which mode creates a new file or truncates existing one?
a) "r"
b) "w"
c) "a"
d) "rw"
✅ Answer: b) "w"
7. Which mode is used to append data to a file?
a) "r"
b) "w"
c) "a"
d) "x"
✅ Answer: c) "a"
8. Which function is used to close a file?
a) fclose()
b) close()
c) f_end()
d) fileclose()
✅ Answer: a) fclose()
9. What is the return value of fclose() on success?
a) 0
b) 1
c) -1
d) NULL
✅ Answer: a) 0
10. What happens if you forget to close a file?
a) Nothing
b) Memory leak / data not saved
c) Compiler error
d) OS crash
✅ Answer: b) Memory leak / data not saved
File I/O Functions
11. Which function reads a character from file?
a) getc()
b) getchar()
c) fgetc()
d) Both a & c
✅ Answer: d) Both a & c
12. Which function writes a character to file?
a) putc()
b) fputc()
c) Both
d) None
✅ Answer: c) Both
13. Which function reads a string from file?
a) gets()
b) fgets()
c) fread()
d) fscanf()
✅ Answer: b) fgets()
14. Which function writes a string to file?
a) puts()
b) fputs()
c) fwrite()
d) fprintf()
✅ Answer: b) fputs()
15. Which function is used to read formatted input from file?
a) fscanf()
b) fread()
c) fget()
d) readf()
✅ Answer: a) fscanf()
16. Which function is used to write formatted output to file?
a) fprintf()
b) fwrite()
c) fprint()
d) writef()
✅ Answer: a) fprintf()
17. Which function is used to read binary data from file?
a) fread()
b) read()
c) fscanb()
d) bget()
✅ Answer: a) fread()
18. Which function is used to write binary data?
a) fwrite()
b) fputb()
c) writebin()
d) putbin()
✅ Answer: a) fwrite()
19. Which is correct syntax of fread()?
a) fread(ptr,size,count,fp);
b) fread(ptr,fp,size,count);
c) fread(fp,ptr,size,count);
✅ Answer: a) fread(ptr,size,count,fp);
20. Return type of fread()?
a) void
b) int
c) size_t (number of elements read)
d) FILE *
✅ Answer: c) size_t
File Positioning
21. Which function moves file pointer to specific location?
a) fseek()
b) seek()
c) rewind()
d) setpos()
✅ Answer: a) fseek()
22. Which function resets file pointer to beginning?
a) fstart()
b) rewind()
c) reset()
d) seekstart()
✅ Answer: b) rewind()
23. Which function gives current file pointer position?
a) ftell()
b) fpos()
c) fgetpos()
d) fseekpos()
✅ Answer: a) ftell()
24. Which function stores file position?
a) fgetpos()
b) fpos()
c) ftell()
✅ Answer: a) fgetpos()
25. Which function restores file position?
a) fsetpos()
b) setpos()
c) restorepos()
✅ Answer: a) fsetpos()
26. In fseek(), SEEK_SET means?
a) Current position
b) Beginning of file
c) End of file
✅ Answer: b) Beginning of file
27. In fseek(), SEEK_CUR means?
a) Current position
b) Beginning of file
c) End of file
✅ Answer: a) Current position
28. In fseek(), SEEK_END means?
a) End of file
b) Current position
c) Beginning
✅ Answer: a) End of file
29. Return type of ftell()?
a) int
b) long
c) size_t
✅ Answer: b) long
30. Return value of fseek() on success?
a) 0
b) 1
c) -1
✅ Answer: a) 0
Error Handling in Files
31. Which function checks end of file?
a) feof()
b) eof()
c) iseof()
✅ Answer: a) feof()
32. Which function checks file error?
a) ferror()
b) perror()
c) error()
✅ Answer: a) ferror()
33. Which function clears file errors?
a) clearerr()
b) reseterr()
c) cleanerr()
✅ Answer: a) clearerr()
34. What is return type of feof()?
a) int
b) bool
c) void
✅ Answer: a) int
35. Which is returned by ferror() if no error?
a) 0
b) 1
c) -1
✅ Answer: a) 0
36. Which function prints error description?
a) perror()
b) ferror()
c) printerr()
✅ Answer: a) perror()
37. What happens if fopen() fails?
a) Returns NULL
b) Returns 0
c) Returns -1
✅ Answer: a) Returns NULL
38. Which function reopens a file?
a) freopen()
b) reopen()
c) freset()
✅ Answer: a) freopen()
39. Can we check error by errno?
a) Yes
b) No
✅ Answer: a) Yes
40. Which header defines perror()?
a) stdio.h
b) errno.h
c) Both
✅ Answer: c) Both
Advanced File Handling
41. Which function deletes a file?
a) remove()
b) delete()
c) fdel()
✅ Answer: a) remove()
42. Which function renames a file?
a) rename()
b) frename()
c) changerename()
✅ Answer: a) rename()
43. Return value of remove() on success?
a) 0
b) 1
c) -1
✅ Answer: a) 0
44. Return value of rename() on failure?
a) -1
b) NULL
c) 0
✅ Answer: a) -1
45. Can file pointer be shared by multiple variables?
a) Yes
b) No
✅ Answer: a) Yes
46. Default mode of fopen()?
a) text mode
b) binary mode
✅ Answer: a) text mode
47. Which mode is used for binary read?
a) "rb"
b) "r"
c) "br"
✅ Answer: a) "rb"
48. Which mode is used for binary write?
a) "wb"
b) "bw"
c) "wr"
✅ Answer: a) "wb"
49. Which function flushes buffer of a stream?
a) fflush()
b) flush()
c) clearbuf()
✅ Answer: a) fflush()
50. Can stdin, stdout, stderr be used as FILE?*
a) Yes
b) No
✅ Answer: a) Yes
More MCQs (51–70)
51. What is default stream for printf()?
a) stdin
b) stdout
c) stderr
✅ Answer: b) stdout
52. What is default stream for scanf()?
a) stdin
b) stdout
c) stderr
✅ Answer: a) stdin
53. What is default stream for error messages?
a) stdin
b) stdout
c) stderr
✅ Answer: c) stderr
54. Which function associates file with buffer?
a) setbuf()
b) bufset()
c) fsetbuf()
✅ Answer: a) setbuf()
55. Which function allows custom buffering?
a) setvbuf()
b) setbuf()
c) fbuf()
✅ Answer: a) setvbuf()
56. What is unbuffered stream?
a) Data written immediately
b) Data stored in memory before writing
✅ Answer: a) Data written immediately
57. Which stream is unbuffered by default?
a) stdin
b) stdout
c) stderr
✅ Answer: c) stderr
58. What is line-buffered stream?
a) Data flushed when buffer full
b) Data flushed when newline
✅ Answer: b) Data flushed when newline
59. Can binary files be opened in text mode?
a) Yes but not safe
b) No
✅ Answer: a) Yes but not safe
60. Can we open multiple files in same program?
a) Yes
b) No
✅ Answer: a) Yes
61. What is maximum open files in C?
a) Depends on OS
b) Fixed 20
c) Fixed 100
✅ Answer: a) Depends on OS
62. Which function duplicates file descriptor?
a) dup()
b) dup2()
c) Both
✅ Answer: c) Both
63. Are dup() and dup2() part of stdio.h?
a) No, they are POSIX (unistd.h)
b) Yes
✅ Answer: a) No, they are POSIX (unistd.h)
64. Which is safer fread/fscanf?
a) fread (binary safe)
b) fscanf (format sensitive)
✅ Answer: a) fread
65. Which is safer fwrite/fprintf?
a) fwrite
b) fprintf
✅ Answer: a) fwrite
66. What is temporary file?
a) File deleted automatically after use
b) File stored permanently
✅ Answer: a) File deleted automatically after use
67. Which function creates temporary file?
a) tmpfile()
b) tempfile()
c) ftemp()
✅ Answer: a) tmpfile()
68. Which function generates unique temp filename?
a) tmpnam()
b) tempname()
c) ftempnam()
✅ Answer: a) tmpnam()
69. What is maximum length of filename in C (POSIX)?
a) 255
b) 100
c) 512
✅ Answer: a) 255
70. Which is correct about file handling?
a) fopen must be matched with fclose
b) fflush ensures data saved
c) fread/fwrite for binary
d) All
✅ Answer: d) All
Storage Classes
1. Which is not a storage class in C?
a) auto
b) static
c) public
d) register
✅ Answer: c) public
2. Default storage class of local variables?
a) static
b) auto
c) register
d) extern
✅ Answer: b) auto
3. Default storage class of global variables?
a) static
b) auto
c) extern
d) register
✅ Answer: c) extern
4. Which storage class retains value between function calls?
a) auto
b) static
c) register
d) extern
✅ Answer: b) static
5. Which storage class suggests compiler to keep variable in CPU register?
a) auto
b) register
c) static
d) extern
✅ Answer: b) register
6. Can we take address of register variable?
a) Yes
b) No
✅ Answer: b) No
7. Storage class for variable shared across multiple files?
a) extern
b) auto
c) static
✅ Answer: a) extern
8. Scope of static global variable?
a) Whole program
b) File scope
c) Function only
✅ Answer: b) File scope
9. Lifetime of static variable?
a) Function call
b) Program execution
c) Block execution
✅ Answer: b) Program execution
10. Keyword not valid as storage class?
a) auto
b) extern
c) static
d) dynamic
✅ Answer: d) dynamic
Command Line Arguments
11. What is signature of main() with arguments?
a) int main()
b) int main(int argc, char *argv[])
c) void main(int argc)
✅ Answer: b) int main(int argc, char *argv[])
12. What does argc store?
a) Number of arguments including program name
b) Number of arguments excluding program name
✅ Answer: a) Number of arguments including program name
13. What is argv[0]?
a) First command-line argument
b) Program name
✅ Answer: b) Program name
14. What is argv[argc]?
a) NULL
b) Last argument
c) Garbage
✅ Answer: a) NULL
15. What is type of argv?
a) char **
b) char *
c) string[]
✅ Answer: a) char **
16. If program executed as ./a.out hello world, argc = ?
a) 2
b) 3
c) 1
✅ Answer: b) 3
17. Which header required for command line args?
a) stdio.h
b) none
✅ Answer: b) none
18. What function converts string argument to int?
a) atoi()
b) atol()
c) atof()
✅ Answer: a) atoi()
19. What function converts string to float?
a) atof()
b) atoi()
c) ftoi()
✅ Answer: a) atof()
20. What library defines atoi/atof?
a) stdlib.h
b) string.h
✅ Answer: a) stdlib.h
Dynamic Memory Allocation
21. Which header file defines malloc/free?
a) stdio.h
b) stdlib.h
c) malloc.h
✅ Answer: b) stdlib.h
22. Which function allocates memory dynamically?
a) malloc()
b) calloc()
c) realloc()
d) All
✅ Answer: d) All
23. Return type of malloc()?
a) void *
b) int *
c) char *
✅ Answer: a) void *
24. What does malloc() initialize memory with?
a) 0
b) Garbage
✅ Answer: b) Garbage
25. What does calloc() initialize memory with?
a) 0
b) Garbage
✅ Answer: a) 0
26. Difference between malloc and calloc?
a) malloc initializes 0, calloc doesn’t
b) calloc initializes 0, malloc doesn’t
✅ Answer: b) calloc initializes 0, malloc doesn’t
27. Which function changes size of allocated memory?
a) realloc()
b) resize()
c) remalloc()
✅ Answer: a) realloc()
28. Which function frees allocated memory?
a) free()
b) delete()
c) remove()
✅ Answer: a) free()
29. What happens if free() not called?
a) Memory leak
b) Compiler error
✅ Answer: a) Memory leak
30. Which function is best for allocating array?
a) calloc()
b) malloc()
✅ Answer: a) calloc()
Preprocessor Directives
31. Which symbol is used for preprocessor directives?
a) #
b) $
c) @
✅ Answer: a) #
32. Which directive includes header files?
a) #include
b) #import
c) #header
✅ Answer: a) #include
33. Which directive defines macro?
a) #define
b) #macro
✅ Answer: a) #define
34. Which directive undefines macro?
a) #undef
b) #delete
✅ Answer: a) #undef
35. Which directive used for conditional compilation?
a) #ifdef
b) #endif
c) #else
d) All
✅ Answer: d) All
36. Which directive generates error?
a) #error
b) #warn
✅ Answer: a) #error
37. Which directive gives line number?
a) #line
b) #num
✅ Answer: a) #line
38. Which directive allows including file only once?
a) #pragma once
b) #include once
✅ Answer: a) #pragma once
39. Which directive suppresses warnings (compiler-specific)?
a) #pragma
b) #suppress
✅ Answer: a) #pragma
40. Preprocessor works before?
a) Compilation
b) Linking
c) Both
✅ Answer: a) Compilation
Miscellaneous
41. Which function terminates program immediately?
a) exit()
b) terminate()
c) stop()
✅ Answer: a) exit()
42. Which function is called automatically at program exit?
a) atexit()
b) onexit()
✅ Answer: a) atexit()
43. Which library defines exit()?
a) stdlib.h
b) stdio.h
✅ Answer: a) stdlib.h
44. What is return type of sizeof operator?
a) int
b) size_t
c) long
✅ Answer: b) size_t
45. Which operator cannot be overloaded in C?
a) +
b) =
c) ::
✅ Answer: c) :: (C doesn’t support overloading at all, unlike C++)
46. Which keyword restricts pointer modification?
a) const
b) static
✅ Answer: a) const
47. Which qualifier tells compiler variable may change anytime?
a) volatile
b) const
c) static
✅ Answer: a) volatile
48. Which keyword is used to inline function (compiler hint)?
a) inline
b) static
✅ Answer: a) inline
49. Which operator is used for conditional expression?
a) ? :
b) if else
✅ Answer: a) ? :
50. What is output type of sizeof('A') in C?
a) int
b) char
c) unsigned int
✅ Answer: a) int
More Advanced (51–70)
51. What is NULL pointer?
a) Pointer with address 0
b) Random pointer
✅ Answer: a) Pointer with address 0
52. Can we compare NULL with 0?
a) Yes
b) No
✅ Answer: a) Yes
53. Dangling pointer means?
a) Pointer pointing to freed memory
b) NULL pointer
✅ Answer: a) Pointer pointing to freed memory
54. Wild pointer means?
a) Uninitialized pointer
b) Freed pointer
✅ Answer: a) Uninitialized pointer
55. Function pointer stores?
a) Function address
b) Return value
✅ Answer: a) Function address
56. Which syntax declares function pointer?
a) int (*fp)(int,int);
b) int *fp(int,int);
✅ Answer: a) int (*fp)(int,int);
57. Which function allocates aligned memory (C11)?
a) aligned_alloc()
b) malloc()
✅ Answer: a) aligned_alloc()
58. Which specifier forces function not to return?
a) _Noreturn
b) noreturn
✅ Answer: a) _Noreturn
59. Which specifier tells variable may be modified asynchronously?
a) volatile
b) static
✅ Answer: a) volatile
60. What is flexible array member?
a) Array with no fixed size in struct
b) Normal array
✅ Answer: a) Array with no fixed size in struct
61. Which keyword defines constant expressions (C11)?
a) constexpr
b) _Static_assert
✅ Answer: b) _Static_assert
62. Which macro expands to current file name?
a) FILE
b) LINE
✅ Answer: a) FILE
63. Which macro expands to current line number?
a) LINE
b) FILE
✅ Answer: a) LINE
64. Which macro expands to date of compilation?
a) DATE
b) TIME
✅ Answer: a) DATE
65. Which macro expands to time of compilation?
a) TIME
b) DATE
✅ Answer: a) TIME
66. Which function copies memory block?
a) memcpy()
b) strcpy()
✅ Answer: a) memcpy()
67. Which function sets memory block with value?
a) memset()
b) setmem()
✅ Answer: a) memset()
68. Which function compares memory blocks?
a) memcmp()
b) strcmp()
✅ Answer: a) memcmp()
69. Which function moves memory block (safe overlap)?
a) memmove()
b) memcpy()
✅ Answer: a) memmove()
70. Which is true about dynamic memory?
a) malloc allocates, free releases
b) Always free after use
c) Access after free is undefined
d) All
✅ Answer: d) All