1. Who is credited with developing the C programming language?
ⓐ. Bjarne Stroustrup
ⓑ. James Gosling
ⓒ. Dennis Ritchie
ⓓ. Guido van Rossum
Explanation: Dennis Ritchie, an American computer scientist, is credited with developing the C programming language in the early 1970s at Bell Labs.
2. In which year was the C programming language first developed?
ⓐ. 1969
ⓑ. 1972
ⓒ. 1978
ⓓ. 1983
Explanation: The C programming language was first developed in 1972 by Dennis Ritchie as a system programming language for the Unix operating system.
3. Which programming language was C derived from?
ⓐ. Fortran
ⓑ. COBOL
ⓒ. B
ⓓ. Pascal
Explanation: C was derived from the B programming language, which was developed by Ken Thompson as a simplified version of the BCPL language.
4. What was the main purpose behind the development of the C programming language?
ⓐ. Web development
ⓑ. Game development
ⓒ. System programming
ⓓ. Data analysis
Explanation: The C programming language was developed mainly for system programming to write the Unix operating system, which required efficient, low-level access to memory and system processes.
5. Which company played a significant role in the development of the C programming language?
ⓐ. IBM
ⓑ. Bell Labs
ⓒ. Microsoft
ⓓ. Apple
Explanation: Bell Labs (Bell Telephone Laboratories) was where Dennis Ritchie and his colleagues developed the C programming language.
6. Which book is considered the authoritative reference on the C programming language?
ⓐ. The C Programming Language
ⓑ. C Programming: A Modern Approach
ⓒ. C in a Nutshell
ⓓ. Head First C
Explanation: “The C Programming Language,” often referred to as K&R (after authors Brian Kernighan and Dennis Ritchie), is considered the definitive book on the C programming language.
7. What does the “ANSI C” standard refer to?
ⓐ. The original version of C
ⓑ. The version of C approved by the American National Standards Institute
ⓒ. A variant of C designed for networking
ⓓ. A C-like scripting language
Explanation: “ANSI C” refers to the standardization of the C programming language by the American National Standards Institute, which established consistent guidelines and definitions for C.
8. Which operating system’s development was significantly influenced by the C programming language?
ⓐ. Windows
ⓑ. Linux
ⓒ. Unix
ⓓ. macOS
Explanation: The development of the Unix operating system was significantly influenced by the C programming language, as it was rewritten in C to take advantage of its portability and efficiency.
9. Which of the following is a characteristic feature of the C programming language?
ⓐ. Automatic memory management
ⓑ. Strong type enforcement
ⓒ. Low-level access to memory
ⓓ. Built-in GUI support
Explanation: One of the characteristic features of the C programming language is its ability to provide low-level access to memory through pointers, which allows for efficient system-level programming.
10. Which language is often considered the successor to C and was also developed by Dennis Ritchie and his colleagues?
ⓐ. C++
ⓑ. Java
ⓒ. Python
ⓓ. Go
Explanation: C++, developed by Bjarne Stroustrup as an extension of the C language, is often considered the successor to C, providing object-oriented features while maintaining compatibility with C.
11. Which feature of C allows the direct manipulation of memory addresses?
ⓐ. Functions
ⓑ. Arrays
ⓒ. Pointers
ⓓ. Structures
Explanation: Pointers are a feature in C that allow direct manipulation of memory addresses, enabling efficient memory management and manipulation.
12. What is the significance of the `main` function in a C program?
ⓐ. It initializes global variables.
ⓑ. It serves as the entry point of the program.
ⓒ. It manages memory allocation.
ⓓ. It is used for debugging purposes.
Explanation: The `main` function is the starting point of execution for a C program. It is where the program begins and ends.
13. Which feature of C allows the creation of user-defined data types?
ⓐ. Loops
ⓑ. Functions
ⓒ. Structures
ⓓ. Arrays
Explanation: Structures in C allow the creation of user-defined data types that can group variables of different types under a single name.
14. What does the term “portability” mean in the context of C programming?
ⓐ. The ability to run the same code on different operating systems without modification.
ⓑ. The ability to manage memory efficiently.
ⓒ. The ability to use object-oriented features.
ⓓ. The ability to handle exceptions.
Explanation: Portability in C programming refers to the ability of code to be compiled and run on different hardware and operating systems with little or no modification.
15. Which feature of C enables the reuse of code and modular programming?
ⓐ. Macros
ⓑ. Functions
ⓒ. Variables
ⓓ. Pointers
Explanation: Functions in C enable the reuse of code and support modular programming by allowing complex operations to be broken down into simpler, reusable pieces.
16. Which feature of C supports the concept of dynamic memory allocation?
ⓐ. Arrays
ⓑ. Pointers
ⓒ. Structures
ⓓ. Functions
Explanation: Pointers in C support dynamic memory allocation, allowing programs to request memory at runtime using functions like `malloc` and `free`.
17. How does C handle input and output operations?
ⓐ. Through built-in language constructs
ⓑ. Through library functions
ⓒ. Through graphical user interfaces
ⓓ. Through command-line arguments
Explanation: C handles input and output operations through library functions such as `printf`, `scanf`, `fopen`, and `fclose` defined in standard libraries like `stdio.h`.
18. What is a key feature of C that allows it to be used for system-level programming?
ⓐ. High-level abstraction
ⓑ. Built-in string handling
ⓒ. Low-level bit manipulation
ⓓ. Object-oriented features
Explanation: C provides low-level bit manipulation, which is essential for system-level programming tasks such as writing operating systems and embedded systems.
19. Which keyword in C is used to define constants?
ⓐ. const
ⓑ. static
ⓒ. define
ⓓ. enum
Explanation: The `const` keyword in C is used to define constant variables whose values cannot be changed after initialization.
20. Which feature of C is essential for managing large software projects?
ⓐ. Macros
ⓑ. Header files
ⓒ. Inline assembly
ⓓ. Preprocessor directives
Explanation: Header files in C are essential for managing large software projects as they allow the separation of code into reusable components, making it easier to manage dependencies and code organization.
21. Which C feature supports conditional compilation?
ⓐ. Functions
ⓑ. Pointers
ⓒ. Preprocessor directives
ⓓ. Arrays
Explanation: Preprocessor directives such as `#ifdef`, `#ifndef`, `#else`, and `#endif` support conditional compilation in C, allowing the compiler to include or exclude parts of the code based on defined conditions.
22. What does the `static` keyword indicate when applied to a variable in a C function?
ⓐ. The variable is global.
ⓑ. The variable retains its value between function calls.
ⓒ. The variable is constant.
ⓓ. The variable is thread-safe.
Explanation: When a variable in a C function is declared as `static`, it retains its value between calls to that function, maintaining state across multiple invocations.
23. Which feature of C allows the grouping of different types of variables under one name?
ⓐ. Arrays
ⓑ. Enums
ⓒ. Structures
ⓓ. Unions
Explanation: Structures in C allow grouping variables of different types under a single name, facilitating complex data management.
24. What is the purpose of the `extern` keyword in C?
ⓐ. To declare a constant variable.
ⓑ. To declare a variable that is defined in another file.
ⓒ. To define a function.
ⓓ. To allocate dynamic memory.
Explanation: The `extern` keyword is used to declare a variable or function that is defined in another file, allowing for the sharing of variables across multiple files.
25. Which feature of C allows the definition of symbolic constants?
ⓐ. Macros
ⓑ. Enums
ⓒ. Typedef
ⓓ. Static
Explanation: Macros, defined using the `#define` preprocessor directive, allow the definition of symbolic constants, making the code more readable and maintainable.
26. What is the role of the `typedef` keyword in C?
ⓐ. To define a new data type name.
ⓑ. To define a function.
ⓒ. To declare a global variable.
ⓓ. To allocate memory dynamically.
Explanation: The `typedef` keyword is used to create new data type names (aliases) in C, enhancing code readability and making type definitions easier to manage.
27. Which feature of C provides error-handling capabilities?
ⓐ. Pointers
ⓑ. Macros
ⓒ. Setjmp and longjmp
ⓓ. Structures
Explanation: The `setjmp` and `longjmp` functions provide error-handling capabilities in C, allowing a program to jump back to a specific point if an error occurs.
28. Which feature of C allows the use of inline assembly code?
ⓐ. Macros
ⓑ. Pointers
ⓒ. Structures
ⓓ. Inline keyword
Explanation: The `inline` keyword allows the incorporation of assembly code within C programs, enabling low-level hardware manipulation and optimization.
29. What is the benefit of using enumerations (enums) in C?
ⓐ. They allow dynamic memory allocation.
ⓑ. They simplify the use of symbolic names for integer values.
ⓒ. They enable object-oriented programming.
ⓓ. They provide built-in functions for string manipulation.
Explanation: Enumerations (enums) simplify the use of symbolic names for integer values, improving code readability and reducing errors associated with magic numbers.
30. Which feature of C supports recursion in functions?
ⓐ. Static variables
ⓑ. Function pointers
ⓒ. Auto variables
ⓓ. Reentrant function calls
Explanation: Reentrant function calls support recursion in C, allowing a function to call itself either directly or indirectly to solve problems that can be broken down into similar sub-problems.
31. What is typically the first line in a C program?
ⓐ. `#include` directives
ⓑ. `int main()`
ⓒ. Variable declarations
ⓓ. Function definitions
Explanation: The `#include` directives are typically the first lines in a C program and are used to include standard or user-defined header files.
32. What is the purpose of the `#include` directive in a C program?
ⓐ. To define functions
ⓑ. To include standard or user-defined libraries
ⓒ. To declare variables
ⓓ. To start the main function
Explanation: The `#include` directive is used to include standard or user-defined header files that contain declarations and macro definitions to be shared between several source files.
33. What does the `main` function represent in a C program?
ⓐ. The program’s entry point
ⓑ. The function that handles input/output operations
ⓒ. The function that declares global variables
ⓓ. The program’s exit point
Explanation: The `main` function represents the entry point of a C program. Execution of a C program begins from the `main` function.
34. Which part of a C program is used for declaring global variables?
ⓐ. Inside the `main` function
ⓑ. Inside header files
ⓒ. Outside all functions
ⓓ. Inside any user-defined function
Explanation: Global variables are declared outside all functions, typically at the top of the program, so they can be accessed by any function within the program.
35. What is the purpose of the `return` statement in the `main` function?
ⓐ. To declare local variables
ⓑ. To terminate the program
ⓒ. To return a value to the calling process
ⓓ. To start another function
Explanation: The `return` statement in the `main` function is used to return a value to the calling process or operating system, indicating the status of program termination.
36. Which part of a C program typically contains function prototypes?
ⓐ. Before the `main` function
ⓑ. Inside the `main` function
ⓒ. After the `main` function
ⓓ. Inside any function
Explanation: Function prototypes are typically declared before the `main` function to inform the compiler about the functions’ return types and parameters.
37. Where are local variables declared in a C program?
ⓐ. Outside all functions
ⓑ. Inside the `main` function only
ⓒ. Inside any function
ⓓ. Inside header files
Explanation: Local variables are declared inside functions. They are only accessible within the function they are declared in.
38. What does the `#define` directive do in a C program?
ⓐ. It includes libraries
ⓑ. It defines symbolic constants and macros
ⓒ. It declares global variables
ⓓ. It starts the main function
Explanation: The `#define` directive is used to define symbolic constants and macros that are replaced by their values before compilation.
39. Which section of a C program contains executable statements?
ⓐ. Header files
ⓑ. Preprocessor directives
ⓒ. Function bodies
ⓓ. Global declarations
Explanation: The executable statements in a C program are contained within the bodies of functions, including the `main` function and any user-defined functions.
40. What is the correct order of sections in a C program?
ⓐ. Preprocessor directives, global declarations, `main` function, user-defined functions
ⓑ. `main` function, preprocessor directives, global declarations, user-defined functions
ⓒ. User-defined functions, `main` function, global declarations, preprocessor directives
ⓓ. Global declarations, preprocessor directives, `main` function, user-defined functions
Explanation: The typical structure of a C program is: preprocessor directives, global declarations, `main` function, and user-defined functions. This order ensures that all dependencies and declarations are handled before the main execution begins.
41. What is the first step in the compilation process of a C program?
ⓐ. Linking
ⓑ. Parsing
ⓒ. Preprocessing
ⓓ. Code generation
Explanation: The first step in the compilation process of a C program is preprocessing, which handles directives like `#include`, `#define`, and other macro expansions.
42. Which tool is used for compiling C programs?
ⓐ. Debugger
ⓑ. Compiler
ⓒ. Linker
ⓓ. Interpreter
Explanation: A compiler is used to convert the source code of a C program into machine code or object code that can be executed by the computer.
43. What is the role of the linker in the compilation process?
ⓐ. Convert source code to object code
ⓑ. Execute the program
ⓒ. Resolve external symbols and combine object files
ⓓ. Optimize the code
Explanation: The linker resolves external symbols and combines multiple object files into a single executable file.
44. What file extension is commonly used for the source code of a C program?
ⓐ. .exe
ⓑ. .obj
ⓒ. .c
ⓓ. .bin
Explanation: The source code of a C program is typically saved with the `.c` file extension.
45. During the preprocessing phase, which directive is responsible for including the content of one file into another?
ⓐ. #define
ⓑ. #include
ⓒ. #ifdef
ⓓ. #pragma
Explanation: The `#include` directive is used during preprocessing to include the content of one file into another, such as including standard library headers.
46. What is an object file in the context of C compilation?
ⓐ. The final executable program
ⓑ. A file containing machine code without linking
ⓒ. A file with human-readable source code
ⓓ. A library file
Explanation: An object file contains machine code generated by the compiler from the source code but is not yet linked into an executable.
47. Which command is used to compile a C program using the GCC compiler?
ⓐ. gcc program.c
ⓑ. g++ program.c
ⓒ. compile program.c
ⓓ. make program.c
Explanation: The `gcc program.c` command is used to compile a C program using the GCC (GNU Compiler Collection) compiler.
48. What is the purpose of the `-o` option in the GCC compilation command?
ⓐ. To optimize the code
ⓑ. To specify the output file name
ⓒ. To include debugging information
ⓓ. To compile without linking
Explanation: The `-o` option in the GCC compilation command specifies the name of the output file. For example, `gcc program.c -o program` compiles `program.c` and names the output executable `program`.
49. What happens during the linking phase of the compilation process?
ⓐ. Syntax errors are checked.
ⓑ. Source code is converted to assembly code.
ⓒ. Object files and libraries are combined to create an executable.
ⓓ. Code is executed.
Explanation: During the linking phase, object files and libraries are combined to create a single executable file, resolving any external references.
50. Which tool is commonly used to check for runtime errors and memory leaks in a C program?
ⓐ. Compiler
ⓑ. Debugger
ⓒ. Linker
ⓓ. Preprocessor
Explanation: A debugger is used to check for runtime errors and memory leaks in a C program, allowing developers to step through the code and inspect variables and memory usage.
51. What file extension is typically used for the executable file generated from a C program?
ⓐ. .c
ⓑ. .o
ⓒ. .exe
ⓓ. .lib
Explanation: The executable file generated from a C program typically has the `.exe` extension, especially on Windows systems.
52. Which stage of the compilation process translates source code into assembly language?
ⓐ. Preprocessing
ⓑ. Compilation
ⓒ. Linking
ⓓ. Execution
Explanation: During the compilation stage, the source code is translated into assembly language, which is then converted into machine code.
53. What is the main purpose of the `-g` option when compiling a C program with GCC?
ⓐ. To enable optimizations
ⓑ. To generate debugging information
ⓒ. To link libraries
ⓓ. To include header files
Explanation: The `-g` option in GCC includes debugging information in the compiled executable, which is useful for debugging with tools like gdb.
54. Which of the following commands is used to run the executable file of a C program in a Unix-like environment?
ⓐ. execute filename
ⓑ. gcc filename.c
ⓒ. ./filename
ⓓ. run filename
Explanation: The `./filename` command is used to run the executable file in a Unix-like environment. This specifies the current directory as the location of the executable.
55. What does the `-Wall` option do when used with the GCC compiler?
ⓐ. Disables all warnings
ⓑ. Enables all compiler warnings
ⓒ. Optimizes the code
ⓓ. Generates an object file
Explanation: The `-Wall` option enables all the commonly used compiler warnings, helping developers catch potential issues in the code.
56. Which tool is typically used to check for syntax errors in a C program before it is compiled?
ⓐ. Compiler
ⓑ. Linker
ⓒ. Preprocessor
ⓓ. Linter
Explanation: A linter is a tool used to analyze source code for potential errors, including syntax errors, before compilation.
57. What is the function of the `make` utility in the context of C programming?
ⓐ. Compiling individual source files
ⓑ. Automating the build process
ⓒ. Running executable files
ⓓ. Debugging the program
Explanation: The `make` utility automates the build process by using a Makefile to manage dependencies and compile source files efficiently.
58. What is the role of a Makefile in C programming?
ⓐ. It includes standard libraries.
ⓑ. It specifies how to compile and link the program.
ⓒ. It contains the main function.
ⓓ. It defines global variables.
Explanation: A Makefile contains rules and dependencies that specify how to compile and link a C program, allowing for efficient management of the build process.
59. What command is used to create an object file from a C source file using GCC?
ⓐ. gcc -c filename.c
ⓑ. gcc -o filename.o
ⓒ. gcc -g filename.c
ⓓ. gcc filename.c
Explanation: The `gcc -c filename.c` command compiles the C source file into an object file without linking, resulting in a `.o` file.
60. Which phase of the compilation process detects syntax and semantic errors in the C source code?
ⓐ. Preprocessing
ⓑ. Compilation
ⓒ. Linking
ⓓ. Execution
Explanation: The compilation phase detects syntax and semantic errors in the C source code, ensuring the code adheres to the language’s rules before generating machine code.
61. What is the correct syntax to include the standard input-output header file in a C program?
ⓐ. `#include `
ⓑ. `#include `
ⓒ. `#include `
ⓓ. `#include `
Explanation: The correct syntax to include the standard input-output header file is `#include `, which provides functionalities for input and output operations.
62. What is the purpose of the `printf` function in a C program?
ⓐ. To read input from the user
ⓑ. To print output to the console
ⓒ. To allocate memory dynamically
ⓓ. To define a function
Explanation: The `printf` function is used to print formatted output to the console in a C program.
63. Which function is used to read input from the user in a C program?
ⓐ. scanf
ⓑ. printf
ⓒ. input
ⓓ. gets
Explanation: The `scanf` function is used to read formatted input from the user in a C program.
64. What is the correct syntax to start the main function in a C program?
ⓐ. `void main()`
ⓑ. `int main()`
ⓒ. `main()`
ⓓ. `start main()`
Explanation: The correct syntax to start the main function in a C program is `int main()`, which indicates that the function returns an integer value.
65. Which statement is used to indicate the end of a C program and return control to the operating system?
ⓐ. `stop`
ⓑ. `end`
ⓒ. `exit()`
ⓓ. `return 0;`
Explanation: The statement `return 0;` is used to indicate the successful end of a C program and return control to the operating system.
66. Where should the `#include` directives be placed in a C program?
ⓐ. Inside the `main` function
ⓑ. After the `main` function
ⓒ. Before the `main` function
ⓓ. Anywhere in the program
Explanation: The `#include` directives should be placed before the `main` function to ensure the necessary libraries are included before the program execution starts.
67. What is the correct way to write a comment in a C program?
ⓐ. `/* This is a comment */`
ⓑ. `// This is a comment`
ⓒ. ``
ⓓ. `# This is a comment`
Explanation: The correct way to write a multi-line comment in C is `/* This is a comment */`. For single-line comments, `// This is a comment` can also be used.
68. Which of the following is a valid variable declaration in C?
ⓐ. `int number;`
ⓑ. `integer number;`
ⓒ. `num = int;`
ⓓ. `number int;`
Explanation: The correct syntax for declaring an integer variable in C is `int number;`.
69. How do you compile a C program named `hello.c` using the GCC compiler?
ⓐ. `gcc -compile hello.c`
ⓑ. `gcc hello.c`
ⓒ. `compile hello.c`
ⓓ. `gcc -run hello.c`
Explanation: To compile a C program named `hello.c` using the GCC compiler, you use the command `gcc hello.c`.
70. What command is used to run the executable file named `a.out` in a Unix-like environment?
ⓐ. `run a.out`
ⓑ. `execute a.out`
ⓒ. `./a.out`
ⓓ. `gcc a.out`
Explanation: To run the executable file named `a.out` in a Unix-like environment, you use the command `./a.out`.
71. What is the output of the following C code?
int main() {
printf("Hello, World!");
return 0;
}
ⓐ. Hello, World!
ⓑ. hello, world!
ⓒ. Hello, World!
ⓓ. Error
Explanation: The code prints “Hello, World!” to the console and then returns 0 to indicate successful execution.
72. Which library function would you use to read a string from the user in a C program?
ⓐ. printf
ⓑ. scanf
ⓒ. gets
ⓓ. getchar
Explanation: The `gets` function can be used to read a string from the user in a C program. However, it’s generally advised to use `fgets` instead for safety reasons.
73. What is the correct way to declare and initialize an integer variable in C?
ⓐ. `int num;`
ⓑ. `int num = 10;`
ⓒ. `num int = 10;`
ⓓ. `integer num = 10;`
Explanation: The correct way to declare and initialize an integer variable in C is `int num = 10;`.
74. How do you add a single-line comment in C?
ⓐ. `// This is a comment`
ⓑ. `/* This is a comment */`
ⓒ. ``
ⓓ. `# This is a comment`
Explanation: A single-line comment in C is added using `// This is a comment`.
75. What will be the output of the following C code?
int main() {
int a = 5;
int b = 10;
printf("%d", a + b);
return 0;
}
ⓐ. 510
ⓑ. 15
ⓒ. 5 10
ⓓ. Error
Explanation: The code prints the sum of `a` and `b`, which is 15.
76. What is the purpose of the `int` keyword in the `main` function?
ⓐ. To specify that `main` returns an integer value
ⓑ. To declare a global variable
ⓒ. To start the program execution
ⓓ. To include standard libraries
Explanation: The `int` keyword indicates that the `main` function returns an integer value to the operating system.
77. How do you compile and create an executable named `program` from a C source file `program.c` using GCC?
ⓐ. `gcc -o program program.c`
ⓑ. `gcc program.c -output program`
ⓒ. `gcc program.c -name program`
ⓓ. `gcc compile program.c -o program`
Explanation: The `gcc -o program program.c` command compiles the C source file `program.c` and creates an executable named `program`.
78. What is the output of the following C code?
int main() {
printf("%d", 2 * 3 + 5);
return 0;
}
ⓐ. 11
ⓑ. 16
ⓒ. 10
ⓓ. 13
Explanation: The code evaluates the expression `2 * 3 + 5`, which results in 11, and prints it to the console.
79. Which function is used to output a single character to the console in C?
ⓐ. printf
ⓑ. putchar
ⓒ. puts
ⓓ. scanf
Explanation: The `putchar` function is used to output a single character to the console in C.
80. What will be the output of the following C code?
int main() {
int num = 10;
printf("The number is %d", num);
return 0;
}
ⓐ. The number is 10
ⓑ. The number is %d
ⓒ. 10
ⓓ. num = 10
Explanation: The code prints the value of `num` using the `%d` format specifier, resulting in “The number is 10”.