-
What does the
sizeof
operator return in C?a) Size of a variable in bytes
b) Size of a datatype in bytes
c) Size of a pointer in bytes
d) Size of the code segment in bytesAnswer: b) Size of a datatype in bytes
-
Which keyword is used to define a constant in C?
a) const
b) constant
c) define
d) varAnswer: a) const
-
What will be the output of the following code?
#include <stdio.h> int main() { int x = 5; int y = 10; int z = x + y; printf("%d\n", z); return 0; }
a) 15
b) 5
c) 10
d) Compiler errorAnswer: a) 15
-
Which one of the following is the correct way to declare a pointer in C?
a) int ptr;
b) int ptr;
c) int ptr;
d) pointer int;*Answer: a) int ptr;
-
What is the value of
x
after the following code is executed?int x = 10; int *ptr = &x; *ptr = 20;
a) 10
b) 20
c) Undefined
d) Compiler errorAnswer: b) 20
-
What does the
strcmp()
function do in C?a) Copies one string to another
b) Compares two strings
c) Concatenates two strings
d) Searches for a substring in a stringAnswer: b) Compares two strings
-
What does the
malloc()
function do in C?a) Allocates memory on the stack
b) Allocates memory on the heap
c) Frees memory
d) Resizes memoryAnswer: b) Allocates memory on the heap
-
Which header file is required for using dynamic memory allocation functions in C?
a) <stdio.h>
b) <stdlib.h>
c) <math.h>
d) <ctype.h>Answer: b) <stdlib.h>
-
What is the purpose of the
break
statement in C?a) To exit a loop
b) To skip the current iteration of a loop
c) To branch unconditionally
d) To terminate the programAnswer: a) To exit a loop
-
Which one of the following is a valid way to declare a multi-dimensional array in C?
a) int arr[5][];
b) int arr[][];
c) int arr[][5];
d) int arr[][];Answer: c) int arr[][5];
Comments