0% found this document useful (0 votes)
12 views8 pages

C Programming 50 MCQs

The document is a comprehensive C programming assessment consisting of 50 questions ranging from basic to advanced topics, including pointers, arrays, data types, operators, control flow, structures, memory management, strings, and file handling. Each section contains multiple-choice questions testing knowledge on specific C programming concepts and syntax. An answer key is provided at the end for reference.

Uploaded by

230541.it
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)
12 views8 pages

C Programming 50 MCQs

The document is a comprehensive C programming assessment consisting of 50 questions ranging from basic to advanced topics, including pointers, arrays, data types, operators, control flow, structures, memory management, strings, and file handling. Each section contains multiple-choice questions testing knowledge on specific C programming concepts and syntax. An answer key is provided at the end for reference.

Uploaded by

230541.it
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

Comprehensive C Programming Assessment

50 Questions: Basic to Advanced

Part 1: Pointers & Arrays (Questions 1-10)


1. Output?
int a[] = {10, 20, 30}; int *p = a;
printf("%d", *p++);

A) 10
B) 20
C) 11
D) 30
2. Output?
int a[] = {10, 20, 30};
printf("%d", *++p); // Assuming p reset to a

A) 10
B) 20
C) 11
D) 30
3. What does sizeof(char*) return on a standard 64-bit system?
A) 1
B) 4
C) 8
D) Depends on string length
4. Output?
char *s = "Hello"; s[0] = 'M'; printf("%s", s);

A) Mello
B) Hello
C) Compile Error
D) Runtime Error (Segfault)
5. int (*ptr)[10]; declares:
A) Array of 10 pointers to int
B) Pointer to an array of 10 ints
C) Function returning array
D) Pointer to function
6. Output?
int a[5] = {1, 2, 3, 4, 5};
int *p = (int*)(&a + 1);
printf("%d", *(p - 1));

A) 1

1
B) 5
C) Garbage
D) 4
7. Valid way to initialize a pointer to null?
A) int *p = 0;
B) int *p = NULL;
C) int *p = (void*)0;
D) All of the above
8. Result of arr[i] is equivalent to:
A) *(arr + i)
B) *arr + i
C) &(arr + i)
D) *(arr + i*sizeof(int))
9. Output?
int x = 10; int *p = &x; int **q = &p;
printf("%d", **q);

A) Address of x
B) Address of p
C) 10
D) Garbage
10. Pointer subtraction (p1 - p2) results in:
A) Difference in bytes
B) Difference in number of elements
C) Sum of addresses
D) Compile Error

Part 2: Data Types & Storage Classes (Questions 11-20)


11. sizeof('a') in C is equal to:
A) sizeof(char)
B) sizeof(int)
C) sizeof(double)
D) 1
12. Scope of a static variable inside a function?
A) Global
B) Function only
C) File only
D) Program execution
13. Default initial value of a local auto variable?
A) 0
B) 1
C) Garbage
D) Null
14. Which keyword prevents a variable from being cached in a register?
A) const
B) static

2
C) volatile
D) auto
15. Output?
float f = 0.1; if (f == 0.1) printf("Yes"); else printf("No");

A) Yes
B) No
C) Compile Error
D) Depends on OS
16. Can you take the address of a register variable?
A) Yes
B) No
C) Only if global
D) Only if static
17. void *ptr; uses:
A) 2 bytes
B) 4 bytes
C) Same as int*
D) 0 bytes
18. Output?
unsigned int i = -1; printf("%u", i);

A) -1
B) 0
C) Max Unsigned Int
D) Compile Error
19. Which is NOT a standard storage class?
A) extern
B) register
C) auto
D) dynamic
20. Correct format specifier for double?
A) %f
B) %lf
C) %d
D) %ld

Part 3: Operators & Control Flow (Questions 21-30)


21. Priority of operators (High to Low):
A) ==, =, &&
B) &&, ==, =
C) ==, &&, =
D) =, ==, &&
22. Output?
int x = 5; if(x=10) printf("T"); else printf("F");

3
A) T
B) F
C) Compile Error
D) None
23. 5 << 2 equals:
A) 10
B) 20
C) 25
D) 7
24. Output?
int i = 0; for(; i < 3; i++); printf("%d", i);

A) 012
B) 3
C) 2
D) Infinite Loop
25. switch variable cannot be:
A) int
B) char
C) float
D) enum
26. continue statement:
A) Exits loop
B) Skips rest of current iteration
C) Restarts program
D) Exits function
27. Output?
int a=1, b=1; int c = a || --b; printf("%d", b);

A) 0
B) 1
C) 2
D) -1
28. Ternary Operator syntax:
A) cond : true ? false
B) cond ? true : false
C) cond ? false : true
D) cond :: true : false
29. Result of -5 % 2:
A) 1
B) -1
C) 0
D) 2
30. Comma operator returns:
A) Leftmost operand
B) Rightmost operand
C) Sum
D) None

4
Part 4: Structures, Unions, Memory (Questions 31-40)
31. union size is determined by:
A) Sum of members
B) Largest member
C) Smallest member
D) Average
32. Accessing member of structure pointer:
A) .
B) ->
C) :
D) ::
33. Output of malloc(0)?
A) NULL
B) Implementation defined
C) Compile Error
D) Crash
34. Function to resize allocated memory?
A) alloc
B) resize
C) realloc
D) calloc
35. Padding in structures is for:
A) Security
B) Alignment/Speed
C) Memory saving
D) Syntax
36. Difference between malloc and calloc?
A) Syntax only
B) calloc initializes to zero
C) malloc initializes to zero
D) No difference
37. Self-referential structure is used for:
A) Arrays
B) Linked Lists
C) Strings
D) Macros
38. typedef is used to:
A) Create variables
B) Create pointers
C) Create aliases for types
D) Define macros
39. Bit-fields allow:
A) Arrays of bits
B) Specifying bits for struct members
C) Pointers to bits
D) None

5
40. Dangling pointer is:
A) Pointer to null
B) Pointer to freed memory
C) Uninitialized pointer
D) None

Part 5: Strings, Files, Preprocessor (Questions 41-50)


41. String ”ABC” size in bytes?
A) 3
B) 4
C) Depends on architecture
D) 2
42. fopen("[Link]", "r") returns:
A) Int file descriptor
B) File pointer FILE*
C) Void pointer
D) Boolean
43. EOF is typically:
A) 0
B) 1
C) -1
D) Null
44. Macro #define MAX(a,b) a>b?a:b. Issue with MAX(i++, j++)?
A) Syntax Error
B) Double increment
C) Type mismatch
D) None
45. #include <file> looks in:
A) Current dir
B) Standard directories
C) Root dir
D) Anywhere
46. sscanf reads from:
A) Console
B) File
C) String
D) Network
47. main(int argc, char *argv[]). argv[0] is:
A) First argument
B) Program name
C) Null
D) Argument count
48. Function used to jump in a file?
A) fjump
B) fseek

6
C) rewind
D) fmove
49. #pragma pack(1) is used to:
A) Speed up code
B) Disable padding
C) Include headers
D) Debug
50. Return type of fgetc()?
A) char
B) int
C) float
D) void*

7
Answer Key
- 1. A (Post-inc: use address, then inc) - 26. B (Skips to next iteration)

- 2. B (Pre-inc: inc address, then access) - 27. B (Short-circuit: b not decremented)


- 3. C (8 bytes on 64-bit) - 28. B (Standard ternary syntax)
- 4. D (String literal is read-only) - 29. B (Sign matches numerator in C99)

- 5. B (Pointer to array of 10 ints) - 30. B (Evaluates all, returns rightmost)


- 6. B (5; ptr math on array vs element) - 31. B (Largest member determines size)
- 7. D (0, NULL, (void*)0 all valid) - 32. B (Arrow operator for pointers)
- 8. A (Definition of array indexing) - 33. B (Std says implementation defined)

- 9. C (Dereference twice gets value) - 34. C (realloc)


- 10. B (Diff in elements, not bytes) - 35. B (CPU memory alignment)
- 11. B (char literal is int in C) - 36. B (calloc zeroes out memory)

- 12. B (Scope local, lifetime global) - 37. B (Struct containing pointer to itself)
- 13. C (Garbage/Indeterminate) - 38. C (New name for existing type)
- 14. C (Forces read from memory) - 39. B (Compact data storage)
- 15. B (0.1 is double, float loses precision) - 40. B (Points to deallocated memory)

- 16. B (Registers have no memory address) - 41. B (’A’,’B’,’C’,Null)


- 17. C (Generic pointer size = std pointer) - 42. B (Returns FILE pointer)
- 18. C (-1 wraps to Max UINT) - 43. C (Macro for -1)

- 19. D (dynamic is not a keyword) - 44. B (Side effect re-evaluation)


- 20. B (%lf for double in scanf/printf) - 45. B (Angle brackets = std lib)
- 21. C (Eq > Log AND > Assign) - 46. C (String scanf)
- 22. A (Assigns 10, which is True) - 47. B (Executable name)

- 23. B (5 × 22 = 20) - 48. B (Moves file cursor)


- 24. B (Loop runs 0,1,2. i becomes 3) - 49. B (Standard packing directive)
- 25. C (Switch requires integer types) - 50. B (Returns int to handle EOF)

You might also like