Chapter 2 Questions Flashcards
(31 cards)
What is the meaning of the #include statement?
it tells the compiler what libraries need to be linked
What is the difference in a library (.h) that is between <> verses between “”?
<> is a prewritten library
“” is a user defined library
What is the library stdio.h for?
contains standard input and output functions such as scanf and printf
What is the library math.h for?
contains mathematical functions such as sqrt and pow
What are the four (4) valid options to define the main() function in C?
main(){…}
void main(){…}
int main(){… return 0;}
main(int argc, char *argv[]){…}
When you have a main() function defined with a type int, what does the statement “return 0;” mean?
the program ran as expected/ no errors or exceptions
In the statement “scanf(%d, &i)”, why do we use “&” in the second parameter?
to store the scanned value at the address?
What is the purpose of the %d, %f, %c, %s, and %p in the printf() function?
they are
What are the two (2) types of variables, scope-wise, that we have in C?
local and global
If C does not have boolean type variables, how are relational operations (needed in conditions and loops) handled?
if it returns a 0 it is false, if it returns any other number it is true
How many basic data types are there in C?
5 (int, double, float, char, void)
How is the scope of a variable defined in C?
it starts at the declaration and goes until the end of the block defined by {}
When declaring a variable/function in C, what does the rule “declaration-before-use” mean?
you cannot use a variable ahead of where it is declared (scope)
What is a forward declaration and why do we want to use it?
What are long, short, signed, and unsigned?
modifiers
What is the initial default value of an integer variable when it is defined as int x?
What is the initial default value of an character variable when it is defined as char a?
What is the initial default value of an float variable when it is defined as float x?
C does not have a byte data type, is there an equivalent type for it?
yes, char
What is the issue with trying to define an array as int a[] or char []?
the length of the array isn’t given so memory cannot be allocated?
What is the function of the null character (‘\0’) when working with strings in C?
it represents the end of the string
While working with strings in C, if we have char s1[3], s2[]; can we do s1 = s2? Yes or no and why?
How would you describe a pointer in terms of what is stored in them?
a pointer stores an address
How would you describe a pointer in terms of the type of memory they use?