- History of C and the four key figures behind it
- Valid vs invalid variable names and keywords
- const, volatile, and storage qualifiers
- Operator precedence, associativity, and type casting
- Conditional, iterative, and functional constructs
- Preprocessor directives: #include, #define, #ifdef
- Arrays, pointers, structs, unions, and file streams
- Reading and tracing short C program output
This page has 40 top multiple choice questions in C, chosen because they appear again and again in college exams, placement tests, and technical interviews. The set spans the whole language — from history and variable naming to operators, preprocessor directives, arrays, pointers, functions, files, and small program-output tracing. Each question comes with the correct answer and a short explanation in plain English. Read them carefully, especially the code-tracing questions, because those test real understanding rather than memorisation.
C Basics, Variables & Keywords
Q1. Who is the father of C language?
Answer: a) Dennis Ritchie
Dennis Ritchie is the father of the C programming language. He developed C in 1972 at AT&T Bell Laboratories in the USA. James Gosling created Java, Steve Jobs co-founded Apple, and Rasmus Lerdorf created PHP — all important figures but for other languages. C's creation was motivated by the need for a portable systems language to rewrite Unix.
Q2. Which of the following is invalid for variable names in C?
Answer: b) int $main;
C variable names can contain letters, digits, and underscores — but no other special characters. The $ symbol is not allowed. Also, variable names cannot start with a digit (that would be an invalid identifier). So int $main; is invalid. This is a common trick question because $ works fine in shell scripting but not in C.
Q3. Which one option is true regarding keywords in C?
Answer: c) LowerCase letters
All C keywords are written in lowercase: int, while, return, const, static, etc. Writing them in uppercase (INT, WHILE) or mixed case (Int) does NOT count as a keyword — the compiler treats them as regular identifiers. This is why #define TRUE 1 is common but #define true 1 with the actual keyword is not. Using uppercase is only a convention in macros.
Q4. Which one of the following is true for variable names in C?
Answer: c) Variable names cannot start with a digit
A variable name can start with a letter or underscore, not a digit. So x2, _var, name1 are valid, but 2x and 1var are invalid. Option a) is wrong — C compilers typically limit identifiers to at least 31 significant characters (the standard requires at least 31, many allow more). Option d) is wrong — using a keyword as a variable name is a compile error.
Q5. Which of the following keywords is NOT used for variable naming in C?
Answer: d) volatile
This question is a bit unusual because volatile IS a C keyword. The correct interpretation: export, friend, and import are NOT C keywords (they're Java/C++ keywords). volatile IS a C keyword, so you cannot use it as a variable name either. All four are invalid as variable names, but only volatile is a C keyword — export, friend, and import are keywords in other languages. Read the question carefully.
Q6. Which is a valid C expression?
Answer: c) int my_num = 100000;
Spaces, commas, and dollar signs are all forbidden in C identifiers or numeric literals. So "my num" (with space) fails, "my_num = 100,000" treats the comma as an operator separator (not a thousands separator — C doesn't allow that), and "$my_num" fails because of the $. Option c is the only clean, valid statement.
Q7. What is short int in C programming?
Answer: b) int is the basic type and short is a qualifier
short, long, signed, and unsigned are type modifiers (qualifiers) applied to int. So "short int" is equivalent to "short" and means a smaller integer (usually 2 bytes). "short" alone works because int is implied. The short keyword by itself is not a standalone type — it must modify int. So the correct answer is b.
Q8. Which one of the following is a wrong variable declaration in C?
Answer: c) String str;
C has no String type. Java has one, but C uses char arrays or char pointers for strings. So "String str;" is illegal — the compiler will complain that String is not a type. Option a) float str = 3e2; is valid (3e2 is scientific notation for 300.0). Option d) char *str; is valid (pointer to char). Option b is wrong because a is valid.
Q9. Which keyword is used to prevent any changes to a variable in a C program?
Answer: a) const
const is a type qualifier that tells the compiler a value cannot be modified after initialization. Any attempt to write to a const variable is a compile error. volatile, by contrast, tells the compiler the value might change externally (hardware, signal handlers). immutable and mutable are not C keywords — they're borrowed from other languages.
Operators & Expressions
Q10. What is the result of a relational or logical expression in C?
Answer: c) 0 or 1
In C, relational and logical operators always return either 0 (false) or 1 (true). Though any non-zero value is treated as true in conditions, the return value of comparison operators is exactly 0 or 1. So 5 > 3 returns 1, and 5 < 3 returns 0. This is stricter than many beginners assume.
Q11. Which of the following typecasting is accepted in C?
Answer: b) Widening & narrowing conversions
C allows both widening (int → long, float → double — no data lost) and narrowing (double → int, long → int — possible data loss) conversions. Narrowing conversions truncate data silently, so you need to be aware when doing them. In C++, both also work but the rules around static_cast/reinterpret_cast are stricter.
Q12. In which of the following does operator precedence not exist?
Answer: d) None of the mentioned
Operator precedence exists wherever operators are used — macros, conditionals, loops, everywhere. Macros don't get their own precedence rules (which is exactly why you must parenthesise macro arguments carefully). So there is no place in C where precedence doesn't apply. The correct answer is that none of the given options is exempt.
Q13. Which combination of two operators is invalid in C?
Answer: c) Same precedence and different associativity
Operators with the same precedence MUST have the same associativity in C. For example, * and / both have the same precedence and both are left-associative, so a * b / c is unambiguous. But if two operators had the same precedence and different associativity, the expression would be ambiguous (should we group left-to-right or right-to-left?). C avoids this by ensuring same-precedence operators always share associativity.
Control Statements & Functions
Q14. Which is an example of an iterative statement in C?
Answer: d) All of the above
C has exactly three iterative (loop) statements: for, while, and do-while. All three repeat a block of code until a condition is met. for is best when the iteration count is known; while when it's unknown but checked first; do-while when the body must run at least once. Any of them is correct as an "iterative statement."
Q15. Can a function return enumeration constants in C?
Answer: a) True
Yes — a function can declare an enum return type and return one of its enumerators. For example: enum Color {RED, GREEN, BLUE}; enum Color pick();. Enum types are just int-compatible types in C, so returning them is no different from returning an int. It's a clean, readable way to communicate the set of valid return values.
Q16. A function in C has which linkage by default?
Answer: a) external
By default, a C function has external linkage — it can be called from any translation unit in the program, provided a prototype is visible. To make a function file-local (internal linkage), prefix it with static: static int helper() { ... }. External linkage is what allows multi-file C programs to work; functions declared in one .c file can be called from another.
Q17. Which one is not correct in C?
Answer: b) static static int a;
Option b is the clearest error: repeating static twice is invalid — a variable can only have one storage class specifier (well, technically you can repeat static in some contexts, but "static static int" is not the standard idiom and most compilers reject it). Option a is also invalid — "static a = 10;" is missing a type (should be "static int a = 10;"). Option c is valid — static function returning int. So b is the most clearly wrong answer.
Preprocessor Directives
Q18. What is the name of the C property that allows you to create different executables for different platforms?
Answer: c) Conditional compilation
Conditional compilation (#ifdef, #ifndef, #if, #else, #endif) lets you include or exclude code based on defined macros. This is how C projects build different executables for different platforms — for example, #ifdef _WIN32 includes Windows-specific code, while #ifdef __linux__ includes Linux code. Only one path is compiled into the executable. This is one of the most powerful preprocessor features.
Q19. What is #include <stdio.h>?
Answer: a) Preprocessor directive
#include is technically called a "preprocessor directive" (specifically, a file inclusion directive). Both a and c are technically correct descriptions, but "preprocessor directive" is the umbrella term and the standard exam answer. The # at the start signals to the preprocessor, which runs before compilation. Preprocessor directives are processed in a separate pass before the compiler sees the code.
Q20. Can C preprocessors have compiler-specific features?
Answer: a) True
Compilers are free to add preprocessor extensions beyond the C standard. For example, GCC supports #pragma GCC ..., MSVC supports #pragma warning, and many compilers define predefined macros like __GNUC__, _MSC_VER, __STDC_VERSION__. These are compiler-specific but widely used in real code. The standard defines the minimum, but implementations can extend it.
Q21. Which of the following are C preprocessors?
Answer: d) All of the mentioned
All three are preprocessor directives. #ifdef starts a conditional block, #define creates a macro, and #endif ends a conditional block. Other common ones include #include, #undef, #ifndef, #else, #elif, #pragma, and #error. Together these form the preprocessor's toolkit for code manipulation before compilation.
Q22. Which symbol is used to specify the C preprocessor?
Answer: a) #
The # (hash) symbol at the start of a line tells the preprocessor to treat that line as a directive. So #include, #define, #ifdef all begin with #. This symbol must be the first non-whitespace character on the line — otherwise it's not recognized as a directive. In C, # is used ONLY for preprocessor directives (unlike shell scripts where it starts a comment).
Q23. How is searching done for #include <header.h> vs #include "header.h"?
Answer: b) Former searches standard directory, latter searches current directory first, then standard directories
Angle brackets (<...>) tell the preprocessor to search standard system directories (where stdio.h, stdlib.h live). Quotes ("...") tell it to search the current directory first, then fall back to the standard directories. Use quotes for your own project headers and angle brackets for standard library and system headers. This is a both practice and portability rule.
Arrays & Pointers
Q24. How many pointer (*) symbols can a pointer variable declaration have in C?
Answer: d) No limits (well, compiler-dependent)
C has no explicit limit on pointer depth, but in practice compilers impose small limits. Each extra * adds another level of indirection (pointer to pointer to pointer...). Most real code uses 1-2 levels; 3+ is rare. For exam purposes, "no limits" is the correct answer, though compilers like GCC might have practical limits around 10-20 levels.
Q25. Which of the array types is not possible in C?
Answer: a) Jagged Array
C has no native jagged arrays (arrays with rows of different lengths). A 2D array int a[3][4] always has fixed 4-column rows. To simulate jagged arrays, you use an array of pointers with each pointer pointing to a differently-sized block. Rectangular, cuboidal (3D), and other multidimensional arrays ARE supported natively. This is a common interview trap.
Q26. Which one of the following is an invalid return type in C?
Answer: d) None of the mentioned
All three are valid return types. char * returns a pointer to char (used for strings). struct (a struct type) can be returned (C copies the whole struct). void means the function returns nothing. So none of them are invalid — the correct choice is d. This is a common trick question because it asks "which is invalid" but none of the listed options actually are.
Files & Streams
Q27. Which standard header file is used for variable argument lists (...) in C?
Answer: d) <stdarg.h>
stdarg.h provides the va_list, va_start, va_arg, and va_end macros used to handle variable argument lists. Functions like printf and scanf use these internally. If you write your own variadic function (e.g., my_printf(const char *fmt, ...)), you include stdarg.h. stdio.h is for I/O, stdlib.h for utilities, and math.h for mathematical functions.
Q28. When a C program starts, which files does the OS open and provide pointers for?
Answer: d) All of the mentioned
Every C program starts with three standard streams already open: stdin (standard input, usually keyboard), stdout (standard output, usually terminal), and stderr (standard error, usually terminal). Each is a FILE* pre-opened by the C runtime. You don't need to fopen or fclose them — they're ready to use, and they're closed automatically at program exit.
Q29. In C, FILE is a data type of what?
Answer: c) struct
FILE is (typically) a typedef for a struct — a struct that holds the file's buffer pointer, current position, error flags, EOF flag, and other internal state. The exact layout is implementation-specific, which is why you never access its members directly. You use FILE* and the standard functions like fgetc and fclose, treating it as an opaque handle.
Q30. What is sizeof(char) in a 32-bit C compiler?
Answer: c) 1 Byte
By definition in C, sizeof(char) is always 1 byte — this is true on every platform regardless of architecture (8-bit, 16-bit, 32-bit, 64-bit). It's the only type with a guaranteed size. "1 byte" happens to be 8 bits on most modern systems, but the C standard says char is exactly 1 byte by definition. Other types vary.
Q31. Which is a valid operator in C?
Answer: d) All of the above
All three are valid operators. The comma operator evaluates two expressions and returns the right one. sizeof is a compile-time operator that returns the byte size of its operand (it's an operator, not a function, despite its function-like syntax). ~ is the bitwise NOT operator. C has an unusually large operator set — well worth memorising.
Q32. scanf() is a predefined function in which header file?
Answer: c) stdio.h
scanf and printf are both declared in stdio.h — standard input/output. stdlib.h is for general utilities (malloc, free, exit, atoi). ctype.h has character classification functions (isalpha, isdigit). stdarg.h is for variadic arguments. If you use scanf without including stdio.h, your compiler may warn or error depending on the standard and settings.
Q33. What is the meaning of 'a' in fp = fopen("Random.txt", "a");?
Answer: b) Append
The "a" mode opens the file for appending — new data is written to the end without overwriting existing content. If the file doesn't exist, it's created. Related modes: "r" (read), "w" (write, truncates), "r+" (read/write), "w+" (read/write, truncates), and "a+" (read/append). Use "a" for log files or any case where you want to keep adding to a file.
Program Output Tracing
Q34. What is the correct output of the following C code?
#include <stdio.h>
int main()
{
int y = 10000;
int y = 34;
printf("Hello World! %d\n", y);
return 0;
}
Answer: a) Compile time error
You cannot redeclare a variable with the same name in the same scope. So "int y = 10000;" followed by "int y = 34;" is a redeclaration error. The compiler will refuse to compile this file. If instead you wrote "y = 34;" (assignment without int), that would compile and print 34. This question tests the difference between declaration and assignment — a frequent point of confusion.
Q35. What will happen if we compile and execute the following C code?
#include <stdio.h>
int main()
{
int main = 3;
printf("%d", main);
return 0;
}
Answer: c) It runs successfully and prints 3
main is a function name, but it's not a reserved keyword. You can declare a local variable named main inside main itself — the local variable shadows the function name. Inside the function body, `main` refers to the local int, which is 3. So it prints 3. This is legal but terrible style — you'd never do it in real code, but exam questions love testing whether you know it compiles.
Q36. Study the following C code and find the correct output.
#include <stdio.h>
int main()
{
signed char chr;
chr = 128;
printf("%d\n", chr);
return 0;
}
Answer: b) -128
signed char holds values from -128 to +127. Assigning 128 overflows the range, wrapping around to -128. In binary, 128 is 1000_0000 — the sign bit (bit 7) is set, so it reads as -128 in two's complement. This is a common exam trap: it tests understanding of signed integer range and overflow.
Q37. What will be the output of the following on a 64-bit machine?
#include <stdio.h>
union Sti
{
int nu;
char m;
};
int main()
{
union Sti s;
printf("%d", sizeof(s));
return 0;
}
Answer: d) 4
A union's size is determined by its largest member. Here the members are int (4 bytes) and char (1 byte), so the union is 4 bytes. The fact that it's a 64-bit machine doesn't change anything — int is still 4 bytes on most 64-bit systems (LLP64, LP64 both give int = 4). Options 80, 15, and 19 are wildly off and would only appear if you misread the code.
Q38. What output will the following code produce?
#include <stdio.h>
enum birds {SPARROW, PEACOCK, PARROT};
enum pets {LION = 8, TIGER, ZEBRA, RABBIT};
int main()
{
enum birds m = LION;
int k;
k = m;
printf("%d\n", k);
return 0;
}
Answer: d) 8
In C, enum constants are just ints at the language level, and enum types are int-compatible. So assigning LION (value 8) to an enum birds variable is allowed — the compiler converts it to int 8. Then k = m copies 8 to k. It prints 8. In C++, this would be a compile error because enum types are stricter, but C is more permissive here.
Q39. Does the following code execute, and what is the output?
#include <stdio.h>
int const print()
{
printf("Hello, World!");
return 0;
}
void main()
{
print();
}
Answer: b) Hello, World!
int const is the same as const int — both mean "const int" (the const qualifier just moves around). So the function returns a const int, which is fine. The return value is discarded at the call site, but that's also legal. The program runs and prints "Hello, World!". The question tests whether you know that const int and int const are identical.
Q40. Is there any error in the given code, or does it run without error?
#include <stdio.h>
int main()
{
for(int x = 0; x < 10; x++);
return 0;
}
Answer: c) Depends on the C standard (C89 vs C99+)
Declaring a variable inside the for-loop initialization (for(int x = 0; ...)) was added in C99. In C89, you must declare x before the loop. So the code compiles under C99 and later but fails under strict C89. Most modern compilers default to C99 or later (or accept it as an extension), so it usually works in practice. This is a subtle standard-dependency question. The empty statement after the for loop is also legal (though useless).
Frequently Asked Questions
What topics are covered in these 40 top MCQs in C?
These 40 questions cover a broad range: history of C, variables and identifiers, keywords, operators and precedence, preprocessor directives, arrays and pointers, functions and linkage, structures and unions, file handling, and program-output tracing. It's designed as a broad revision set for exams and interviews.
Why are some questions marked "depends on the standard"?
C has multiple standards (C89, C99, C11, C17). Some features were added later (like declaring variables inside a for loop, which is C99), and some behaviour is implementation-defined. When a question's answer depends on the standard, we say so explicitly. This is often more accurate than picking one answer, because real codebases often target different standards.
What is the difference between a keyword and an identifier in C?
A keyword is a reserved word built into the language (if, else, while, return, const, etc.) and cannot be used as a name. An identifier is any name you choose for a variable, function, struct, etc. Keywords are always lowercase; identifiers can be any case. This distinction is fundamental to understanding C's grammar.
Why is "String str;" invalid in C?
C does not have a built-in String type. Strings in C are arrays of char (char str[100]) or pointers to char (char *str). The capital-S String comes from Java and other languages. This is a common trap question — C's approach is more manual but allows more control over memory and encoding.
What does "int const print()" mean, and does it compile?
int const is just another way to write const int — they are the same type. So the function returns a const int. The const is placed on the return type, which is unusual but legal. This compiles fine in C, though const on a plain int return value has no real effect (the caller gets a copy either way). The question tests your familiarity with reading type qualifiers placed in unusual positions.
💡 Tip: The most efficient way to revise with these 40 questions is to attempt them first without looking at answers, then check your score. If you get fewer than 30 right, review the topics in the "What You Will Learn" box above. Most candidates who get 35+ correct are well-prepared for a mid-level C interview.