10 Flashcards

1
Q

What is the function prototype for getchar?

A

int getchar(void);

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

What does getchar do?

A

Gets a single character from stdin.

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

What is the function prototype for putchar?

A

int putchar(int c);

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

What does putchar do?

A

Prints a single character to stdout.

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

What does putchar do if it is not given an unsigned char?

A

It returns an error value.

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

What does getchar return when it reaches the end of input?

A

EOF. This is a macro and may vary across platforms.

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

What is the return value of fopen?

A

FILE*

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

What are the three modes of file access?

A

‘r’, ‘w’, ‘a’

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

What is the ‘r’ mode of file access used for?

A

Reading.

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

What is the ‘w’ mode of file access used for?

A

Writing.

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

What is the ‘a’ mode of file access used for?

A

Appending data to a file.

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

What is the difference between ‘write’ and ‘append’ mode?

A

Write deletes the contents of the file if it already exists, whereas append starts writing to the end of the file.

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

What function is used to close a FILE*?

A

fclose

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

What is the function prototype for fclose?

A

int fclose(FILE *fp);

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

What is the function prototype for fopen?

A

FILE* fopen(const char* fname, const char* mode);

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

Which one of these is the correct function for writing a character to a file?
fputc
fputchar

A

fputc

17
Q

Which one of these is the correct function for reading a character from a file?
fgetc
fgetchar

A

fgetc

18
Q

What is the data type of stdin, stdout and stderr?

A

FILE*

19
Q

What is the function prototype for ungetc?

A

int ungetc(int char, FILE* stream);

20
Q

What does the function ‘ungetc’ do?

A

It returns a single character back into a stream. Useful for parsers etc.

21
Q

What does feof do?

A

Returns zero if the stream is at the end of the file.

22
Q

Which of these three streams in unbuffered?
stdin
stdout
stderr

A

stderr

23
Q

How are each of these streams buffered?
stdin
stdout
stderr

A

stdin and stdout are both line-buffered.

stderr is unbuffered.

24
Q

What does the fflush function do?

A

Flushes the buffer of a FILE*

25
Q

What does the function strerror do?

A

It takes in an errornumber and returns a string describing the error.

26
Q

What does the function perror do?

A

Prints a message to the error stream along with the current error message.

27
Q

What are bitfields?

A

When you specify how many bits a number will take up when you declare them.

28
Q

What are the three main ways of exiting a program?

A
  • Reaching the end of main
  • abort()
  • exit(int status)