Ch1 Systems Programming and C Basics II Flashcards

1
Q

What is the purpose of the main() function in a C program?

A

The main() function is the entry point of a C program. Execution of the program starts and ends here.

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

What is the difference between printf() and scanf() format specifiers %d and %f?

A
  • %d is used for integers.
  • %f is used for floating-point numbers.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the purpose of the \n character in a printf() statement?

A

The \n character is used to insert a newline, moving the cursor to the beginning of the next line.

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

What is the purpose of the #include <math.h> directive in a C program?

A

The #include <math.h> directive includes the math library, which provides functions like sin(), cos(), pow(), and sqrt().

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

What is the difference between float and double in C?

A
  • float is a single-precision floating-point number (typically 4 bytes).
  • double is a double-precision floating-point number (typically 8 bytes).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the purpose of the sizeof operator in C?

A

The sizeof operator returns the size, in bytes, of a variable or data type.

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

What is the difference between int and unsigned int in C?

A
  • int can represent both positive and negative numbers.
  • unsigned int can only represent non-negative numbers (zero and positive).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the purpose of the if statement in C?

A

The if statement is used to execute a block of code only if a specified condition is true.

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

What is the purpose of the else statement in C?

A

The else statement is used to execute a block of code if the condition in the if statement is false.

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

What is the purpose of the switch statement in C?

A

The switch statement is used to execute one of many code blocks based on the value of a variable or expression.

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

What is the purpose of the for loop in C?

A

The for loop is used to repeatedly execute a block of code a specific number of times.

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

What is the purpose of the while loop in C?

A

The while loop is used to repeatedly execute a block of code as long as a specified condition is true.

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

What is the purpose of the do-while loop in C?

A

The do-while loop is used to repeatedly execute a block of code at least once, and then continue as long as a specified condition is true.

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

What is the purpose of the break statement in a switch statement?

A

The break statement is used to exit the switch statement, preventing fall-through to the next case.

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

What is the purpose of the continue statement in a loop?

A

The continue statement skips the rest of the current iteration and proceeds to the next iteration of the loop.

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

What is the purpose of the return statement in a function?

A

The return statement is used to exit a function and optionally return a value to the caller.

17
Q

What is the purpose of the void keyword in a function declaration?

A

The void keyword indicates that the function does not return a value.

18
Q

What is the purpose of the static keyword in C?

A

The static keyword can be used to:
- Limit the scope of a variable or function to the file in which it is declared.
- Preserve the value of a local variable between function calls.

19
Q

What is the purpose of the const keyword in C?

A

The const keyword is used to declare a variable as read-only, meaning its value cannot be changed after initialization.

20
Q

What is the purpose of the typedef keyword in C?

A

The typedef keyword is used to create an alias for a data type, making it easier to use and understand.