-
Which of the following is true regarding the
sizeof
operator in C?a) It is a preprocessor directive
b) It returns the size of a variable in bits
c) It can be used with any data type including user-defined types
d) It can be used to determine the size of dynamic memory allocationsAnswer: c) It can be used with any data type including user-defined types
-
What will be the output of the following code?
#include <stdio.h> int main() { int arr[5] = {1, 2, 3, 4, 5}; printf("%d\n", arr[5]); return 0; }
a) 1
b) 5
c) Compiler error
d) Undefined behaviorAnswer: d) Undefined behavior
-
In C, what is the purpose of the
continue
statement?a) To terminate the program
b) To exit the loop and transfer control to the loop's condition check
c) To skip the remaining code in the loop and continue with the next iteration
d) To jump to a labeled statementAnswer: c) To skip the remaining code in the loop and continue with the next iteration
-
Which function is used to compare two strings in C?
a) strcomp()
b) strcmp()
c) strcompare()
d) compare()Answer: b) strcmp()
-
What will be the output of the following code?
#include <stdio.h> int main() { int x = 5, y = 10; if (x = y) printf("x is equal to y\n"); else printf("x is not equal to y\n"); return 0; }
a) x is equal to y
b) x is not equal to y
c) Compiler error
d) No outputAnswer: a) x is equal to y
-
Which header file is required to use the
pow()
function in C?a) <stdio.h>
b) <stdlib.h>
c) <math.h>
d) <ctype.h>Answer: c) <math.h>
-
What will be the output of the following code?
#include <stdio.h> int main() { int x = 5, y = 10; x ^= y; y ^= x; x ^= y; printf("x = %d, y = %d\n", x, y); return 0; }
a) x = 5, y = 10
b) x = 10, y = 5
c) x = 0, y = 0
d) Compiler errorAnswer: b) x = 10, y = 5
-
What does the
isdigit()
function in C do?a) Checks if a character is a digit
b) Converts a character to its lowercase equivalent
c) Converts a character to its uppercase equivalent
d) Checks if a character is a whitespace characterAnswer: a) Checks if a character is a digit
-
What will be the output of the following code?
#include <stdio.h> int main() { int x = 5; printf("%d\n", x++); printf("%d\n", ++x); return 0; }
a) 5, 7
b) 5, 6
c) 6, 6
d) 6, 7Answer: b) 5, 6
-
In C, what is the purpose of the
goto
statement?a) To exit a loop
b) To transfer control to a labeled statement
c) To skip the remaining code in a loop and continue with the next iteration
d) To terminate the programAnswer: b) To transfer control to a labeled statement
Comments