Learn C MCQs
Prepare C MCQs (Multiple choice Questions) for exam and job interviews.
Which of the following is a valid C variable name?
1) 1variable
2) _variable
3) variable#1
4) None of the above
Answer : _variable
Which statement is true about the `static` keyword?
1) It defines a function that cannot be called outside its file.
2) It makes a variable retain its value between function calls.
3) It declares a variable with a fixed size.
4) None of the above
Answer : It makes a variable retain its value between function calls.
How do you define a constant pointer in C?
1) const int *ptr;
2) int *const ptr;
3) const int const *ptr;
4) None of the above
Answer : int *const ptr;
What is the output of printf("%d", 1<<3);?
1) 8
2) 4
3) 1
4) Error
Answer : 8
What will be the output of printf("%d", 10 & 5);?
1) 0
2) 10
3) 5
4) 15
Answer : Option 1
How do you correctly initialize a 2D array in C?
1) int arr[2][3] = {{1,2,3},{4,5,6}};
2) int arr[2,3] = {{1,2,3},{4,5,6}};
3) int arr(2,3) = {{1,2,3},{4,5,6}};
4) None of the above
Answer : int arr[2][3] = {{1,2,3},{4,5,6}};
Which of the following is not a storage class in C?
1) auto
2) static
3) register
4) dynamic
Answer : dynamic
Which function is used to allocate memory for an array dynamically in C?
1) calloc()
2) malloc()
3) new()
4) alloc()
Answer : calloc()
What is the default value of uninitialized local variables in C?
1) Zero
2) Random value
3) NULL
4) Depends on the data type
Answer : Random value
How do you define a macro function in C?
1) #define FUNC(x) (x+1)
2) #define FUNC(x) x+1
3) #macro FUNC(x) x+1
4) None of the above
Answer : #define FUNC(x) x+1