Week 7: Function Calls in C, Variables (Scope) in C, Program Organization, and Header Files Flashcards

1
Q

The “STACK” is what?

A

The stack is the memory set aside as scratch space for a thread of execution. Reserved for each function call

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

When calling a function, each parameter must…

A

Reduce down to a single value

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

What is the difference between pass-by-reference and pass-by-value?

A

pass-by-reference means passing a variable by its location in memory, which allows a variable to be changed by a function

pass-by-value means literally passing he value stored in the variable with no way of changing the variable stored in main memory

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

When accessing an array, using the name of the array is essentially….

A

Using the location in memory of the first item in the array

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

dbray &(dbray[0]) both mean…

A

The address of the first element of the array

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

Arrays are actually…

A

Pointers

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

double *ptr = &(array[0]);

is the same as….

A

double *ptr = array;

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

The main difference between malloc and calloc is…

A

Malloc sets aside a certain number of bytes:
double *a;
a = ( double *) malloc (40);

Calloc sets aside a certain number of that type
double *a;
a = (double *) calloc ( 70, sizeof(double) );

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

Static memory is ____ at the end of each use.

Dynamic memory is ______ at the end of each use unless ____

A

Static memory is deallocated at the end of each use.

Dynamic memory is not deallocated at the end of each use unless freed

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

How do you free the following dynamic memory?

double *a;
a = ( double *) malloc (40);

A

free(a)

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

Two ways of causing a memory leak are….

A

Not freeing the memory with free()

Reassigning the pointer variable to another place in dynamic memory before freeing it with free()

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

What lines of code are required to set aside 70 double variables? Using malloc? Calloc? Calloc another way?

A

double *a;

a = (double)malloc(708);

or

a = (double)malloc(70(sizeof(double)));

or

a = (double)malloc(708);

or

a = (double *) calloc ( 70, sizeof(double) );

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

What does a function prototype do?

A

Tell the preprocessor what to expect as a return type

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

What is the format of a function protoytype?

A

float division(int , int , int* , int*);

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

Function prototypes MUST

A

End with a semicolon

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

To avoid including header files more than once…

A

endif // PROG1_H_INCLUDE

use the following format:

#ifndef PROG1_H_INCLUDED
     #define PROG1_H_INCLUDED
 #define NUMB int

 float rT;

 float division(int , int , int* , int*);
17
Q

What are the two categories of variable types in C?

A

Compile-time (allocated) variables
(The life time of these kinds of variables is the whole execution period of the C program)

Run-time variables
(The memory space used for these kinds of variables are allocated (reserved) during the
execution (running) of the program)

18
Q

What are the compile-time (allocated) variables in C?

A

Global variables — accessible everywhere

Static global variables — accessible within the same C program file

Static local variables — accessible within the same C function

19
Q

What are the run-time variables in C?

A

Local variables — accessible only in the block they are declared in

Parameter variables — accessible within the called function

20
Q

What is a parameter variable?

A

A variable accessible within the called function

21
Q

What is a local variable?

A

A variable accessible only in the block they are declared in

22
Q

What is a global variable?

A

A variable accessible everywhere

23
Q

What is a static global variable?

A

A variable accessible within the same C program file

24
Q

What is a static local variable?

A

A variable accessible within the same C function