Showing 1–10 of 35 questions
in Basics & Syntax
Which of the following is NOT a valid variable name in C?
A
_var123
B
123var
C
var_123
D
__var
Correct Answer:
B. 123var
EXPLANATION
Variable names cannot start with a digit. They must start with a letter or underscore. Option B violates this rule.
What is the output of the following C program?
#include
int main() {
char str[] = "GATE";
printf("%d", sizeof(str));
return 0;
}
A
4
B
5
C
6
D
Compilation Error
EXPLANATION
sizeof(str) includes the null terminator. The string "GATE" has 4 characters plus 1 null terminator = 5 bytes.
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 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.
What will be the output of: int x = 10; printf("%d", x++);
A
10
B
11
C
Undefined
D
Error
EXPLANATION
x++ is post-increment. The current value (10) is printed first, then x is incremented to 11. So output is 10.
Which of the following is NOT a valid C data type?
A
int
B
string
C
double
D
char
Correct Answer:
B. string
EXPLANATION
C does not have a built-in 'string' data type. Strings are arrays of characters. int, double, and char are valid primitive data types.
What will be the output of: printf("%d", 5 / 2);
EXPLANATION
Integer division truncates the result. 5/2 = 2 (not 2.5) because both operands are integers.
In C, which of the following correctly declares a pointer to an integer?
A
int *ptr;
B
*int ptr;
C
int& ptr;
D
pointer int *;
Correct Answer:
A. int *ptr;
EXPLANATION
The correct syntax is 'int *ptr;' where * indicates ptr is a pointer to int.