There are 20 multiple-choice questions (MCQs) related to the C programming language along with their answers:
1. What does the acronym "C" stand for in C programming?
a) Computer
b) Common
c) Code
d) Central
Answer: b) Common
2. Which of the following is a valid identifier in C?
a) 2variable
b) _variable
c) switch
d) float
Answer: b) _variable
3. What is the size of the int
data type in C on a 32-bit system?
a) 2 bytes
b) 4 bytes
c) 8 bytes
d) Depends on the compiler
Answer: b) 4 bytes
4. In C, what is the purpose of the typedef
keyword?
a) To define a new type
b) To declare a variable
c) To include a header file
d) To create a pointer
Answer: a) To define a new type
5. What is the output of the following code?
#include <stdio.h> int main() { printf("%d", sizeof(5.5)); return 0; }
a) 2
b) 4
c) 8
d) Compiler Error
Answer: b) 4
6. Which header file is used for dynamic memory allocation in C?
a) stdlib.h
b) math.h
c) string.h
d) stdio.h
Answer: a) stdlib.h
7. What is the purpose of the break
statement in C?
a) Exits the program
b) Exits the loop or switch statement
c) Skips the rest of the code inside a loop
d) Jumps to a specific label
Answer: b) Exits the loop or switch statement
8. How do you declare a constant in C using #define
?
a) constant = 5;
b) define constant 5
c) #define constant 5
d) const constant = 5;
Answer: c) #define constant 5
9. What is the purpose of the getchar()
function in C?
a) Reads a character from the keyboard
b) Prints a character to the console
c) Clears the screen
d) Closes a file
Answer: a) Reads a character from the keyboard
10. Which symbol is used for the modulus operation in C?
a) %
b) /
c) *
d) &
Answer: a) %
11. What is the output of the following code?
#include <stdio.h>
int main() { int i = 10; printf("%d", i++); return 0; } a) 10 b) 11 c) 12 d) Compiler Error Answer: a) 10
12. How do you initialize an array in C?
a) int arr[];
b) int arr[5] = {1, 2, 3, 4, 5};
c) arr = {1, 2, 3, 4, 5};
d) int arr[5];
Answer: b) int arr[5] = {1, 2, 3, 4, 5};
13. What is the purpose of the static
keyword in C?
a) Declares a global variable
b) Allocates dynamic memory
c) Specifies a file scope
d) Initializes a variable
Answer: c) Specifies a file scope
14. What is the role of the void
keyword in a function declaration?
a) Indicates that the function returns no value
b) Specifies the return type of the function
c) Declares a variable
d) Marks the function as deprecated
Answer: a) Indicates that the function returns no value
15. How do you close a file in C?
a) fclose(file);
b) close(file);
c) file.close();
d) closeFile(file);
Answer: a) fclose(file);
16. What is the purpose of the sizeof
operator in C?
a) Returns the size of a variable
b) Returns the size of a function
c) Returns the size of a datatype
d) Returns the size of a pointer
Answer: a) Returns the size of a variable
17. Which of the following is the correct syntax for a for
loop in C?
a) for (i = 0; i < 10; i++)
b) for i = 0; i < 10; i++
c) for (int i = 0; i < 10)
d) for (i < 10; i++)
Answer: a) for (i = 0; i < 10; i++)
18. What is the role of the scanf
function in C?
a) Prints formatted output to the console
b) Reads formatted input from the console
c) Allocates dynamic memory
d) Opens a file for reading
Answer: b) Reads formatted input from the console
19. How do you access the value stored at a pointer in C?
a) *ptr
b) &ptr
c) ptr.value
d) ptr->value
Answer: a) *ptr
20. What is the purpose of the malloc
function in C?
a) Allocates memory for a variable
b) Frees allocated memory
c) Initializes memory to zero
d) Declares a variable
Answer: a) Allocates memory for a variable
Comments