C FILE HANDLING
Ques 1. what is the meaning of the statement ?
FILE *fileptr;
options:
A. fileptr is a integer pointer.
B. fileptr is pointer
C. FILE is a structure , fileptr is a pointer of type FILE.
D. error declaration.
Ques 2. what is the output written in the file samp.txt?
#include <stdio.h>
#include <stdlib.h>
FILE *fp;
int main()
{
char str[30]="good";
fp=fopen("samp.txt", "w");
fprintf(fp, "%s",str );
fclose(fp);
printf("Hello world!\n");
return 0;
}
options:
A. good
B. compiler error
C. runtime error
Ques 3. what is the value of EOF?
options:
A. none of the below
B. NULL
C. 0
D. -1
Ques 4. what is the meaning of r mode in c file opening?
options:
A. file is opened for read only
B. file is opened for write only
C. file is opened for write/read
D. none of the above
Ques 5. what is the meaning of "a" mode in c file opening?
options:
A. file is opened for read only
B. file is opened for write only
C. file is opened for append mode
D. none of the above
Ques 6. what is correct for about getc in below options?
options:
A. getc() read till EOF or finds error on reading a character.
B. getc() just read a character from standard input
C. getc read a character from a file.
D. none of the above
Ques 7. why is fseek is used?
options:
A. fseek moves the file ptr to the beginning of the file.
B. fseek moves the file ptr to the end of the file.
C. fseek moves the file ptr to the required location of the file.
D. all of the above.
Ques 8. what are the file opening modes in c?
options:
A. w,r,a, r+, w+
B. only w, r
C. only w, a
D. none of the above.
Ques 9. what fclose() funtion will do in c?
options:
A. it closes the stream and all the structure associated with it.
B. it exits the program
C. It exits from the fucntion
D. none of the above
Ques 10. what is the output for the below code?
#include < stdio.h>
#include < stdlib.h>
FILE *fp;
int main()
{
char str[30]="good";
int data = 456;
fp=fopen("samp.txt", "w");
fprintf(fp, "%s = %d",str,data );
fclose(fp);
return 0;
}
options:
A. 456 = good
B. good = 456
C. compiler error
D. runtime error
Answers
1. C
2. A
3. D
4. A
5. C
6. A
7. D
8. A
9. A
10. B