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 6

1. Which of the following correctly represents pointer arithmetic?
A) ptr + sizeof(int)
B) ptr + 1 moves by one byte
C) ptr + 1 moves by size of pointed data type
D) ptr arithmetic is not allowed

C) ptr + 1 moves by size of pointed data type

2. What does the expression *(&x) evaluate to?
A) Address of x
B) Value of x
C) Pointer to x
D) Compilation error

B) Value of x

3. Which of the following is true about arrays passed to functions?
A) Entire array is copied
B) Array is passed by value
C) Base address of array is passed
D) Only first element is passed

C) Base address of array is passed

4. Which of the following causes undefined behavior in C?
A) Using uninitialized local variable
B) Accessing array within bounds
C) Initializing pointer to NULL
D) Using sizeof operator

A) Using uninitialized local variable

5. What is the output of: printf("%d", sizeof(5));
A) 2
B) 4
C) 8
D) Depends on compiler

B) 4

6. Which keyword prevents compiler optimization on a variable?
A) const
B) static
C) volatile
D) register

C) volatile

7. Which of the following is true about malloc()?
A) Initializes memory to zero
B) Returns pointer to allocated memory
C) Allocates memory on stack
D) Automatically frees memory

B) Returns pointer to allocated memory

8. What happens if free() is called twice on the same pointer?
A) Safe operation
B) Memory leak
C) Undefined behavior
D) Compilation error

C) Undefined behavior

9. Which macro operator concatenates tokens?
A) #
B) ##
C) @
D) &

B) ##

10. What does the # operator do in macros?
A) Concatenates tokens
B) Converts argument to string literal
C) Comments the macro
D) Terminates macro

B) Converts argument to string literal

11. Which of the following is a dangling pointer?
A) Pointer initialized to NULL
B) Pointer pointing to freed memory
C) Pointer pointing to global variable
D) Pointer pointing to static variable

B) Pointer pointing to freed memory

12. Which segment stores global and static variables?
A) Stack
B) Heap
C) Data segment
D) Code segment

C) Data segment

13. Which of the following statements about const int *p is true?
A) p is constant
B) *p is constant
C) Both p and *p are constant
D) Neither is constant

B) *p is constant

14. What is the output of: printf("%d", !!5);
A) 0
B) 1
C) 5
D) Undefined

B) 1

15. Which of the following is NOT a valid storage class?
A) auto
B) register
C) extern
D) dynamic

D) dynamic

16. Which function pointer declaration is correct?
A) int *fp();
B) int (*fp)();
C) int fp*();
D) int (fp*)();

B) int (*fp)();

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

A) 0

18. Which of the following guarantees memory alignment?
A) malloc()
B) calloc()
C) realloc()
D) All of the above

D) All of the above

19. Which operator is evaluated first?
A) &&
B) ||
C) !
D) =

C) !

20. Which of the following is implementation-defined behavior?
A) Integer overflow
B) Order of evaluation of function arguments
C) Size of int
D) Dereferencing NULL pointer

C) Size of int

21. What is the return type of main() in standard C?
A) void
B) int
C) char
D) float

B) int

22. Which header is required for assert()?
A) stdio.h
B) stdlib.h
C) assert.h
D) error.h

C) assert.h

23. Which function terminates the program immediately?
A) break
B) return
C) exit()
D) abort()

D) abort()

24. What is the output of: printf("%d", sizeof(char*));
A) 1
B) 2
C) 4
D) Depends on architecture

D) Depends on architecture

25. Which of the following best describes C language?
A) Object-oriented
B) Functional
C) Procedural
D) Declarative

C) Procedural