C Enumeration
1. What is an Enumeration? An enumeration (enum) is a user-defined data type in C. It consists of a set of named integer constants. Makes code more readable and less error-prone compared to using...
1. What is an Enumeration? An enumeration (enum) is a user-defined data type in C. It consists of a set of named integer constants. Makes code more readable and less error-prone compared to using...
1. What is Struct Alignment? Alignment ensures that data members of a struct are stored at memory addresses suitable for their type. Many CPUs require certain types (like int or double) to be stored...
1. What is typedef? typedef allows you to define a new name for an existing data type. Makes code more readable, especially for complex types like structures, pointers, and function pointers. Syntax: typedef existing_type...
1. What is a Union? A union is similar to a structure (struct) in C, but all members share the same memory location. Only one member can store a value at a time. Useful...
1. Pointer to a Structure You can create a pointer that points to a structure variable. Useful when passing structures to functions or for dynamic memory allocation. Syntax:
|
1 2 |
struct StructName *ptr; ptr = &structVariable; |
Access members using arrow ->...
1. What are Nested Structures? A nested structure is a structure that contains another structure as a member. Useful for representing complex data objects like a student with an address, or an employee with...
1. What is a Structure? A structure is a user-defined data type in C. It allows you to store multiple variables of different data types under a single name. Useful for representing complex objects...
1. Opening a File for Reading Use fopen() with read mode:
|
1 |
FILE *fopen(const char *filename, const char *mode); |
Mode Description “r” Read (file must exist) “r+” Read & write (file must exist) “a+” Read & append (creates file if...
1. Opening a File for Writing Use fopen() with a write mode: FILE *fopen(const char *filename, const char *mode); Mode Description “w” Write (creates a new file or overwrites existing file) “a” Append (adds...
1. What is File Handling in C? File handling allows a program to store data permanently in a file on disk. Types of files in C: Text files → store readable characters (.txt) Binary...