C MCQs (91-120)

91. What is the default value of a local variable in C?
a) 0
b) NULL
c) Undefined
d) Random value

Answer: c) Undefined


92. Which of the following is the correct syntax to declare a constant in C?
a) const int MAX = 100;
b) #define MAX 100
c) #const int MAX = 100;
d) Both a and b

Answer: d) Both a and b


93. What does the following code do?

int a = 5;

printf("%d", a++);

a) Prints 5
b) Prints 6
c) Causes a compilation error
d) Prints 0

Answer: a) Prints 5


94. Which of the following is used to terminate a program in C?
a) exit()
b) return()
c) quit()
d) stop()

Answer: a) exit()


95. In C, which of the following functions is used to obtain the length of a string?
a) length()
b) strlength()
c) strlen()
d) stringlen()

Answer: c) strlen()


96. What is the purpose of the void keyword in C?
a) It specifies that a function returns no value.
b) It specifies that a function can accept any type of argument.
c) It defines a pointer type.
d) It denotes an empty structure.

Answer: a) It specifies that a function returns no value.


97. What will the following code output?

#include <stdio.h>  
int main() {  
    int a = 3;  
    int b = 2;  
    printf("%d", a < b ? a : b);  
    return 0;  
}  

a) 3
b) 2
c) 5
d) Error

Answer: b) 2


98. What is the result of the following expression in C?

5 == 5

a) true
b) false
c) 5
d) 0

Answer: a) true


99. Which of the following functions is used to allocate memory dynamically in C?
a) malloc()
b) calloc()
c) realloc()
d) All of the above

Answer: d) All of the above


100. What will the following C program print?

#include <stdio.h>  
int main() {  
    int x = 4, y = 5;  
    printf("%d", x < y);  
    return 0;  
}  

a) 1
b) 0
c) 4
d) Error

Answer: a) 1


101. In C, which of the following is a valid way to access an array element?
a) arr[3]
b) arr(3)
c) arr{3}
d) arr{3}()

Answer: a) arr[3]


102. Which of the following is the correct syntax to declare a pointer to a double in C?
a) double* ptr;
b) double ptr*;
c) double ptr;
d) ptr
double;

Answer: a) double* ptr;


103. Which of the following statements about malloc() is true?
a) It initializes the memory to zero.
b) It returns a pointer to the allocated memory.
c) It allocates memory on the stack.
d) It is used to deallocate memory.

Answer: b) It returns a pointer to the allocated memory.


104. What is the output of the following code?

#include <stdio.h>  
int main() {  
    int a = 5, b = 2;  
    printf("%d", a / b);  
    return 0;  
}  

a) 2
b) 2.5
c) 5
d) Error

Answer: a) 2


105. Which of the following C operators is used for logical NOT?
a) !
b) ~
c) &&
d) ||

Answer: a) !


106. In C, which of the following is a valid function signature?
a) int function(int a, float b);
b) function int(int a, float b);
c) function(int a, float b) int;
d) int function(int a, b float);

Answer: a) int function(int a, float b);


107. Which of the following functions is used to convert a string to an integer in C?
a) atoi()
b) itoa()
c) strtoi()
d) toint()

Answer: a) atoi()


108. Which of the following is a valid pointer declaration in C?
a) int ptr;
b) ptr int
;
c) *ptr int;
d) ptr *int;

Answer: a) int *ptr;


109. What is the output of the following code?

#include <stdio.h>  
int main() {  
    int x = 5;  
    printf("%d", x != 5);  
    return 0;  
}  

a) 1
b) 0
c) Error
d) Undefined

Answer: b) 0


110. Which of the following operators is used for pointer arithmetic in C?
a) +
b) –
c) *
d) All of the above

Answer: d) All of the above


111. Which of the following is the correct syntax for a do-while loop in C?
a) do { } while (condition);
b) do while { } (condition);
c) do { condition } while;
d) while do { } (condition);

Answer: a) do { } while (condition);


112. What is the correct way to define a function in C?
a) function_name() {}
b) void function_name() {}
c) void function_name {};
d) function void_name() {};

Answer: b) void function_name() {}


113. Which of the following is used to indicate the end of an array in C?
a) NULL
b) -1
c) 0
d) \0

Answer: d) \0


114. Which of the following functions is used to concatenate two strings in C?
a) strjoin()
b) strconcat()
c) strcat()
d) append()

Answer: c) strcat()


115. What does the break statement do in C?
a) It ends the current loop and jumps to the next iteration.
b) It breaks the current loop and continues after the loop.
c) It ends the current loop and exits the program.
d) It skips the current loop iteration.

Answer: b) It breaks the current loop and continues after the loop.


116. Which of the following is NOT a valid C keyword?
a) auto
b) int
c) new
d) static

Answer: c) new


117. Which of the following is a valid way to define a string in C?
a) string str = “Hello”;
b) char str[] = “Hello”;
c) char str = “Hello”;
d) string str = “Hello”;

Answer: b) char str[] = “Hello”;


118. Which of the following is true about free() in C?
a) It initializes memory allocated dynamically.
b) It releases dynamically allocated memory.
c) It allocates memory dynamically.
d) It clears the contents of a pointer.

Answer: b) It releases dynamically allocated memory.


119. Which of the following is used to exit a function in C?
a) stop()
b) return;
c) exit();
d) break;

Answer: b) return;


120. Which of the following is the correct way to declare a long integer in C?
a) long int var;
b) int long var;
c) long var;
d) long var int;

Answer: a) long int var;

Leave a Reply