Ch1 Systems Programming and C Basics II Flashcards
What is the purpose of the main()
function in a C program?
The main()
function is the entry point of a C program. Execution of the program starts and ends here.
What is the difference between printf()
and scanf()
format specifiers %d
and %f
?
-
%d
is used for integers. -
%f
is used for floating-point numbers.
What is the purpose of the \n
character in a printf()
statement?
The \n
character is used to insert a newline, moving the cursor to the beginning of the next line.
What is the purpose of the #include <math.h>
directive in a C program?
The #include <math.h>
directive includes the math library, which provides functions like sin()
, cos()
, pow()
, and sqrt()
.
What is the difference between float
and double
in C?
-
float
is a single-precision floating-point number (typically 4 bytes). -
double
is a double-precision floating-point number (typically 8 bytes).
What is the purpose of the sizeof
operator in C?
The sizeof
operator returns the size, in bytes, of a variable or data type.
What is the difference between int
and unsigned int
in C?
-
int
can represent both positive and negative numbers. -
unsigned int
can only represent non-negative numbers (zero and positive).
What is the purpose of the if
statement in C?
The if
statement is used to execute a block of code only if a specified condition is true.
What is the purpose of the else
statement in C?
The else
statement is used to execute a block of code if the condition in the if
statement is false.
What is the purpose of the switch
statement in C?
The switch
statement is used to execute one of many code blocks based on the value of a variable or expression.
What is the purpose of the for
loop in C?
The for
loop is used to repeatedly execute a block of code a specific number of times.
What is the purpose of the while
loop in C?
The while
loop is used to repeatedly execute a block of code as long as a specified condition is true.
What is the purpose of the do-while
loop in C?
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.
What is the purpose of the break
statement in a switch
statement?
The break
statement is used to exit the switch
statement, preventing fall-through to the next case.
What is the purpose of the continue
statement in a loop?
The continue
statement skips the rest of the current iteration and proceeds to the next iteration of the loop.
What is the purpose of the return
statement in a function?
The return
statement is used to exit a function and optionally return a value to the caller.
What is the purpose of the void
keyword in a function declaration?
The void
keyword indicates that the function does not return a value.
What is the purpose of the static
keyword in C?
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.
What is the purpose of the const
keyword in C?
The const
keyword is used to declare a variable as read-only, meaning its value cannot be changed after initialization.
What is the purpose of the typedef
keyword in C?
The typedef
keyword is used to create an alias for a data type, making it easier to use and understand.