Week 9 Flashcards

1
Q

There are two main ways the compile views a 2d array, how do they differ?

A

int a[][] is a cube

int **b is an array with each array item pointing to another array

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

How many malloc calls do we require to create a 2D array?

A

Two mallocs

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

How do you interpret the declaration int ***a?

A

A 3D array

A pass-by-reference of a 2D array

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

Given int **a: What data type if a?

A

A is a 2D array or a pass-by-reference of a 1D array

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

Given int **a: What is *a?

A

A pointer to an integer

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

Given int **a: What is **a?

A

**a is an integer value

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

What are the three modes of interacting with files?

A

Read the contents of a file

Write to a new file

Append to an existing file

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

Writing and appending operate in a similar manner. What is the main difference?

A

Where the writing happens.

Write -> start writing at the first byte of the file

Appending -> start writing after the last byte of the file

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

If the file doesn’t exist when its called, what happens?

A

The open call fails

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

What are the four buffers to your program?

A

Keyboard input

Screen output

disc drive output

network output

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

Emptying a buffer: What is the input buffer?

A

Reading the data

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

Emptying a buffer: What is the output buffer?

A

Filling the buffer
Printing \n (for the screen only)
Closing the file
Explicitly pushing the data to the file

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

What is “flushing” the buffer?

A

Explicitly pushing the data to the file

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

How are files accessed?

A

Through a file descriptor

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

The file descriptor keeps track of all the important file information. What is it?

A

Where does the file live?
Where am in the file?
What operations are available on the file?
What permissions do I have for the file?

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

Where do stdin, stdout and stderr exist?

A

In the open file table

17
Q

FILE *fopen(char *file_path, char *mode) opens a file. What are the options for mode?

A

r, w, a

r - open in read mode
w - open in write mode
a - open in append mode

18
Q

It’s rarely done, but adding a + to the mode allows what?

A

Both input and output

19
Q

What does char *fgets( char *buffer, int buffer_size, FILE *file_descriptor); do?

A

Returns the pointer to the buffer if data was read, NULL otherwise

20
Q

What does fscanf(FILE *file_descriptor, char *pattern, …); do?

A

Returns the number of items of the pattern matched

21
Q

What does int fgetc( FILE *file_descriptor); do?

A

Returns unsigned char promoted to an int

22
Q

What does int ungetc(int character, FILE *file_descriptor); do?

A

Put a read character back into the data buffer

23
Q

What does feof( FILE *file_descriptor) do?

A

Returns zero (false) if there is more data in the file to read

24
Q

What does int fprintf( FILE * file_descriptor, char *pattern, …); do?

A

Returns the number of bytes printed.

25
Q

What does fputs( char *string, FILE *file_descriptor) do?

A

Returns the number of characters printed

26
Q

What does fputc( int character, FILE *file_descriptor) do?

A

Returns the character printed or EOF

27
Q

What does fflush( FILE *file_descriptor) do?

A

Flush the data from the buffer to the IO device

Returns 0 if the flush was successful

28
Q

What does char *tmpname( char *name_buffer) do?

A

Get the name of the temporary file that you can open

Typically appears in the /tmp directory

The name is stored in name_buffer
Must have at least L_tmpnam butes in the array

Returns name_buffer if successful, NULL otherwise

29
Q

What does FILE *tmpfile( void) do?

A

Open a temporary file

You won’t know the file name

Opened in w+ mode, so you can read or write to it