Showing 41–50 of 100 questions
in Basics & Syntax
Which of the following is NOT a valid C identifier?
A
_variable123
B
123variable
C
variable_123
D
__var__
Correct Answer:
B. 123variable
EXPLANATION
Identifiers cannot start with a digit. They must start with a letter (a-z, A-Z) or underscore.
What is the size of the 'int' data type in a 32-bit system according to C standard?
A
2 bytes
B
4 bytes
C
8 bytes
D
Platform dependent
Correct Answer:
D. Platform dependent
EXPLANATION
The size of 'int' is implementation-defined and depends on the compiler and platform, though it is typically 4 bytes on 32-bit systems.
Which of the following best describes the 'register' storage class in modern C compilers?
A
Guarantees storage in CPU register
B
A hint to the compiler to optimize variable storage; compiler may ignore it
C
Forces the variable to be global
D
Automatically allocates memory on the stack
Correct Answer:
B. A hint to the compiler to optimize variable storage; compiler may ignore it
EXPLANATION
The 'register' keyword is a hint for compiler optimization. Modern compilers often ignore it as they have sophisticated optimization strategies.
What is the output of: printf("%d", (int)3.7);?
EXPLANATION
Type casting (int)3.7 truncates the decimal part, converting 3.7 to 3. The fractional part is discarded.
Consider a function declared as 'static int func()'. What is the scope of this function?
A
Global scope across all files
B
Limited to the current file only
C
Only within the function where it's declared
D
Limited to the current block
Correct Answer:
B. Limited to the current file only
EXPLANATION
When 'static' is applied to a function at file scope, it restricts the function's visibility to that translation unit (file) only.
What will be the result of the bitwise operation: 5 & 3 in C?
EXPLANATION
5 (binary 101) & 3 (binary 011) = 001 (binary) = 1. Bitwise AND operates on each bit position.
In C, what is the correct way to pass a variable by reference using pointers?
A
void func(int var) { var = 10; }
B
void func(int &var) { var = 10; }
C
void func(int *var) { *var = 10; }
D
void func(int *var) { var = 10; }
Correct Answer:
C. void func(int *var) { *var = 10; }
EXPLANATION
C uses pointers for pass-by-reference. The dereference operator '*var' accesses the actual variable. C++ supports references (&var), but C does not.
What is the difference between 'break' and 'continue' statements in C?
A
'break' stops execution while 'continue' skips iteration
B
Both have the same function
C
'continue' stops execution while 'break' skips iteration
D
Neither has practical use in loops
Correct Answer:
A. 'break' stops execution while 'continue' skips iteration
EXPLANATION
'break' terminates the loop entirely, while 'continue' skips the current iteration and moves to the next one.
Which of the following is a correct way to read a string from user input avoiding buffer overflow?
A
scanf("%s", str);
B
scanf("%10s", str);
C
gets(str);
D
scanf("%[^
]s", str);
Correct Answer:
B. scanf("%10s", str);
EXPLANATION
Using scanf("%10s", str) limits input to 10 characters, preventing buffer overflow. The gets() function is deprecated and unsafe.
What does the 'const' keyword do when applied to a pointer?
A
Makes the pointer value constant only
B
Makes the pointed data constant only
C
Can make either or both constant depending on placement
D
Has no effect in C
Correct Answer:
C. Can make either or both constant depending on placement
EXPLANATION
'const int *ptr' makes the data constant, 'int * const ptr' makes the pointer constant, and 'const int * const ptr' makes both constant.