Which of the following is used to declare a constant in C?
Aconstant int x = 5;
Bconst int x = 5;
Cfinal int x = 5;
Dimmutable int x = 5;
Correct Answer:
B. const int x = 5;
Explanation:
In C, the 'const' keyword is used to declare constants. Once a const variable is initialized, its value cannot be changed. Options A, C, and D are not valid C syntax.
What is the purpose of the return statement in a C function?
ATo exit the program
BTo return a value to the caller and exit the function
CTo declare variables
DTo create a loop
Correct Answer:
B. To return a value to the caller and exit the function
Explanation:
The return statement is used to exit a function and return a value (if any) to the calling function. If the function has return type void, no value is returned.
Which loop in C does NOT check the condition before executing the loop body?
Afor loop
Bwhile loop
Cdo-while loop
Dforeach loop
Correct Answer:
C. do-while loop
Explanation:
The do-while loop executes the loop body at least once before checking the condition. Other loops check the condition before execution. Syntax: do { } while(condition);
Which of the following is the correct way to define a function that takes no parameters and returns no value?
Avoid function() { }
Bnull function() { }
Cempty function() { }
Dvoid function(void) { }
Correct Answer:
A. void function() { }
Explanation:
In C, void function() { } is correct. In some contexts, void function(void) { } is more explicit. Options B and C use invalid keywords for this purpose.