Lecture 1 - Introduction Flashcards
What are the key differences between C and Java?
Java is designed for portability, C for systems programming.
Java hides hardware differences using JVM, while C exposes hardware differences.
Java is object-oriented; C is procedural.
Java handles memory with garbage collection; in C, the programmer manages memory.
Java has strong type checking; C offers more flexibility but requires manual error management.
What is the purpose of the #include <stdio.h>
directive in C?
It includes the header file that contains the declaration of the standard input/output functions such as printf
.
What are preprocessor directives in C?
Preprocessor directives (like #include
, #define
) provide instructions to the preprocessor before compilation, such as including files, defining macros, and conditional compilation.
What does the main()
function do in a C program?
The main()
function is the entry point of a C program, where the execution starts. It usually returns an integer to indicate the program’s success or failure (e.g., EXIT_SUCCESS
or EXIT_FAILURE
).
What is the basic structure of a C program?
Preprocessor directivesmain()
function definition
Variable declarations
Statements and function calls
Return statement
What is the difference between EXIT_SUCCESS
and EXIT_FAILURE
?
EXIT_SUCCESS
indicates that the program executed successfully.EXIT_FAILURE
indicates that the program encountered an error.
What are the stages of the C compilation process?
Preprocessing: Handles directives like #include
and #define
.
Compilation: Converts source code into object code.
Linking: Combines object code with libraries to produce the executable.
What are formatted I/O functions in C?
Formatted I/O functions include printf
for output and scanf
for input, which allow formatted text display and input reading.
What is the canonical first C program?
The canonical first C program is the “Hello World!” program:
#include <stdio.h> int main() { printf("Hello World!\n"); return EXIT_SUCCESS; }
What are the main components of a C program’s memory model?
Text Segment: Contains the compiled code.
Data Segment: Contains global/static variables initialized by the programmer.
Heap: Used for dynamic memory allocation.
Stack: Used for local variables and function calls.
What is the purpose of #define
in C?
It defines macros, allowing you to create constants or shorthand notations for code that will be replaced by the preprocessor before compilation.
What are the benefits of using C for systems programming?
C provides low-level access to memory, efficient execution, and flexibility, making it ideal for systems programming like writing operating systems and embedded software.