← Back to Subject
PPS (C Language) • MCQ • User Defined Data Types and File Handling
Most Important 30 Objective Question - User Defined Data Types and File Handling
Q1. Which keyword is used to define structure in C?

A) union
B) struct
C) typedef
D) class

Answer: B

Explanation:
The struct keyword is used to define a structure in C.

Q2. Structure is used to store:

A) Same type data only
B) Different type data together
C) Only integers
D) Only strings

Answer: B

Explanation:
Structure allows storing different types of data under one name.

Q3. Which operator is used to access structure members?

A) *
B) .
C) &
D) %

Answer: B

Explanation:
Dot (.) operator is used to access members of a structure.

Q4. Which is a valid structure declaration?

A) struct student;
B) struct student { int id; };
C) student struct { };
D) structure student { };

Answer: B

Explanation:
This is the correct syntax for structure declaration.

Q5. Which keyword is used to define union?

A) struct
B) typedef
C) union
D) class

Answer: C

Explanation:
The union keyword is used to define a union.

Q6. In union, memory is:

A) Separate for each member
B) Shared by all members
C) Not allocated
D) Fixed to integer only

Answer: B

Explanation:
All members of a union share the same memory location.

Q7. Which operator is used for pointer to structure?

A) .
B) ->
C) ::
D) %

Answer: B

Explanation:
Arrow operator (->) is used with structure pointers.

Q8. typedef is used for:

A) Creating loops
B) Giving new name to existing data type
C) Opening files
D) Pointer declaration

Answer: B

Explanation:
typedef creates an alias name for an existing data type.

Q9. Which function is used to open a file?

A) fopen()
B) fclose()
C) fprintf()
D) fscanf()

Answer: A

Explanation:
fopen() is used to open a file.

Q10. Which function is used to close a file?

A) fopen()
B) fclose()
C) fread()
D) fwrite()

Answer: B

Explanation:
fclose() is used to close an opened file.

Q11. Which mode is used to read a file?

A) w
B) a
C) r
D) x

Answer: C

Explanation:
'r' mode opens a file for reading.

Q12. Which mode is used to write a file?

A) r
B) w
C) a
D) rb

Answer: B

Explanation:
'w' mode opens a file for writing.

Q13. Which mode is used to append data?

A) a
B) r
C) w
D) x

Answer: A

Explanation:
'a' mode adds data at the end of the file.

Q14. FILE in C is:

A) Keyword
B) Data type
C) Structure type
D) Loop

Answer: C

Explanation:
FILE is a structure type used for file handling.

Q15. Which function writes formatted data to file?

A) fscanf()
B) fprintf()
C) fgets()
D) scanf()

Answer: B

Explanation:
fprintf() writes formatted output into a file.

Q16. Which function reads formatted data from file?

A) fprintf()
B) fscanf()
C) fwrite()
D) putc()

Answer: B

Explanation:
fscanf() reads formatted input from a file.

Q17. Which function writes binary data?

A) fwrite()
B) fprintf()
C) fscanf()
D) gets()

Answer: A

Explanation:
fwrite() is used to write binary data into files.

Q18. Which function reads binary data?

A) fread()
B) fprintf()
C) fscanf()
D) puts()

Answer: A

Explanation:
fread() reads binary data from a file.

Q19. Which file stores data permanently?

A) RAM
B) File
C) Register
D) Cache

Answer: B

Explanation:
Files are used for permanent storage of data.

Q20. Which statement is true for structure?

A) Same type only
B) Different data types allowed
C) No variables allowed
D) Only arrays allowed

Answer: B

Explanation:
Structures allow members of different data types.

Q21. Which statement is true for union?

A) Separate memory for all
B) Shared memory for all
C) No memory
D) Only float allowed

Answer: B

Explanation:
Union members use the same memory area.

Q22. Which function moves file pointer?

A) fseek()
B) fopen()
C) fclose()
D) fgets()

Answer: A

Explanation:
fseek() is used for random access in files.

Q23. Which function tells current file position?

A) ftell()
B) fread()
C) fopen()
D) rewind()

Answer: A

Explanation:
ftell() returns the current position of the file pointer.

Q24. Which function moves file pointer to beginning?

A) rewind()
B) ftell()
C) fseek()
D) fclose()

Answer: A

Explanation:
rewind() resets the file pointer to the beginning.

Q25. Which is correct for file pointer declaration?

A) file *fp;
B) FILE *fp;
C) pointer file fp;
D) FILE fp();

Answer: B

Explanation:
Correct syntax is: FILE *fp;

Q26. Nested structure means:

A) File inside file
B) Structure inside structure
C) Union inside loop
D) Array inside file only

Answer: B

Explanation:
Nested structure means one structure inside another structure.

Q27. Array of structures means:

A) Many structure variables in array form
B) Array inside file
C) Union inside array
D) Pointer inside loop

Answer: A

Explanation:
Array of structures stores multiple records of same structure type.

Q28. Which function is used for character input from file?

A) fgetc()
B) getch()
C) getchar()
D) gets()

Answer: A

Explanation:
fgetc() reads a single character from a file.

Q29. Which function writes one character to file?

A) fputc()
B) putchar()
C) printf()
D) puts()

Answer: A

Explanation:
fputc() writes a single character into a file.

Q30. Which is used for random access file handling?

A) while loop
B) fseek()
C) printf()
D) typedef

Answer: B

Explanation:
fseek() helps move directly to any position in a file.
Google AdSense Ad Placement Here 📢