Chapter 2 Questions Flashcards

1
Q

What is the meaning of the #include statement?

A

it tells the compiler what libraries need to be linked

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

What is the difference in a library (.h) that is between <> verses between “”?

A

<> is a prewritten library
“” is a user defined library

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

What is the library stdio.h for?

A

contains standard input and output functions such as scanf and printf

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

What is the library math.h for?

A

contains mathematical functions such as sqrt and pow

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

What are the four (4) valid options to define the main() function in C?

A

main(){…}
void main(){…}
int main(){… return 0;}
main(int argc, char *argv[]){…}

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

When you have a main() function defined with a type int, what does the statement “return 0;” mean?

A

the program ran as expected/ no errors or exceptions

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

In the statement “scanf(%d, &i)”, why do we use “&” in the second parameter?

A

to store the scanned value at the address?

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

What is the purpose of the %d, %f, %c, %s, and %p in the printf() function?

A

they are

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

What are the two (2) types of variables, scope-wise, that we have in C?

A

local and global

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

If C does not have boolean type variables, how are relational operations (needed in conditions and loops) handled?

A

if it returns a 0 it is false, if it returns any other number it is true

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

How many basic data types are there in C?

A

5 (int, double, float, char, void)

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

How is the scope of a variable defined in C?

A

it starts at the declaration and goes until the end of the block defined by {}

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

When declaring a variable/function in C, what does the rule “declaration-before-use” mean?

A

you cannot use a variable ahead of where it is declared (scope)

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

What is a forward declaration and why do we want to use it?

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

What are long, short, signed, and unsigned?

A

modifiers

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

What is the initial default value of an integer variable when it is defined as int x?

A
17
Q

What is the initial default value of an character variable when it is defined as char a?

A
18
Q

What is the initial default value of an float variable when it is defined as float x?

A
19
Q

C does not have a byte data type, is there an equivalent type for it?

A

yes, char

20
Q

What is the issue with trying to define an array as int a[] or char []?

A

the length of the array isn’t given so memory cannot be allocated?

21
Q

What is the function of the null character (‘\0’) when working with strings in C?

A

it represents the end of the string

22
Q

While working with strings in C, if we have char s1[3], s2[]; can we do s1 = s2? Yes or no and why?

A
23
Q

How would you describe a pointer in terms of what is stored in them?

A

a pointer stores an address

24
Q

How would you describe a pointer in terms of the type of memory they use?

A
25
Q

Is it possible to have pointers to any type in C?

A

yes

26
Q

What is the result of combining these two operands?

(&y)
&(
y)

A
27
Q

There are two operators for pointers, * and &. What is the purpose of each of them?

A
  • returns the value stored in the variable to which the attached variable points to
    & returns the address of the variable to which it is attached
28
Q

Why is it said that an array can be seen as a pointer? Justify in terms of the information stored in the pointer and array.

A
29
Q

In C, there is no string type, however, there are ways to implement strings? What are they?

A

an array of char

30
Q

While defining a pointer to a character and initializing it with a string literal, it is said that the string is immutable. What does that mean and would the pointer also be immutable?

char *str = “Hello World”;

A

when a string is immutable, it cannot be changed during runtime, with the exception of using pointers

no the pointer would be mutable in this example

31
Q

Given the following definition of an array, give the same array using pointers.

int array[] = {1, 2, 3, 4, 5};

Provide a visual representation of the above array and pointers.

A

*(array + 0) = 1;
*(array + 1) = 2;
*(array + 2) = 3;
*(array + 3) = 4;
*(array + 4) = 5;