Showing 11–20 of 100 questions
in Basics & Syntax
What is the correct way to declare a two-dimensional array of integers with 3 rows and 4 columns?
A
int arr[3][4];
B
int arr[4][3];
C
int **arr[3][4];
D
int arr(3)(4);
Correct Answer:
A. int arr[3][4];
EXPLANATION
2D array syntax is int arr[rows][columns]. So int arr[3][4] creates 3 rows and 4 columns.
Which of the following about register variables is TRUE?
A
They must be initialized
B
They are faster to access than normal variables
C
They cannot be pointers
D
They are stored in RAM
Correct Answer:
B. They are faster to access than normal variables
EXPLANATION
register keyword suggests the compiler to store the variable in CPU register for faster access. Modern compilers often ignore this hint. You cannot take address of register variables.
What does the 'volatile' keyword in C indicate?
A
Variable value can change unexpectedly
B
Variable is constant
C
Variable is local
D
Variable must be initialized
Correct Answer:
A. Variable value can change unexpectedly
EXPLANATION
volatile tells the compiler that a variable's value can change unexpectedly (e.g., in hardware registers or interrupt handlers), so it should not optimize away repeated reads.
What is the output of: printf("%d %d", 10 % 3, 10 / 3);
A
3 3
B
1 3
C
3 1
D
10 10
EXPLANATION
10 % 3 = 1 (remainder), 10 / 3 = 3 (integer division). Output is '1 3'.
Which of the following is correct about static variables in C?
A
They are destroyed after function returns
B
They retain their value between function calls
C
They cannot be used in functions
D
They are global by default
Correct Answer:
B. They retain their value between function calls
EXPLANATION
Static variables retain their value between function calls and are initialized only once. They persist for the lifetime of the program.
What will be the output of: int a = 5; int b = a < 10 ? 20 : 30; printf("%d", b);
EXPLANATION
This is the ternary operator. Since 5 < 10 is true, b = 20. If false, b would be 30.
What is the purpose of the getchar() function in C?
A
Get a string from input
B
Get a single character from input
C
Get a number from input
D
Get a pointer from input
Correct Answer:
B. Get a single character from input
EXPLANATION
getchar() reads a single character from standard input and returns it. For strings, fgets() or scanf() is used.
Which of the following correctly declares a pointer to an integer?
A
int *ptr;
B
int& ptr;
C
ptr *int;
D
int ptr*;
Correct Answer:
A. int *ptr;
EXPLANATION
The correct syntax for a pointer to int is 'int *ptr;' or 'int* ptr;'. & is a C++ reference, not used in C pointers.
Which escape sequence represents a horizontal tab in C?
EXPLANATION
\t is the escape sequence for horizontal tab. \n is newline, \h and \s are not valid escape sequences.
How many bytes does a 'long long' integer occupy in C (standard 32-bit system)?
A
2 bytes
B
4 bytes
C
8 bytes
D
16 bytes
Correct Answer:
C. 8 bytes
EXPLANATION
'long long' is guaranteed to be at least 64 bits (8 bytes) as per C99 standard.