A Learning Platform

SUCCESS

Success = Discipline + Consistency + Sacrifice.
Discipline - in what you do.
Consistency - in what you do.
Sacrifice - for what you do.

                   -- Manjunatha C. P. --

C PROGRAMMING MCQ SET 7

1. Which of the following expressions has undefined behavior in C?
A) i = i + 1
B) i++
C) i = i++
D) i = i + 2

C) i = i++

2. Which of the following is guaranteed by the C standard for malloc()?
A) Memory is zero-initialized
B) Returned pointer is suitably aligned for any object type
C) Allocation always succeeds if size > 0
D) Memory comes from stack

B) Returned pointer is suitably aligned for any object type

3. What does “strict aliasing rule” primarily relate to?
A) File I/O buffering
B) Type-based pointer access assumptions by compiler
C) Macro expansion order
D) Function call stack layout

B) Type-based pointer access assumptions by compiler

4. Which of the following is the correct interpretation of “sequence point” (classic C terminology)?
A) Any semicolon
B) A point where all side effects of previous evaluations are complete
C) A compiler optimization barrier
D) A place where variables are initialized to zero

B) A point where all side effects of previous evaluations are complete

5. What is the output of: printf("%d", (1,2,3));
A) 1
B) 2
C) 3
D) Compilation error

C) 3

6. Which statement about volatile is most accurate?
A) It makes code faster by optimization
B) It forces variable into register
C) It tells compiler not to assume the value won’t change unexpectedly
D) It zero-initializes variables

C) It tells compiler not to assume the value won’t change unexpectedly

7. Which of these is an example of implementation-defined behavior?
A) Dereferencing NULL pointer
B) Signed integer overflow
C) Right shift of negative signed integer
D) Accessing freed memory

C) Right shift of negative signed integer

8. Which of the following is true about bit-fields in C?
A) You can take the address of a bit-field
B) Bit-field width must be constant integral expression
C) Bit-fields are always stored in separate bytes
D) Bit-fields can be of type float

B) Bit-field width must be constant integral expression

9. Which is the correct type of expression “a” where a is declared as int a[10]; in most expressions?
A) int
B) int[10]
C) int*
D) pointer to array of 10 ints

C) int*

10. Which of the following causes a memory leak?
A) free(p); p = NULL;
B) p = malloc(100); p = malloc(200);
C) p = malloc(50); free(p);
D) p = NULL;

B) p = malloc(100); p = malloc(200);

11. What is the result of: printf("%zu", sizeof("A"));
A) 0
B) 1
C) 2
D) Depends on compiler

C) 2

12. Which of the following is true about function-like macros?
A) Arguments are evaluated only once
B) They perform type checking
C) They may evaluate arguments multiple times
D) They cannot take parameters

C) They may evaluate arguments multiple times

13. Which standard library function is used to convert a string to long?
A) atoi()
B) atol()
C) strtol()
D) itoa()

C) strtol()

14. Which is true about “const int *p” and “int * const p”?
A) Both mean pointer is constant
B) First means pointed value is const, second means pointer is const
C) First means pointer is const, second means pointed value is const
D) Both mean pointed value is const

B) First means pointed value is const, second means pointer is const

15. What does the expression “p[i]” mean in C (for pointer/array p)?
A) *(p + i)
B) *(i + p)
C) Both *(p + i) and *(i + p)
D) None of the above

C) Both *(p + i) and *(i + p)

16. Which of the following is true about “static” at file scope?
A) Makes variable accessible from other files
B) Gives internal linkage (visible only within that translation unit)
C) Allocates variable on stack
D) Forces variable into CPU register

B) Gives internal linkage (visible only within that translation unit)

17. Which header defines size_t?
A) stdio.h
B) stddef.h
C) limits.h
D) float.h

B) stddef.h

18. Which of the following is true about “restrict” keyword (C99)?
A) It disables all optimizations
B) It promises pointers do not alias the same object in that scope
C) It forces pointer to be constant
D) It makes pointer volatile

B) It promises pointers do not alias the same object in that scope

19. Which function is used to set memory block to a byte value?
A) memcpy()
B) memmove()
C) memset()
D) memcmp()

C) memset()

20. What is the key difference between memcpy() and memmove()?
A) memcpy is slower always
B) memmove handles overlapping regions safely
C) memmove cannot copy bytes
D) memcpy works only for strings

B) memmove handles overlapping regions safely

21. Which of the following is true about endianness?
A) It affects floating point only
B) It is the byte order used to store multi-byte values
C) It changes the size of int
D) It is unrelated to memory representation

B) It is the byte order used to store multi-byte values

22. What does the expression (int*)0 indicate?
A) A valid pointer to int
B) A NULL pointer cast to int*
C) Pointer to address 1
D) Pointer to uninitialized memory

B) A NULL pointer cast to int*

23. Which of the following is a correct use of fprintf()?
A) fprintf("file.txt", "%d", x);
B) fprintf(fp, "%d", x);
C) fprintf("%d", x, fp);
D) fprintf(x, "%d", fp);

B) fprintf(fp, "%d", x);

24. Which header file is required for va_list and variadic functions?
A) stdarg.h
B) varargs.h
C) stdio.h
D) stdlib.h

A) stdarg.h

25. What is the output of: printf("%d", 1<<3);
A) 3
B) 6
C) 8
D) 9

C) 8