C Language MCQ Questions and Answers. A collection of C language multiple choice questions with answers, suitable for Class 11-12 studies. Includes basic concepts, functions & pointers.
C Language MCQ Questions and Answers – Mock Online Test
Question 1: Which language directly influenced the development of C?
A. Java
B. B
C. Python
D. COBOL
B. B. C was derived from the B programming language, which itself was influenced by BCPL.
Question 2: Who is credited with creating the C programming language?
A. Bjarne Stroustrup
B. James Gosling
C. Dennis Ritchie
D. Guido van Rossum
C. Dennis Ritchie. Dennis Ritchie developed C at Bell Labs in the early 1970s.
Question 3: What is the name of the first widely available description of the C language, often referred to as “K&R C”?
A. The C Programming Language
B. The C++ Programming Language
C. The C Standard Library
D. The C Reference Manual
A. The C Programming Language. This book, written by Brian Kernighan and Dennis Ritchie, became a definitive guide for C programmers.
Question 4: Which of the following is NOT a C standard?
A. ANSI C
B. C99
C. C++11
D. K&R C
C. C++11. This is a standard for the C++ programming language, not C.
Question 5: C played a crucial role in the development of which operating system?
A. Windows
B. macOS
C. Unix
D. Android
C. Unix. C was initially developed to rewrite the Unix operating system.
Question 6: What programming paradigm does C follow?
A. Object-oriented
B. Functional
C. Procedural
D. Logic
C. Procedural. C programs are structured around procedures or functions that perform specific tasks.
Question 7: Which feature allows C programs to run on different types of computers with minimal changes?
A. Modularity
B. Efficiency
C. Portability
D. Low-level access
C. Portability. C code can be compiled and run on various platforms with little or no modification.
Question 8: What mechanism in C promotes code reusability?
A. Classes
B. Objects
C. Functions
D. Templates
C. Functions. Functions encapsulate blocks of code that can be reused multiple times within a program.
Question 9: C is known for its efficiency because it:
A. Is interpreted
B. Has automatic garbage collection
C. Provides low-level access to hardware
D. Uses dynamic typing
C. Provides low-level access to hardware. This allows for direct manipulation of memory and system resources.
Question 10: What type of language is C, in terms of how it is executed?
A. Interpreted
B. Compiled
C. Scripted
D. Markup
B. Compiled. C code is translated into machine code by a compiler before execution.
Question 11: Which of the following is NOT a characteristic of C?
A. High-level abstraction
B. Rich set of operators
C. Modularity
D. Efficiency
A. High-level abstraction. While C provides some abstraction, it is generally considered a lower-level language compared to languages like Java or Python.
Question 12: What is the process of converting C source code into an executable program called?
A. Interpretation
B. Compilation
C. Assembly
D. Linking
B. Compilation. A compiler translates the human-readable C code into machine code that the computer can understand.
Question 13: Which of the following is a popular compiler for C?
A. Python interpreter
B. Java Virtual Machine
C. GCC
D. Node.js
C. GCC. GCC (GNU Compiler Collection) is a widely used compiler for C and other languages.
Question 14: What is the purpose of a linker in C programming?
A. To write the source code
B. To compile the source code
C. To combine object files and libraries into an executable
D. To debug the program
C. To combine object files and libraries into an executable. The linker resolves references between different code modules.
Question 15: What is the typical file extension for C source code files?
A. .cpp
B. .java
C. .c
D. .py
C. .c. C source code files are typically saved with the .c extension.
Question 16: Which of the following is NOT a component of a typical C development environment?
A. Text editor
B. Compiler
C. Web browser
D. Debugger
C. Web browser. While a web browser might be used for accessing documentation, it’s not a core component of the development environment itself.
Question 17: What is the first step in creating a C program?
A. Compiling the code
B. Running the code
C. Writing the source code in a text editor
D. Linking the object files
C. Writing the source code in a text editor. You need to write the C code before you can compile or run it.
Question 18: What command is commonly used to compile C code using GCC?
A. python
B. java
C. gcc
D. node
C. gcc. The gcc command invokes the GNU Compiler Collection to compile C code.
Question 19: What is the name of the function that serves as the entry point for execution in a C program?
A. start()
B. main()
C. begin()
D. execute()
B. main(). The main() function is where the program’s execution begins.
Question 20: What is the purpose of header files in C?
A. To store the program’s executable code.
B. To define functions, variables, and macros.
C. To contain the program’s main logic.
D. To provide comments and documentation.
B. To define functions, variables, and macros. Header files provide declarations and definitions that can be used in multiple source files.
Question 21: Which preprocessor directive is used to include header files in a C program?
A. #define
B. #ifdef
C. #include
D. #pragma
C. #include. The #include directive tells the preprocessor to insert the contents of a header file into the source code.
Question 22: What function is commonly used to display output to the console in C?
A. scanf()
B. print()
C. cout
D. printf()
D. printf(). The printf() function is used for formatted output to the console.
Question 23: What is the purpose of comments in C code?
A. To instruct the compiler.
B. To improve code readability and provide explanations.
C. To define variables.
D. To declare functions.
B. To improve code readability and provide explanations. Comments are ignored by the compiler and serve as documentation for humans.
Question 24: What symbol is used to indicate a single-line comment in C?
A. //
B. /* */
C. D. # [Answer: A. //. Two forward slashes (//) mark the beginning of a single-line comment.]
Question 25: What is the purpose of the scanf() function in C? A. To display output to the console. B. To read input from the user. C. To define variables.
D. To perform mathematical calculations.
B. To read input from the user. The scanf() function is used for formatted input from the console.
Question 26: Which of the following is NOT an integer data type in C?
A. int
B. char
C. float
D. long
C. float. float is a floating-point data type, used for representing numbers with decimal points.
Question 27: What data type is used to store single characters in C?
A. int
B. char
C. string
D. float
B. char. The char data type is used to store individual characters like ‘A’, ‘b’, or ‘?’.
Question 28: What is the purpose of the void data type in C?
A. To represent integers.
B. To store decimal numbers.
C. To indicate the absence of a value or type.
D. To define strings.
C. To indicate the absence of a value or type. void is often used for functions that do not return a value.
Question 29: What is the correct way to declare an integer variable named “age” in C?
A. int age;
B. variable age;
C. age integer;
D. declare age as int;
A. int age;. The syntax for variable declaration is data_type variable_name;
Question 30: What is the process of assigning an initial value to a variable at the time of declaration called?
A. Declaration
B. Definition
C. Initialization
D. Assignment
C. Initialization. For example, int age = 25; initializes the age variable to 25.
Question 31: What are values that cannot be changed during program execution called?
A. Variables
B. Constants
C. Literals
D. Identifiers
B. Constants. Constants are fixed values that remain the same throughout the program.
Question 32: Which keyword is used to declare a constant in C?
A. constant
B. const
C. fixed
D. static
B. const. The const keyword is used to declare a constant, e.g., const int MAX_VALUE = 100;
Question 33: Where are variables typically stored in a computer’s memory?
A. Hard drive
B. CPU
C. RAM
D. ROM
C. RAM. Variables are stored in RAM (Random Access Memory) for fast access during program execution.
Question 34: Which operator is used for addition in C?
A.+
B.-
C.*
D./
A. +. The plus symbol (+) is the addition operator.
Question 35: What does the modulus operator (%) do?
A. Divides two numbers.
B. Returns the remainder of a division operation.
C. Multiplies two numbers.
D. Subtracts one number from another.
B. Returns the remainder of a division operation. For example, 10 % 3 would result in 1.
Question 36: Which operator is used to check if two values are equal in C?
A.=
B.==
C.!=
D.>
B. ==. The double equals sign (==) is the equality operator.
Question 37: What does the logical AND operator (&&) do?
A. Returns true if either operand is true.
B. Returns true if both operands are true.
C. Returns true if an operand is false.
D. Inverts the logical value of an operand.
B. Returns true if both operands are true.
Question 38: Which operator is used to perform a bitwise XOR operation in C?
A.&
B.|
C.^
D.~
C. ^. The caret symbol (^) is the bitwise XOR operator.
Question 39: What is the purpose of the assignment operator (=) in C?
A. To check if two values are equal.
B. To assign a value to a variable.
C. To perform addition.
D. To compare two values.
B. To assign a value to a variable. For example, age = 30; assigns the value 30 to the variable age.
Question 40: What is the order in which operators are evaluated in an expression called?
A. Associativity
B. Precedence
C. Evaluation order
D. Grouping
B. Precedence. Operators with higher precedence are evaluated before operators with lower precedence.
Question 41: What is the process of converting one data type to another called in C?
A. Casting
B. Transformation
C. Parsing
D. Transmutation
A. Casting. For example, (int)3.14 would convert the floating-point number 3.14 to an integer.
Question 42: Which of the following is NOT a type of operator in C?
A. Arithmetic
B. Relational
C. Logical
D. Declarative
D. Declarative. Declarative is a programming paradigm, not a type of operator.
Question 43: Which statement is used to execute a block of code only if a condition is true?
A.for
B.while
C.if
D.switch
C. if. The if statement allows for conditional execution of code.
Question 44: What is the keyword used to specify an alternative block of code to be executed if the condition in an if statement is false?
A.else
B.elseif
C.otherwise
D.elif
A. else. The else block is executed when the if condition is false.
Question 45: What is a series of nested if-else statements called?
A. Conditional chain
B. Nested conditional
C. If-else ladder
D. Branching statement
C. If-else ladder. This structure allows for multiple conditions to be checked sequentially.
Question 46: Which statement allows you to select one of many code blocks to be executed based on the value of an expression?
A.if
B.while
C.for
D.switch
D. switch. The switch statement provides a way to choose between multiple cases based on a value.
Question 47: What keyword is used to exit a switch statement in C?
A.exit
B.return
C.break
D.continue
C. break. The break statement is used to prevent fall-through to the next case.
Question 48: What is the purpose of the default case in a switch statement?
A. To specify the first case to be checked.
B. To provide a catch-all block of code if no other case matches.
C. To define a condition for the switch statement.
D. To exit the switch statement.
B. To provide a catch-all block of code if no other case matches.
Question 49: Which loop is used when you know the number of iterations in advance?
A.for
B.while
C.do-while
D.repeat-until
A. for. The for loop is ideal for situations where the number of iterations is predetermined.
Question 50: What is the section of a for loop that determines whether the loop should continue or terminate called?
A. Initialization
B. Condition
C. Update
D. Body
B. Condition. The condition is evaluated before each iteration; if it’s true, the loop continues.
Question 51: Which loop continues to execute as long as its condition remains true?
A.for
B.while
C.do-while
D.if
B. while. The while loop repeatedly executes its code block as long as the specified condition is true.
Question 52: What is the key difference between a while loop and a do-while loop?
A. A while loop always executes at least once.
B. A do-while loop always executes at least once.
C. A while loop is used for definite iteration.
D. A do-while loop cannot have a condition.
B. A do-while loop always executes at least once. The condition is checked after the loop body executes.
Question 53: What is a loop placed inside another loop called?
A. Inner loop
B. Outer loop
C. Nested loop
D. Parallel loop
C. Nested loop. Nested loops allow for more complex iterative processes.
Question 54: Which keyword is used to immediately exit a loop in C?
A.exit
B.return
C.break
D.continue
C. break. The break statement terminates the loop and transfers execution to the code following the loop.
Question 55: What does the continue keyword do in a loop?
A. Exits the loop completely.
B. Skips the current iteration and proceeds to the next.
C. Pauses the loop execution.
D. Restarts the loop from the beginning.
B. Skips the current iteration and proceeds to the next. continue jumps to the next iteration of the loop.
Question 56: What is a function prototype in C?
A. The complete definition of a function.
B. A declaration of a function that specifies its name, return type, and parameters.
C. The code that calls a function.
D. A comment that describes what a function does.
B. A declaration of a function that specifies its name, return type, and parameters.
Question 57: What is the keyword used to specify the type of value a function returns in C?
A.void
B.return
C.function
D. The data type of the return value (e.g., int, float)
D. The data type of the return value (e.g., int, float). This indicates the type of value the function will send back to the caller.
Question 58: What is the process of passing data to a function called?
A. Function calling
B. Argument passing
C. Value returning
D. Data sharing
B. Argument passing. Arguments are the values provided to a function when it’s called.
Question 59: What keyword is used to send a value back from a function to its caller?
A.void
B.return
C.send
D.back
B. return. The return statement sends a value back to the calling function.
Question 60: What is the region of a program where a variable is accessible called?
A. Scope
B. Lifetime
C. Visibility
D. Accessibility
A. Scope. A variable’s scope determines where in the code it can be used.
Question 61: What type of variable is declared inside a function and is only accessible within that function?
A. Global variable
B. Local variable
C. Static variable
D. External variable
B. Local variable. Local variables have function-level scope.
Question 62: What is a function that calls itself called?
A. Iterative function
B. Recursive function
C. Self-referential function
D. Nested function
B. Recursive function. Recursion involves a function calling itself to solve a problem.
Question 63: Which of the following is NOT a common application of recursion?
A. Calculating factorials
B. Traversing tree structures
C. Sorting arrays
D. Performing simple arithmetic operations
D. Performing simple arithmetic operations. Recursion is typically used for more complex tasks that can be broken down into smaller, self-similar subproblems.
Question 64: What is the process of dividing a program into smaller, self-contained units called functions referred to as?
A. Object-oriented programming
B. Modular programming
C. Functional programming
D. Structured programming
B. Modular programming. This approach improves code organization and reusability.
Question 65: What is a key benefit of using functions in C?
A. Increased code complexity
B. Reduced code reusability
C. Improved code readability and maintainability
D. Slower program execution
C. Improved code readability and maintainability. Functions make code easier to understand, debug, and modify.
Question 66: What design approach starts with a high-level overview of the program and breaks it down into smaller, more manageable components?
A. Bottom-up design
B. Top-down design
C. Inside-out design
D. Spiral design
B. Top-down design. This method helps in organizing complex programs by starting with the overall structure and refining it step by step.
Question 67: What is the process of gradually refining program components into more detailed implementations called?
A. Decomposition
B. Abstraction
C. Stepwise refinement
D. Modularization
C. Stepwise refinement. This technique involves breaking down a problem into smaller steps and implementing them in a systematic way.
Question 68: What is the primary purpose of using header files in modular programming?
A. To store the program’s executable code.
B. To organize function declarations and make them accessible to multiple source files.
C. To contain the program’s main logic.
D. To provide comments and documentation.
B. To organize function declarations and make them accessible to multiple source files. This promotes code reusability and reduces redundancy.
Question 69: What is a collection of elements of the same data type stored contiguously in memory called?
A. Structure
B. Union
C. Array
D. List
C. Array. Arrays provide a way to store multiple values of the same type under a single name.
Question 70: How are individual elements within an array accessed?
A. By their names
B. By their values
C. By their indices (positions)
D. By their memory addresses
C. By their indices (positions). Array indices start from 0.
Question 71: What is a common way to process all elements in an array?
A. Using conditional statements
B. Using loops
C. Using functions
D. Using pointers
B. Using loops. Loops provide a convenient way to iterate through array elements.
Question 72: What is an array with more than one dimension called?
A. Single-dimensional array
B. Linear array
C. Multidimensional array
D. Dynamic array
C. Multidimensional array. These arrays have rows and columns (or more dimensions).
Question 73: How are arrays typically passed to functions in C?
A. By value
B. By reference
C. By pointer
D. By copy
C. By pointer. When passing an array to a function, you’re actually passing a pointer to its first element.
Question 74: If an array is declared as int numbers[5];, what is the index of the last element?
A. 5
B. 6
C. 4
D. 0
C. 4. Array indices start from 0, so the last element in a 5-element array has an index of 4.
Question 75: How are strings represented in C?
A. As a separate string data type
B. As arrays of characters
C. As individual characters
D. As pointers to characters
B. As arrays of characters. A string is a sequence of characters terminated by a null character (‘\0’).
Question 76: What is the special character used to mark the end of a string in C?
A. \n
B. \t
C. \0
D. \
C. \0. The null character signals the end of the string.
Question 77: Which function is used to find the length of a string in C?
A.length()
B.size()
C.strlen()
D.strsize()
C. strlen(). The strlen() function returns the number of characters in a string (excluding the null terminator).
Question 78: What function is used to copy one string to another in C?
A.strcpy()
B.strcat()
C.strdup()
D.strcopy()
A. strcpy(). The strcpy() function copies the contents of one string to another.
Question 79: What function is used to concatenate (join) two strings in C?
A.strcpy()
B.strcat()
C.strjoin()
D.stradd()
B. strcat(). The strcat() function appends one string to the end of another.
Question 80: What is a sequence of characters enclosed in double quotes called in C?
A. Character array
B. String literal
C. String constant
D. Character sequence
B. String literal. For example, “Hello, world!” is a string literal.
Question 81: What is a variable that stores the memory address of another variable called?
A. Array
B. Structure
C. Pointer
D. Function
C. Pointer. Pointers provide a way to indirectly access and manipulate data.
Question 82: What symbol is used to declare a pointer variable in C?
A.&
B.*
C.->
D..
B. *. The asterisk (*) is used in pointer declarations.
Question 83: What is the process of accessing the value stored at the memory address held by a pointer called?
A. Pointer assignment
B. Dereferencing
C. Pointer arithmetic
D. Address resolution
B. Dereferencing. The dereference operator (*) is used to access the value.
Question 84: What does pointer arithmetic allow you to do?
A. Perform mathematical operations on memory addresses.
B. Compare the values of two pointers.
C. Assign a new value to a pointer.
D. All of the above.
D. All of the above. Pointer arithmetic includes operations like adding or subtracting integers from pointers.
Question 85: What is the relationship between pointers and arrays in C?
A. Arrays are implemented using pointers.
B. An array name can be used as a pointer to its first element.
C. Pointer arithmetic can be used to access array elements.
D. All of the above.
D. All of the above. There’s a close connection between pointers and arrays in C.
Question 86: If ptr is a pointer to an integer, what does *ptr represent?
A. The address of the pointer itself.
B. The value of the integer that ptr points to.
C. The size of the integer.
D. The data type of the pointer.
B. The value of the integer that ptr points to. Dereferencing the pointer gives you the value it points to.
Question 87: What is the mechanism of passing a pointer to a function as an argument called?
A. Pass by value
B. Pass by reference
C. Pass by pointer
D. Both B and C
D. Both B and C. Passing by reference in C is achieved using pointers.
Question 88: What is a key advantage of passing pointers to functions?
A. It allows you to modify the original values of variables passed as arguments.
B. It reduces the amount of memory used.
C. It makes the code more readable.
D. It prevents errors.
A. It allows you to modify the original values of variables passed as arguments. This is because the function receives the memory address of the variable.
Question 89: Can functions return pointers?
A. No, functions can only return basic data types.
B. Yes, functions can return pointers to any data type.
C. Yes, but only pointers to integers.
D. It depends on the compiler.
B. Yes, functions can return pointers to any data type. This can be useful for returning dynamically allocated memory or pointers to structures.
Question 90: What is the process of allocating memory during program execution called?
A. Static memory allocation
B. Dynamic memory allocation
C. Automatic memory allocation
D. Memory reservation
B. Dynamic memory allocation. This allows you to allocate memory as needed while the program is running.
Question 91: Which function is commonly used to allocate a block of memory dynamically in C?
A.malloc()
B.calloc()
C.realloc()
D. All of the above
D. All of the above. malloc() allocates a block of memory, calloc() allocates and initializes it to zero, and realloc() resizes an existing block.
Question 92: What function is used to deallocate dynamically allocated memory in C?
A.delete()
B.free()
C.release()
D.dealloc()
B. free(). It’s important to free dynamically allocated memory to prevent memory leaks.
Question 93: What is a user-defined data type that groups related variables of different data types under a single name called?
A. Array
B. Structure
C. Union
D. Pointer
B. Structure. Structures allow you to create complex data types by combining variables of various types.
Question 94: What operator is used to access members of a structure in C?
A.. (dot operator)
B.-> (arrow operator)
C.* (asterisk)
D.& (ampersand)
A. . (dot operator). For example, if you have a structure student with a member name, you would access it as student.name.
Question 95: Can structures be passed to functions and returned from functions?
A. No, only basic data types can be used with functions.
B. Yes, structures can be passed by value or by reference (using pointers).
C. Yes, but only small structures can be use
D. D. It depends on the compiler.
B. Yes, structures can be passed by value or by reference (using pointers). This allows you to work with complex data structures within functions.
Question 96: What is a structure defined within another structure called?
A. Inner structure
B. Nested structure
C. Substructure
D. Child structure
B. Nested structure. Nesting structures provides a way to create hierarchical data organizations.
Question 97: What is a union in C?
A. A data type that groups variables of different data types, where all members share the same memory location.
B. The same as a structure.
C. A special type of pointer.
D. A way to define constants.
A. A data type that groups variables of different data types, where all members share the same memory location. This means that only one member of a union can hold a value at a time.
Question 98: What is the key difference between a structure and a union?
A. Structures can hold data of different types, while unions cannot.
B. Members of a structure share the same memory location, while members of a union do not.
C. Members of a union share the same memory location, while members of a structure do not.
D. There is no difference.
C. Members of a union share the same memory location, while members of a structure do not. This makes unions more memory-efficient in certain situations.
Question 99: Which of the following is a potential application of a union?
A. Storing data that can have different interpretations (e.g., a value that can be treated as an integer or a float).
B. Representing complex data structures with hierarchical relationships.
C. Creating arrays of different data types.
D. Defining functions with multiple return types.
A. Storing data that can have different interpretations (e.g., a value that can be treated as an integer or a float). Unions can be used when you need to store different types of data in the same memory location, but only one type at a time.
Question 100: Which function is used to open a file in C?
A.open()
B.fopen()
C.create_file()
D.file_open()
B. fopen(). This function opens a file and returns a file pointer that can be used for subsequent file operations.