Lecture 1 - Introduction Flashcards

1
Q

What are the key differences between C and Java?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the purpose of the #include <stdio.h> directive in C?

A

It includes the header file that contains the declaration of the standard input/output functions such as printf.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are preprocessor directives in C?

A

Preprocessor directives (like #include, #define) provide instructions to the preprocessor before compilation, such as including files, defining macros, and conditional compilation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the main() function do in a C program?

A

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).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the basic structure of a C program?

A

Preprocessor directives
main() function definition
Variable declarations
Statements and function calls
Return statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the difference between EXIT_SUCCESS and EXIT_FAILURE?

A

EXIT_SUCCESS indicates that the program executed successfully.
EXIT_FAILURE indicates that the program encountered an error.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the stages of the C compilation process?

A

Preprocessing: Handles directives like #include and #define.
Compilation: Converts source code into object code.
Linking: Combines object code with libraries to produce the executable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are formatted I/O functions in C?

A

Formatted I/O functions include printf for output and scanf for input, which allow formatted text display and input reading.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the canonical first C program?

A

The canonical first C program is the “Hello World!” program:

#include <stdio.h>

int main() {
    printf("Hello World!\n");
    return EXIT_SUCCESS;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the main components of a C program’s memory model?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the purpose of #define in C?

A

It defines macros, allowing you to create constants or shorthand notations for code that will be replaced by the preprocessor before compilation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the benefits of using C for systems programming?

A

C provides low-level access to memory, efficient execution, and flexibility, making it ideal for systems programming like writing operating systems and embedded software.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly