Introduction
The C programming language, developed by Dennis Ritchie in 1972, remains a cornerstone of computer science education and software development. Known for its efficiency and versatility, mastering C is crucial for students preparing for competitive exams, job interviews, or academic assessments. This article presents 200 one-liner computer C language quiz questions with answers, carefully curated from trusted sources to enhance your general knowledge and exam readiness. These concise questions cover fundamental to advanced C concepts, making them ideal for quick revision and effective learning. Dive into this C language quiz with answers to test your skills and boost your confidence!
- Who developed the C programming language?
Dennis Ritchie. - In which year was C developed?
1972. - Where was C programming language developed?
Bell Laboratories. - What type of programming language is C?
General-purpose and procedural. - Which operating system was C primarily developed for?
UNIX. - What is the file extension for C source files?
.c - What is the file extension for C header files?
.h - Which keyword is used to define a constant in C?
const - Which symbol is used for the address-of operator in C?
& - Which symbol is used for the dereference operator in C?
- What is the size of an int data type in a 32-bit system?
4 bytes - What is the size of a char data type in C?
1 byte - What is the size of a double data type in C?
8 bytes - Which keyword is used to exit a loop in C?
break - Which keyword is used to skip the current iteration of a loop?
continue - What does the printf() function do in C?
Prints formatted output to the console. - What does the scanf() function do in C?
Reads formatted input from the console. - Which header file is required for printf() and scanf()?
stdio.h - What is the purpose of the main() function in C?
It is the entry point of the program. - What is the return type of the main() function in C?
int - What does the return 0 statement in main() indicate?
Successful program execution - Which operator is used for logical AND in C?
&& - Which operator is used for logical OR in C?
|| - Which operator is used for logical NOT in C?
! - What is the result of 5 % 2 in C?
1 - Which keyword is used to define a function in C?
return_type (e.g., int, void) - What is a pointer in C?
A variable that stores a memory address. - How is a pointer declared in C?
Using the * symbol, e.g., int *ptr; - What does the & operator do when used with a variable?
Returns the address of the variable - What does the * operator do when used with a pointer?
Accesses the value at the pointer’s address - What is NULL in C?
A macro representing a null pointer constant - Which header file defines NULL?
stddef.h - What is an array in C?
A collection of elements of the same data type. - How is an array declared in C?
data_type array_name[size]; - What is the index of the first element in a C array?
0 - What is a string in C?
An array of characters terminated by a null character (\0). - Which function is used to find the length of a string in C?
strlen() - Which header file is required for string functions like strlen()?
string.h - What does the strcpy() function do in C?
Copies one string to another. - What does the strcmp() function do in C?
Compares two strings lexicographically. - What is the purpose of the getchar() function in C?
Reads a single character from stdin - What is the purpose of the putchar() function in C?
Writes a single character to stdout - Which loop in C is used when the number of iterations is known?
for loop - Which loop in C is used when the condition is checked at the end?
do-while loop - What is the syntax of a while loop in C?
while (condition) { statements; } - What is a function prototype in C?
A declaration of a function’s name, return type, and parameters - What is the purpose of the void keyword in a function?
Indicates no return value or no parameters - What is recursion in C?
A function calling itself. - What is a structure in C?
A user-defined data type that groups different data types. - How is a structure declared in C?
Using the struct keyword, e.g., struct name { members; }; - What is a union in C?
A user-defined type where all members share the same memory location. - What is the size of a union in C?
Equal to the size of its largest member. - Which keyword is used to define a macro in C?
#define - What is the purpose of the #include directive in C?
Includes a header file in the program. - What does the #ifndef directive do in C?
Checks if a macro is not defined - What is the purpose of the typedef keyword in C?
Creates an alias for a data type. - What is the difference between ++i and i++ in C?
++i increments before use; i++ increments after use. - What is the ternary operator in C?
condition ? expr1 : expr2 - What is the result of a logical expression in C?
0 (false) or 1 (true). - Which keyword is used to jump to a label in C?
goto - What is the purpose of the switch statement in C?
Executes one of many code blocks based on a value. - What is the default case in a switch statement?
Executes if no case matches the expression - What happens if a break is omitted in a switch case?
Fall-through occurs, executing subsequent cases. - What is the size of a void pointer in C?
Depends on the system architecture (e.g., 4 bytes on 32-bit) - What is a dangling pointer in C?
A pointer pointing to a deallocated memory location - What is a wild pointer in C?
An uninitialized pointer - Which function allocates memory dynamically in C?
malloc() - Which function allocates and initializes memory to zero in C?
calloc() - Which function resizes dynamically allocated memory in C?
realloc() - Which function frees dynamically allocated memory in C?
free() - What is a memory leak in C?
Failure to free dynamically allocated memory - What is the purpose of the sizeof operator in C?
Returns the size of a variable or type in bytes. - What is the range of a signed int in a 16-bit system?
-32768 to 32767 - What is the format specifier for an int in printf()?
%d - What is the format specifier for a float in printf()?
%f - What is the format specifier for a character in printf()?
%c - What is the format specifier for a string in printf()?
%s - What is the format specifier for a pointer address in printf()?
%p - What does the %u format specifier represent in C?
Unsigned integer - What is a bitwise AND operator in C?
& - What is a bitwise OR operator in C?
| - What is a bitwise XOR operator in C?
^ - What is a bitwise NOT operator in C?
~ - What is the left shift operator in C?
<< - What is the right shift operator in C? The right shift operator in C is >>.
- What does the expression x << 2 do in C?
Shifts x left by 2 bits (multiplies by 4) - What does the expression x >> 1 do in C?
Shifts x right by 1 bit (divides by 2) - What is a static variable in C?
A variable that retains its value between function calls - What is the scope of a static variable declared inside a function?
Local to the function - What is the lifetime of a static variable in C?
Entire program duration - What is an extern variable in C?
A variable declared in one file and defined in another - What is the purpose of the extern keyword?
Declares a variable or function defined elsewhere - What is a volatile keyword in C?
Indicates a variable can change unexpectedly - What is an enum in C?
A user-defined type for a set of named constants - How is an enum declared in C?
enum name { value1, value2, … }; - What is the default value of the first enum member in C?
0 - What is a file pointer in C?
A pointer to a FILE structure for file operations - Which function opens a file in C?
fopen() - Which function closes a file in C?
fclose() - What is the mode “r” in fopen() used for?
Opens a file for reading - What is the mode “w” in fopen() used for?
Opens a file for writing (creates or overwrites) - What is the mode “a” in fopen() used for?
Opens a file for appending - Which function reads a character from a file in C?
fgetc() - Which function writes a character to a file in C?
fputc() - Which function reads a string from a file in C?
fgets() - Which function writes a string to a file in C?
fputs() - What is the purpose of the feof() function in C?
Checks for end-of-file condition - What is the purpose of the fseek() function in C?
Moves the file pointer to a specific position - What is the purpose of the ftell() function in C?
Returns the current file pointer position - What is the purpose of the rewind() function in C?
Moves the file pointer to the beginning of the file - What is a command-line argument in C?
Arguments passed to the main() function - How is the main() function defined to accept command-line arguments?
int main(int argc, char *argv[]) - What does argc represent in main()?
Number of command-line arguments - What does argv represent in main()?
Array of command-line argument strings - What is the first element of argv in C?
The program name - What is a preprocessor in C?
A tool that processes source code before compilation - What is the purpose of the #pragma directive in C?
Provides compiler-specific instructions - What does the #error directive do in C?
Generates a compilation error with a message - What does the #line directive do in C?
Changes the reported line number and file name - What is a macro in C?
A fragment of code replaced by the preprocessor - What is the difference between a macro and a function in C?
Macros are preprocessed; functions are compiled - What is a conditional compilation in C?
Including or excluding code based on conditions - What is the purpose of the #ifdef directive?
Checks if a macro is defined - What is the purpose of the #endif directive?
Ends a conditional compilation block - What is a typecasting in C?
Converting one data type to another - What is implicit typecasting in C?
Automatic conversion by the compiler - What is explicit typecasting in C?
Manual conversion using a cast operator - What is the syntax for explicit typecasting in C?
(type) expression - What is a segmentation fault in C?
An error caused by accessing invalid memory - What is a buffer overflow in C?
Writing data beyond a buffer’s allocated memory - What is the purpose of the assert() function in C?
Tests a condition and terminates if false - Which header file is required for assert()?
assert.h - What is the purpose of the exit() function in C?
Terminates the program - Which header file is required for exit()?
stdlib.h - What is the purpose of the atoi() function in C?
Converts a string to an integer - What is the purpose of the atof() function in C?
Converts a string to a float - Which header file is required for atoi() and atof()?
stdlib.h - What is the purpose of the rand() function in C?
Generates a pseudo-random number - Which header file is required for rand()?
stdlib.h - What is the purpose of the srand() function in C?
Seeds the random number generator - What is a bitwise operation in C?
Operations on individual bits of data - What is the result of 5 & 3 in C?
1 (binary: 0101 & 0011 = 0001) - What is the result of 5 | 3 in C?
7 (binary: 0101 | 0011 = 0111) - What is the result of 5 ^ 3 in C?
6 (binary: 0101 ^ 0011 = 0110) - What is the result of ~5 in C (assuming 32-bit int)?
-6 (binary: ~00000101 = 11111010) - What is a function pointer in C?
A pointer that points to a function - How is a function pointer declared in C?
return_type (*pointer_name)(parameter_types); - What is a call-by-value in C?
Passing a copy of a variable to a function - What is a call-by-reference in C?
Passing a pointer to a variable to a function - What is the purpose of the const keyword in a function parameter?
Prevents modification of the parameter - What is a storage class in C?
Defines the scope and lifetime of a variable - What are the four storage classes in C?
auto, register, static, extern - What is the default storage class for local variables in C?
auto - What is the purpose of the register storage class in C?
Suggests storing a variable in a CPU register - What is a global variable in C?
A variable declared outside all functions - What is the scope of a global variable in C?
Entire program - What is a local variable in C?
A variable declared inside a function or block - What is the scope of a local variable in C?
Limited to the function or block - What is the lifetime of a local variable in C?
Until the function or block ends - What is a variable initialization in C?
Assigning a value to a variable at declaration - What is the default value of an uninitialized global variable in C?
0 - What is the default value of an uninitialized local variable in C?
Garbage value - What is a format string vulnerability in C?
Improper use of format specifiers in printf/scanf - What is the purpose of the getch() function in C?
Reads a character without echoing to the console - Which header file is required for getch()?
conio.h (non-standard) - What is the purpose of the clrscr() function in C?
Clears the console screen (non-standard) - What is a multidimensional array in C?
An array of arrays - How is a 2D array declared in C?
data_type array_name[rows][columns]; - What is the purpose of the const pointer in C?
A pointer that cannot change the address it holds - What is the purpose of a pointer to const in C?
A pointer that cannot modify the data it points to - What is a far pointer in C?
A pointer that can access memory outside the current segment (legacy) - What is a near pointer in C?
A pointer limited to the current segment (legacy) - What is a self-referential structure in C?
A structure containing a pointer to its own type - What is a linked list in C?
A data structure with nodes linked via pointers - What is the purpose of the malloc() function in a linked list?
Allocates memory for a new node - What is a double pointer in C?
A pointer to a pointer (e.g., int **ptr) - What is the purpose of a double pointer in C?
Used for dynamic memory allocation or passing pointers to functions - What is a variadic function in C?
A function that accepts a variable number of arguments - Which header file is required for variadic functions?
stdarg.h - What is the purpose of the va_start macro in C?
Initializes access to variadic function arguments - What is the purpose of the va_arg macro in C?
Retrieves the next argument in a variadic function - What is the purpose of the va_end macro in C?
Cleans up after accessing variadic arguments - What is a signal in C?
A software interrupt delivered to a program - Which header file is required for signal handling in C?
signal.h - What is the purpose of the raise() function in C?
Sends a signal to the program - What is the purpose of the signal() function in C?
Sets a handler for a specific signal - What is a floating-point exception in C?
An error like division by zero in floating-point operations - What is the purpose of the math.h header file in C?
Provides mathematical functions like sqrt(), sin() - What is the purpose of the time.h header file in C?
Provides functions for date and time operations - What is the purpose of the ctype.h header file in C?
Provides functions for character classification - What is the purpose of the isalpha() function in C?
Checks if a character is alphabetic - What is the purpose of the isdigit() function in C?
Checks if a character is a digit - What is the purpose of the toupper() function in C?
Converts a character to uppercase - What is the purpose of the tolower() function in C?
Converts a character to lowercase - What is a preprocessor directive in C?
Instructions processed before compilation - What is the purpose of the #elif directive in C?
Provides an else-if condition in preprocessing - What is the purpose of the #undef directive in C?
Undefines a macro - What is a token in C?
A basic building block like keywords, identifiers - What is the maximum length of an identifier in C?
Implementation-dependent (often 31 characters) - What is the purpose of the inline keyword in C?
Suggests inlining a function for optimization
Conclusion
Mastering the C programming language is a vital step for students and professionals aiming to excel in computer science. These 200 one-liner computer C language quiz questions with answers provide a comprehensive resource for quick learning and exam preparation. By practicing these questions, you can strengthen your understanding of C fundamentals, advanced concepts, and common pitfalls. Keep revisiting this C language quiz with answers to stay sharp and confident for your exams and interviews. Happy coding!
Disclaimer
The information provided in this article, including the computer C language quiz questions with answers, is compiled from various trusted online sources for educational purposes only. While efforts have been made to ensure accuracy, we do not guarantee the correctness or completeness of the content. Users are advised to verify answers independently before relying on them for examinations or professional use. The authors and publishers are not liable for any errors, omissions, or consequences arising from the use of this content.