WorksheetsLesson 2 Quiz
Total questions: 34
Worksheet time: 3hrs 50mins
Which of the following is NOT a characteristic of the C programming language?
High-level language
Platform-independent
Primarily used for web development
Case-sensitive
Which characteristic of C programming allows it to run on various hardware platforms with minimal modification?
Portability
Power
Flexibility
Efficiency
C's 'power' as a programming language is often attributed to its ability to:
Directly manipulate hardware and memory addresses.
Support object-oriented programming paradigms natively.
Automatically manage memory allocation and deallocation.
Generate interactive graphical user interfaces with ease.
The 'efficiency' of C programs is largely due to which of the following?
Its extensive use of dynamic linking at runtime.
Its compilation directly into machine code and low-level memory access.
The automatic parallelization of code by the compiler.
Its built-in garbage collection mechanism.
Which aspect of C programming contributes most to its 'flexibility' for a wide range of applications?
Its procedural nature and support for low-level system programming.
The availability of numerous third-party frameworks for web development.
Its strict type-checking rules.
The automatic generation of documentation from source code.
The 'standard library' in C primarily provides:
Tools for automated code testing and debugging.
Graphical user interface (GUI) components and tools.
A collection of pre-written functions for common tasks like input/output and string manipulation.
Object-oriented programming constructs and classes.
Which of the following best describes why C programs are often considered 'error-prone'?
The strict syntax rules that limit programmer flexibility.
Its automatic garbage collection system that can introduce subtle bugs.
Its lack of direct memory access and pointer manipulation.
Its low-level features, like manual memory management and pointer arithmetic, can easily lead to bugs if not handled carefully.
What makes C programs 'difficult to understand', especially for larger projects?
The automatic parallelization of code by the compiler.
The extensive use of high-level abstractions and object-oriented design patterns.
The common use of pointers, manual memory management, and less expressive syntax compared to modern languages.
Its reliance on graphical user interfaces for program logic.
What is the primary purpose of #include
To specify the program's operating system.
To add comments to the code.
To allow the program to use input/output functions like printf().
To define the main function.
Which function is the entry point for every C program?
run()
start()
execute()
main()
What does printf() do in a C program?
Reads input from the keyboard.
Creates new files on the system.
Prints output to the console.
Performs mathematical calculations.
What is the significance of return 0; at the end of the main() function?
It signals that the program executed successfully.
It restarts the program from the beginning.
It clears the screen.
It allocates memory for variables.
Which symbol is used to mark the end of a statement in C?
; (semicolon)
. (period)
, (comma)
: (colon)
What are { and } used for in C programming?
To indicate the beginning and end of a code block or function body.
To define variables.
To perform arithmetic operations.
To enclose strings.
What happens if #include
The program will run normally, as it's a minor typo.
The compiler will issue an error because studio.h does not exist.
The program will automatically fix the typo during compilation.
The program will compile but printf() will not work.
Which of the following is a correct way to declare the main function?
int main()
void main;
main {}
int main []
What is the purpose of the compiler in C programming?
To manage the program's memory during runtime.
To run the program directly without translation.
To display output on the screen.
To translate source code written in C into machine-executable code.
If you forget the semicolon at the end of a printf() statement, what will typically happen?
The compiler will report a syntax error, preventing the program from compiling.
The program will run but produce no output.
The program will compile but crash at runtime.
The compiler will ignore the error and compile the code anyway.
In a C program, what does the main() function represent structurally?
The declaration of a global variable.
A built-in data type.
The entry point and primary execution block of the program.
A preprocessor instruction.
Which of these best describes a 'library function' in C?
A function that is only used for debugging purposes.
A function defined by the programmer for specific tasks within their program.
A function that allocates memory dynamically.
A pre-written function provided by the C standard library for common operations.
Which of the following is an example of a preprocessor directive in C?
#define PI 3.14
int main()
return 0;
printf("Hello");
What is the primary structural difference between a 'user-defined function' and a 'library function'?
User-defined functions are always called from main(), while library functions are not.
Library functions can return values, but user-defined functions cannot.
User-defined functions don't require semicolons, while library functions do.
User-defined functions are written by the programmer, while library functions are pre-written and provided with the compiler.
Which of the following correctly describes a 'statement' in C programming?
A block of code enclosed in curly braces {}.
A keyword that begins with #.
The name given to a variable.
A complete instruction that performs some action, usually ending with a semicolon.
What is the primary reason the main() function in C is typically declared with an int return type (e.g., int main())?
It ensures that the program can only perform integer-based calculations.
It is a requirement for memory allocation by the operating system.
It signifies that the main() function can only accept integer arguments.
It allows the program to return an integer status code to the operating system upon completion.
What is the widely accepted convention for the int value returned by the main() function in a C program, and what does 0 specifically signify?
0 means a critical error occurred, and the program terminated abnormally.
0 indicates that the program executed successfully without any errors.
The return value of main() is only used for internal compiler checks and has no external significance.
Any integer value can be returned; 0 simply means the program has finished.
In a well-structured C program, where is the statement return 0; most commonly and importantly found?
Immediately after an #include preprocessor directive.
At the end of every user-defined function that has an int return type.
Inside the printf() function's parameters.
As the final statement within the main() function.
What is the primary role of a semicolon (;) at the end of a statement in C?
What is the primary role of a semicolon (;) at the end of a statement in C?
It marks the beginning of a new code block.
It separates variables in a declaration.
It acts as a statement terminator, indicating the end of an instruction.
It indicates a comment to the compiler.
If a semicolon is accidentally omitted at the end of a printf() statement, what is the most likely outcome when compiling the C program?
The compiler will report a syntax error, preventing successful compilation.
A runtime error will occur when the program is executed.
The program will run but produce incorrect output.
The compiler will automatically insert the missing semicolon.
Which statement about this code's compilation is TRUE?
The int x = 10; line will be commented out due to a multi-line comment spanning two lines.
The code will compile successfully because comment syntax is correctly applied for both types.
The code will produce a compilation error because the single-line comment on the second line incorrectly tries to start a multi-line comment.
The code will produce a compilation error because of nested comments in the first line.
What is the output of the following C code snippet?
Hello C Programming
Hello Goodbye C Programming
Hello /* World */ C Programming
Hello / World */ Goodbye Farewell C Programming
What is the primary reason why the string literal "Hello\nWorld" will print 'Hello' on one line and 'World' on the next, but "Hello\\nWorld" will print 'Hello\nWorld' all on one line?
The first uses a single newline character, while the second has a syntax error.
In "Hello\nWorld", \n is interpreted as a newline character, whereas in "Hello\\nWorld", \\ escapes the backslash itself, making \n a literal sequence of two characters.
The first string uses a char type, and the second uses a string type.
The compiler automatically optimizes the second string to avoid printing a newline.
Which statement accurately describes the likely outcome when trying to compile and run these snippets as standalone C programs?
Both snippets will compile and run successfully.
Snippet A will compile and run, but Snippet B will produce a compilation error.
Snippet A will produce a compilation error, while Snippet B will compile and run successfully.
Both snippets will compile but neither will run due to missing entry point.
What is the primary significance of curly braces {} in C programming, specifically in the context of if statements or function bodies, that might confuse a beginner?
They are exclusively used for comments and are ignored by the compiler.
They always define a mandatory block of code that must execute.
They group multiple statements into a single, compound statement, dictating execution flow and variable scope.
They act as optional visual aids for code readability but are not essential for execution.
