1. What is a file in C?

A file in C is a collection of data stored on secondary storage (hard disk). It allows programs to store data permanently. C provides file handling functions through the standard library header <stdio.h>.

2. What is FILE in C?

FILE is a structure defined in <stdio.h>. It is used to handle file streams. A pointer of type FILE* is used to access a file.

3. What is fopen()?

fopen() is used to open a file. It returns a pointer to FILE.

FILE *fp = fopen("data.txt", "r");

4. Explain file opening modes in C.

  • r – Read mode
  • w – Write mode
  • a – Append mode
  • r+ – Read & Write
  • w+ – Read & Write (truncate)
  • a+ – Read & Append

5. What is fclose()?

fclose() closes an opened file and releases resources.

6. What is EOF?

EOF (End Of File) is a constant that indicates the end of file. It is generally -1.

7. Difference between text file and binary file?

Text files store data in human-readable format, while binary files store data in binary form, which is faster and more compact.

8. What is fgetc()?

Reads a single character from a file.

9. What is fputc()?

Writes a single character to a file.

10. What is fgets()?

Reads a string from a file including spaces until newline.

11. What is fprintf()?

Used to write formatted output to a file.

12. What is fscanf()?

Used to read formatted input from a file.

13. What is fseek()?

Moves the file pointer to a specific position.

14. What is ftell()?

Returns current file pointer position.

15. What is rewind()?

Moves file pointer to the beginning of file.

16. What is a structure?

A structure is a user-defined data type that groups variables of different data types under one name.

17. Syntax of structure?

struct student {
int roll;
char name[50];
float marks;
};

18. How to access structure members?

Using dot operator (.)

19. What is structure pointer?

A pointer that stores address of structure variable. Access members using arrow operator (->).

20. What is nested structure?

A structure inside another structure.

21. What is array of structures?

An array where each element is a structure variable.

22. What is structure padding?

Extra bytes added by compiler to align data properly in memory.

23. What is typedef in structure?

typedef gives an alias name to structure.

24. Difference between structure and union?

Structure allocates memory for all members separately. Union shares memory among members.

25. Can structure contain functions?

No, C structures cannot directly contain functions.

26. What is enum?

Enum is a user-defined data type used to assign names to integral constants.

27. Example of enum:

enum day {MON, TUE, WED, THU, FRI};

28. What is default value of enum?

First element starts from 0 by default.

29. Can enum values be changed?

Yes, we can assign custom values.

30. Advantages of enum?

  • Improves code readability
  • Better program organization

31. What is memory allocation?

Process of allocating memory during program execution.

32. What is malloc()?

Allocates memory dynamically.

33. What is calloc()?

Allocates multiple blocks and initializes to zero.

34. Difference between malloc() and calloc()?

malloc() does not initialize memory; calloc() initializes to zero.

35. What is realloc()?

Resizes previously allocated memory.

36. What is free()?

Releases dynamically allocated memory.

37. What is memory leak?

When allocated memory is not freed properly.

38. What is stack memory?

Memory used for local variables and function calls.

39. What is heap memory?

Memory used for dynamic allocation.

40. Difference between stack and heap?

  • Stack: Automatic, faster
  • Heap: Manual allocation, slower

41. What is error handling in C?

Mechanism to detect and respond to runtime errors.

42. What is perror()?

Prints error message based on errno.

43. What is errno?

Global variable that stores error number.

44. What is strerror()?

Returns string representation of error.

45. What are compile-time errors?

Errors detected during compilation.

46. What are runtime errors?

Errors occurring during execution.

47. What are logical errors?

Errors in program logic.

48. How to handle file opening error?

if(fp == NULL) {
printf("File not found");
}

49. What is exit()?

Terminates program execution.

50. What is assert()?

Used for debugging; checks condition and stops program if false.

51. What is segmentation fault?

Occurs when program accesses invalid memory location.

52. What is dangling pointer?

Pointer pointing to freed memory.

53. What is null pointer?

Pointer that does not point to any valid memory.

54. What is file descriptor?

Integer that uniquely identifies an open file in low-level I/O.

55. What is buffering in file handling?

Temporary storage used to improve I/O performance.

📢 Join Our WhatsApp Channel

💼 Get Daily IT Job Updates, Interview Preparation Tips & Instant Alerts directly on WhatsApp.

👉 Join WhatsApp Now

📢 Join Our Telegram Channel

💼 Get Daily IT Job Updates, Interview Tips & Exclusive Alerts directly on Telegram!

👉 Join Telegram

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright © 2022 - 2025 itfreesource.com

Enable Notifications OK No thanks