C Basics Question Bank for C-CAT
Topic-wise C Basics MCQs for CDAC C-CAT preparation with answers and explanations.
Show Answer & Explanation
Correct Answer: C - Dennis Ritchie
C was developed by Dennis Ritchie at Bell Labs in the early 1970s.
Show Answer & Explanation
Correct Answer: D - UNIX
C was developed to write the UNIX operating system.
Show Answer & Explanation
Correct Answer: D - C89
C89 (ANSI C) is one of the official C language standards.
Show Answer & Explanation
Correct Answer: D - boolean
C does not have a built-in boolean keyword.
Show Answer & Explanation
Correct Answer: B - char
char data type is used to store a single character.
Show Answer & Explanation
Correct Answer: B - 4 bytes
On most modern systems, int occupies 4 bytes.
Show Answer & Explanation
Correct Answer: C - long
The long modifier increases the size/range of integer.
Show Answer & Explanation
Correct Answer: B - const
const prevents modification of a variable.
Show Answer & Explanation
Correct Answer: D - int
By default, main() returns an integer value.
Show Answer & Explanation
Correct Answer: D - stdio.h
printf() is declared in stdio.h.
Show Answer & Explanation
Correct Answer: A - ;
Every C statement ends with a semicolon.
Show Answer & Explanation
Correct Answer: B - _num
Variable names can start with underscore.
Show Answer & Explanation
Correct Answer: B - const
const keyword declares read-only variables.
Show Answer & Explanation
Correct Answer: A - scanf()
scanf() is used for formatted input.
Show Answer & Explanation
Correct Answer: C - long double
long double provides highest floating-point precision.
What is the output of the following code?
int x = 5;
printf("%d", x);Show Answer & Explanation
Correct Answer: B - 5
x is initialized to 5 and printed.
Show Answer & Explanation
Correct Answer: C - array
Array is a derived data type.
Show Answer & Explanation
Correct Answer: C - volatile
volatile prevents compiler optimizations.
Show Answer & Explanation
Correct Answer: A - &
& operator returns the address of a variable.
Show Answer & Explanation
Correct Answer: C - Platform dependent
C programs depend on underlying hardware and OS.
Show Answer & Explanation
Correct Answer: C - printf("%d", x);
printf with %d format specifier is used to print integers.
Show Answer & Explanation
Correct Answer: D - 1 byte
char always occupies 1 byte in C.
Show Answer & Explanation
Correct Answer: A - unsigned int x;
Correct syntax is modifier followed by data type.
Show Answer & Explanation
Correct Answer: B - register
register suggests the compiler to store variable in CPU register.
What will be the output?
int a = 10;
printf("%d", sizeof(a));Show Answer & Explanation
Correct Answer: D - 4
sizeof(int) is typically 4 bytes on modern systems.
Show Answer & Explanation
Correct Answer: D - All of the above
Integer, floating, and character constants are valid.
Show Answer & Explanation
Correct Answer: B - \n
\n moves the cursor to next line.
What is the output?
printf("Hello
World");Show Answer & Explanation
Correct Answer: A - Hello then World in next line
\n causes a line break.
Show Answer & Explanation
Correct Answer: B - No header required
sizeof is a compile-time operator.
Show Answer & Explanation
Correct Answer: C - Special symbols
Special symbols like @, # are not allowed.
Show Answer & Explanation
Correct Answer: A - extern
extern is used to declare global variables across files.
What will be the output?
int x;
printf("%d", x);Show Answer & Explanation
Correct Answer: D - Garbage value
Uninitialized local variables contain garbage values.
Show Answer & Explanation
Correct Answer: B - float
float stores decimal (fractional) values.
Show Answer & Explanation
Correct Answer: A - Prevents optimization
volatile tells compiler value may change unexpectedly.
Show Answer & Explanation
Correct Answer: C - sizeof
sizeof operator returns memory size in bytes.
Show Answer & Explanation
Correct Answer: A - %lf
double uses %lf in scanf and printf.
Show Answer & Explanation
Correct Answer: B - Both A and B
C supports both single-line and multi-line comments.
What is the output?
printf("%c", 65);Show Answer & Explanation
Correct Answer: D - A
ASCII value 65 represents character 'A'.
Show Answer & Explanation
Correct Answer: A - void
void indicates no return value.
Show Answer & Explanation
Correct Answer: B - return 0;
return 0 indicates successful execution.
Show Answer & Explanation
Correct Answer: C - string
'string' is not a built-in data type in C. Strings are represented as arrays of characters (char[]). The valid primitive data types include int, float, double, char, and void.
What will be the output of the following code?
int x = 5;
printf("%d", sizeof(x++));
printf("%d", x);Show Answer & Explanation
Correct Answer: A - 45
The sizeof operator is evaluated at compile time, so the expression x++ inside sizeof is never executed at runtime. Therefore x remains 5. sizeof(int) is typically 4 bytes on most systems. The first printf prints 4, the second prints 5 (since x was never incremented). Output: 45.
Show Answer & Explanation
Correct Answer: D - const
The 'const' keyword makes a variable read-only after initialization, preventing any modification to its value. 'static' controls storage duration, 'volatile' prevents compiler optimization, and 'register' suggests storing in a CPU register.
Show Answer & Explanation
Correct Answer: A - 0 to 255
An unsigned char uses all 8 bits for magnitude (no sign bit), giving a range of 0 to 28 - 1 = 255. A signed char uses one bit for sign, giving -128 to 127.
What will be the output?
int a = 10, b = 20;
printf("%d", a, b);Show Answer & Explanation
Correct Answer: B - 10
There is only one %d format specifier but two arguments are passed. The printf function will print the first matching argument (10) and ignore the extra argument b. This is valid C and does not cause a compilation error, though it may generate a warning.
Show Answer & Explanation
Correct Answer: C - float 2ndValue = 3.14;
Variable names in C cannot begin with a digit. '2ndValue' starts with the digit 2, making it an invalid identifier. Valid identifiers must start with a letter (a-z, A-Z) or underscore (_), followed by letters, digits, or underscores.
Show Answer & Explanation
Correct Answer: C - The variable's value may change unexpectedly outside the program's control
'volatile' tells the compiler that a variable's value can be changed by external factors (hardware registers, interrupt service routines, other threads), so the compiler should not optimize reads/writes to that variable and must always fetch it from memory.
What is the output of the following code?
printf("%d", (int)3.9 + (int)3.1);Show Answer & Explanation
Correct Answer: A - 6
When a float/double is cast to int in C, the fractional part is truncated (not rounded). So (int)3.9 = 3 and (int)3.1 = 3. Therefore 3 + 3 = 6. The %d format prints it as integer 6.
Show Answer & Explanation
Correct Answer: D - static
A 'static' local variable is initialized only once and retains its value between function calls throughout the program's lifetime. 'auto' and 'register' variables are destroyed when the function returns. 'extern' is used to declare variables defined in other files.
What will the following code print?
char str[] = "CDAC";
printf("%lu", sizeof(str));Show Answer & Explanation
Correct Answer: A - 5
The string "CDAC" has 4 visible characters, but C automatically appends a null terminator '\0' at the end. So the character array str contains {'C','D','A','C','\0'}, which is 5 bytes. sizeof(str) returns 5.