Programming in C MCQs set 3 for Bahria University Entry Test computer science — 20 solved questions.
Q1. The `const` keyword in C is used to
Answer: declare a constant variable
Explanation: const keyword is used to declare variables that cannot be modified. NET computer science MCQs often test this core concept.
Q2. What is the output of the expression `5 & 3`?
Answer: 1
Explanation: Bitwise AND operation: 5 (101) & 3 (011) = 1 (001). NET computer science MCQs often test this core concept.
Q3. The `typedef` keyword is used to
Answer: create a new data type
Explanation: typedef is used to create an alias for an existing data type.
Q4. What is the output of `printf('%d', 10 % -3)`?
Answer: 1
Explanation: Modulus operation: 10 % -3 = 1. 1 is correct because it matches what the question requires. NET computer science MCQs often test this core concept.
Q5. The `extern` keyword is used to
Answer: declare a global variable
Explanation: extern is used to declare global variables that are defined elsewhere. NET computer science MCQs often test this core concept.
Q6. What is the output of `int arr[3] = 1, 2, 3; printf('%d', arr[3])`?
Answer: Garbage value
Explanation: Accessing an array out of bounds results in undefined behavior, typically a garbage value.
Q7. The `register` keyword is used to
Answer: declare a variable that is stored in a register
Explanation: register keyword is a hint to the compiler to store the variable in a register.
Q8. What is the output of `printf('%d', sizeof(void *))`?
Answer: 4
Explanation: Size of a void pointer is typically equal to the word size of the system, often 4 bytes on 32-bit systems.
Q9. The function `free()` is used to
Answer: free allocated memory
Explanation: free() is used to deallocate memory that was previously allocated using malloc() or similar functions.
Q10. What is the output of `int x = 5; printf('%d', ~x)`?
Answer: -6
Explanation: Bitwise NOT operation: ~5 = -6 (two's complement representation). NET computer science MCQs often test this core concept.
Q11. The `volatile` keyword is used to
Answer: declare a variable that can be modified by external factors
Explanation: volatile keyword informs the compiler that a variable's value can change in ways not explicitly specified by the program.
Q12. Which operator has the highest precedence in C?
Answer: ()
Explanation: Parentheses () have the highest precedence, used for grouping and function calls.
Q13. In C, what is `NULL` typically defined as?
Answer: (void *)0
Explanation: NULL is defined as (void *)0, representing a null pointer constant. NET computer science MCQs often test this core concept.
Q14. What is the purpose of `extern` keyword in C?
Answer: To declare a global variable
Explanation: extern declares a global variable or function that is defined elsewhere. NET computer science MCQs often test this core concept.
Q15. What does `typedef` do?
Answer: Creates a new data type
Explanation: typedef creates an alias for an existing data type, enhancing code readability.
Q16. How does `switch` statement work?
Answer: Jumps to the matching case
Explanation: switch jumps to the case matching the expression's value, then executes until break.
Q17. What is the output of `int arr[5] = 1, 2; printf('%d', arr[4]);`?
Answer: Garbage value
Explanation: Uninitialized elements in an array contain garbage values. NET computer science MCQs often test this core concept.
Q18. What is the effect of `register` keyword?
Answer: Stores variable in register
Explanation: register hints the compiler to store the variable in a CPU register for faster access.
Q19. What is the behavior of `int a = 10; a = a << 1;`?
Answer: Doubles the value of a
Explanation: Left shift (<<) effectively doubles the value by shifting bits one place to the left.
Q20. What does `const` mean for a pointer?
Answer: It depends on the placement of const
Explanation: const can be applied to either the pointer, the data it points to, or both, depending on its placement.