C Objective Interview Questions on Files

These C Objective Interview Questions On Files post providing basic, intermediate and Hard level examples in C Files. The Practice of these examples makes you good in C programming.


How is a file closed?

  1. file_pointer.close();
  2. file_pointer.fclose();
  3. close(file_pointer);
  4. fclose(file_pointer);

Answer :

Ans : 4

What is a random access file?

  1. Opening a file in random mode.
  2. A file can be accessed at random using fseek() function
  3. Both A and B
  4. None.

Answer :

Ans : 2

Pick out the correct statements in case of ftell function?

  1. Return character at particular location
  2. Return byte location of particular character
  3. Return 0 if no such location
  4. Return EOF if no such location.

Answer :

Ans : 2 , ftell function always returns byte location

What is the use of getw() and putw() functions?

  1. No such functions in file handling
  2. Used to work with string data in files
  3. Used to work with integer data in files
  4. None of above.

Answer :

Ans : 3

How many arguments fgets( ) is function taking to read a string?

  1. 2
  2. 4
  3. 3
  4. 1

Answer :

Ans : 4 , Only one, that is string variable name

Difference between gets() and fgets() functions

  1. gets() read a string including spaces from console
  2. fgets() read a specific set of characters into character array from file
  3. Both A and B correct
  4. Only B is correct.

Answer :

Ans : 3

Which of the following fopen statements is illegal?

  1. fp = fopen(“sample.txt”, “r”);
  2. fp = fopen(“/src/practice/test.txt”, “w”);
  3. fp = fopen(“abc”, “a”);
  4. None.

Answer :

Ans : 4

What does the following segment of code do?
fprintf(fp, “Java2Python”);

  1. It writes “Java2Python” into the file pointed by fp
  2. It reads“Java2Python” from the file and prints on display
  3. It writes as well as reads “Java2Python” to and from the file and prints it
  4. No such file in C file system.

Answer :

Ans : 1

FILE reserved word is

  1. A structure in stdio.h header file
  2. Primitive type in C
  3. No such type in C
  4. It is a type name defined in stdio.h

Answer :

Ans : 4

stdout, stdin and stderr are

  1. File pointers
  2. File descriptors
  3. Streams
  4. Structure.

Answer :

Ans : 3, All are streams to print a message, error messages and read message

 

Share this