Basics of C Flashcards

(26 cards)

1
Q

List the phases of the C program life cycle.

A

Editing, Preprocessing, Compilation, Assembly, Linking, Loading, Execution, Termination

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

Describe the basic structure of a C program, including the main function syntax.

A

A C program typically includes Preprocessor Directives (header files), global declarations (optional), the main() function (entry point), and function definitions. The main function has the syntax int main() { … return 0; }.

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

What are the typical size and data range for the int primitive data type?

A

Typically 4 bytes. The data range is approximately −2^31 to 2^31−1.

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

How do you safely read a string (including spaces) from standard input into a character array name of size 50?

A

fgets(name, 50, stdin);

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

Explain the purpose and syntax of the increment (++) and decrement (–) operators.

A

They are unary operators used to increase or decrease the value of a variable by one.
Prefix: ++x (increments then uses value), –x (decrements then uses value).
Postfix: x++ (uses value then increments), x– (uses value then decrements).

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

What is the syntax for the ternary (conditional) operator, and how does it work?

A

condition ? expression_if_true : expression_if_false;. If the condition is true, expression_if_true is evaluated; otherwise, expression_if_false is evaluated.

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

When and how is explicit type casting used in C?

A

(dataType) expression;

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

Name the four primitive data types in C and their format specifiers for printf/scanf.

A

char (%c), int (%d), float (%f), double (%lf).

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

Size of float, double, Short Integer, Long integer

A

Float : 4 bytes , double : 8 bytes , Short Integer : 16 , Long Integer : 32

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

What are the rules for C identifiers?

A

Must start with an alphabet or underscore. Can contain alphabets, digits, and underscores. Cannot be a C keyword. Case-sensitive.

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

What is the difference between a Variable and a Constant in C?

A

Variable: Named storage location whose value can change during execution.

Constant: Named storage location whose value cannot be changed after initialization (declared with const or #define).

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

Explain the difference between printf() and puts().

A

printf(): Prints formatted output, requires format specifiers, and does not automatically add a newline.
puts(): Prints a string and automatically adds a newline character at the end.

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

Explain the difference between scanf() and gets().

A

scanf() ignores newline but gets() considers it

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

Life Cycle - Editing

A
  1. You write your program in a text editor (e.g., VSCode), saved as program.c
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Preprocessing

A
  1. Handles lines starting with # like #include, #define. This expands code.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Expanded Source Code

A
  1. Now your code has library content and macros expanded (not seen by you)
17
Q

Compilation

A
  1. Compiler checks syntax and converts expanded code to assembly instructions
18
Q

Assembly

A
  1. Assembly code is converted to machine code (Object Code / .o)
19
Q

Assembler

A
  1. Translates assembly into actual object file
20
Q

Object Code

A
  1. Intermediate .o or .obj file – not runnable yet
21
Q

Linking

A
  1. Combines object code with standard library code (printf, scanf, etc.)
22
Q

Executable Code

A
  1. Final .exe file is created (platform-dependent)
23
Q

Final .exe file is created (platform-dependent)

A
  1. Program is loaded into RAM by OS
24
Q

Execution

A
  1. CPU starts executing the instructions
25
Termination
12. Program ends, memory is freed, control returns to OS
26
THE SPICY DRAMA MNEMONIC 2.0
Ed ne Priya se uske Expenses pooche... Toh Complaint karne lagi, 'Aaj Aapne Objection kardi!' Ab Love toh Execute hi nahi hoga... Love Ek Tarfa hai bro 💔