Skip to main content

Posts

Showing posts with the label Program

C programming- structure

Structures and unions are fundamental components in the C programming language that allow for the grouping of different data types. Here’s a detailed explanation of their definitions, declarations, initializations, and differences. 4.3.1 Structure: Definition, Declaration, Initialization, and Size Definition A structure in C is a user-defined data type that allows the combination of data items of different kinds. Structures are used to represent a record. For example, a structure can hold information about a student, including their name, age, and grade. Declaration To declare a structure, the  struct  keyword is used followed by the structure name and its members enclosed in braces. For example: c struct Student { char name [ 50 ] ; int age ; float grade ; } ; Initialization Structures can be initialized at the time of declaration using an initializer list. For example: c struct Student student1 = { "John Doe" , 20 , 3.5 } ; Size The size of a str...