C Programming 09/10 Flashcards

1
Q

What is realloc?

A

Allows you to change the size of a buffer which was previously malloced.
• void* realloc(void* ptr, int size);

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

What is memcpy?

A

Copies bytes from one memory area to another area.

• void *memcpy(void *restrict dst, const void *restrict src, size_t n);

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

What is alignment?

A

Many types have limitations on the memory address they can be placed at, it results in slower performance and wasted memory

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

What is getchar?

A

Function that gets a single character from stdin
• int getchar(void);
• Returns EOF or an unsigned char

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

What is putchar?

A

Function that puts a single character to stdout
• int putchar(int c);
• Should provide unsigned char, returns error value

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

What is fopen?

A

Opens a file and returns a file stream
• FILE *fopen(const char *fname, const char *mode);
• Returns a stream or NULL

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

What are the file modes?

A
  • “r” = Open file for reading
  • “w” = Open file for writing
  • “a” = Open file for appending at end of file (retain existing data)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is fclose?

A

Closes file associated with file stream
• int fclose(FILE *fp);
• Returns error value

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

What is fgetc?

A

Function that gets a single character from a file stream

• int fgetc(FILE *stream);

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

What is fputc?

A

Function that puts a single character to a file stream

• int fputc(int c, FILE *stream);

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

Why use fgetc/fputc over getchar/putchar?

A
  • fgets/fputs take size parameter so safe
  • fgets records \n
  • fputs doesn’t put \n
How well did you know this?
1
Not at all
2
3
4
5
Perfectly