Practice Programming in C MCQs for NTS NAT-ICS (Computer Science Track) computer science — topic-wise sets with solved answers.
Q1. What is the output of `printf('%d', sizeof('a'));` in C?
Answer: 4
Explanation: In C, character literals are treated as integers, so 'a' is an int, typically 4 bytes on most systems.
Q2. What does `static int x;` imply?
Answer: x retains its value between function calls
Explanation: Static variables retain their values between function calls, initialized only once. NET computer science MCQs often test this core concept.
Q3. What is the result of `5 / 2` in C?
Answer: 2
Explanation: Integer division truncates the decimal part, resulting in 2. NET computer science MCQs often test this core concept.
Q4. What is the output of `int x = 10; printf('%d', x++);`?
Answer: 10
Explanation: Post-increment operator returns the current value before incrementing. NET computer science MCQs often test this core concept.
Q5. What is a dangling pointer?
Answer: Pointer to a freed memory location
Explanation: Dangling pointer points to memory that has been freed or reused. NET computer science MCQs often test this core concept.
Q6. What is the purpose of `typedef`?
Answer: To define a new data type
Explanation: Typedef is used to create an alias for an existing data type.
Q7. What is the output of `printf('%d', 3 && 0);`?
Answer: 0
Explanation: Logical AND operation results in 0 because one operand is 0. NET computer science MCQs often test this core concept.
Q8. What does `extern int x;` mean?
Answer: x is defined elsewhere
Explanation: Extern keyword declares a variable defined elsewhere, typically in another file. NET computer science MCQs often test this core concept.
Q9. What is the result of `sizeof(int) / sizeof(int*)` on a 64-bit system?
Answer: 1/2
Explanation: On a 64-bit system, sizeof(int) is typically 4 and sizeof(int*) is 8, so the result is 4/8 = 1/2.
Q10. What is a memory leak?
Answer: Memory not being freed after use
Explanation: Memory leak occurs when dynamically allocated memory is not released back to the system.
Q11. What is the output of `int arr[5] = 1, 2; printf('%d', arr[3]);`?
Answer: Garbage Value
Explanation: Uninitialized elements in an array contain garbage values. NET computer science MCQs often test this core concept.
Q12. What is the use of `register` keyword?
Answer: To suggest the compiler to store a variable in a register
Explanation: Register keyword is a hint to the compiler to store a variable in a CPU register for faster access.
Q13. What is the result of `!0 && 5`?
Answer: 1
Explanation: !0 is 1, and 1 && 5 is 1 because both are non-zero.
Q14. What is the output of `printf('%lu', sizeof('Hello'));`?
Answer: 6
Explanation: String literal 'Hello' includes a null terminator, making its size 6 bytes.
Q15. What is the purpose of `volatile` keyword?
Answer: To inform the compiler that a variable's value can change unexpectedly
Explanation: Volatile keyword tells the compiler to always read a variable's value from memory, not from a register.
Q16. What is the output of `int x = 5; x = x++ + ++x; printf('%d', x);`?
Answer: Undefined Behavior
Explanation: The expression involves multiple side effects on the same variable between sequence points, leading to undefined behavior.
Q17. What is the difference between `calloc()` and `malloc()`?
Answer: calloc() initializes memory to zero
Explanation: calloc() allocates memory and initializes it to zero, unlike malloc(). NET computer science MCQs often test this core concept.
Q18. What is the output of `char str[] = 'Hello'; printf('%s', str + 2);`?
Answer: llo
Explanation: Pointer arithmetic moves the starting point of the string to 'l', so it prints 'llo'.
Q19. What is the result of `sizeof(void*)` on a 64-bit system?
Answer: 8
Explanation: On a 64-bit system, the size of a pointer is typically 8 bytes.
Q20. What is the purpose of `#ifndef` directive?
Answer: To prevent multiple inclusions of a header file
Explanation: #ifndef directive checks if a symbol is not defined, used to prevent multiple inclusions of the same header file.
Loading...