Join 75,000+ students acing their exams with Studygenie
Unlimited practice
Flashcards, multiple choice and written questions, as many as you want.
Study sets in seconds
Turn your notes and files into a set with AI.
See your progress
Always know what you've learned and what's left.
Questions in this set (7)
What does scanf do?
reads a string and tells it where to write the input. returns either: number of parsed tokens, 0 (formatting error), EOF (end of file)
Why is scanf bad?
scanf doesn't have a limit to how many characters it can reads from input. Thus, if the input is longer than the allocated memory for the variable, it will lead to buffer overflow
What do we have to do when opening files?
since C program doesn't have exceptions, we have check if file is successfully opened. and make sure once we're done with the file we fclose(file)
What is the difference between struct and classes from Java?
struct is similar to class, except that struct can only hold data and not have its own functions/methods.
Is this correct: int* ptr1, ptr2? If not, what would happen?
not correct, only ptr1 would be a pointer variable. correct implementation would be
int *ptr1, *ptr2
How to open a file in C program?
FILE *file = fopen("filename.txt", "r");
"r" stands for read mode
What happens if we don't close our file?
fclose(file) is important, if there was a situation where we open a bunch of files, it'll cause the program to crash.