C Programming MCQ - File Handling

11.If there is any error while opening a file, fopen will return?

A. Nothing
B. EOF
C. NULL
D. Depends on compiler

View Answer


12.It is not possible to combine two or more file opening mode in open () method.

A. True
B. False

View Answer


13.What is the return value of putchar()?

A. The character written
B. EOF if an error occurs
C. Nothing
D. Both character written & EOF if an error occurs

View Answer


14.Which is true?

A. The symbolic constant EOF is defined in
B. The value is -1
C. The symbolic constant EOF is defined in & value is -1
D. Only value is -1

View Answer


15.What is the purpose of "rb" in fopen() function used below in the code?

FILE *fp;
fp = fopen("demo.txt", "rb");

A. Open "demo.txt" in binary mode for reading
B. Create a new file "demo.txt" for reading and writing
C. Open "demo.txt" in binary mode for reading and writing
D. None of the above

View Answer


16. Which files will get closed through the fclose() in the following program?

  void main()
  {
     FILE *fp, *ft;
     fp = fopen("a.txt", "r");
     ft = fopen("b.txt", "r");
     fclose(fp,ft);
  }

A. a, b
B. a
C. b
D. Error in fclose

View Answer


17. When fopen() is not able to open a file, it returns

A. EOF
B. NULL
C. Run-time Error
D. None of the above

View Answer


18. getc() returns EOF when

A. When getc() fail to read the character
B. When end of file is reached
C. Both A and B
D. None of the above

View Answer


19. What is the output of this program?

  #include<stdio.h>
  int main(){
     FILE *fp;
     char *str;
     fp=fopen("demo.txt","r");
// demo.txt :you are a good programmer
     while(fgets(str,6,fp)!=NULL)
     puts(str);
     fclose(fp);
     return 0;
  }

A. you are a good programmer
B. e a good programmer
C. you ar
D. you are

View Answer


20. What is the output of this program?

  #include<stdio.h>
  int main(){
     char c;
     FILE *fp;
     fp=fopen("demo.txt","r");
     while((c=fgetc(fp))!=EOF)
     printf("%c",c);
     fclose(fp);
     return 0;
  }

A. It will print the content of file demo.txt
B. It will print the content of file till it encouter new line character
C. Compilation Error
D. None of the above

View Answer


21. What is the output of this program?

  #include<stdio.h>
  int main(){
     char c;
     FILE *fp;
     fp=fopen("demo.txt","a+");
// demo.txt : hello you are reading a file
     fprintf(fp," demo");
     fclose(fp);
     fp=fopen("myfile.txt","r");
     while((c=fgetc(fp))!=EOF)
     printf("%c",c);
     fclose(fp);
     return 0;
  }

A. hello you are reading a file
B. hello you are reading a file demo
C. demo
D. None of the above

View Answer







Also check :


Discussion


* You must be logged in to add comment.