Home C Programming Language / Programs / Basic Programming of Structure
🚀 Programming Example

Basic Programming of Structure

👁 991 Views
💻 Practical Program
📘 Step Learning
This is a basic programming of Structure

💻 Program Code

#include <stdio.h>  
#include <string.h>  
struct employee    
{   int id;    
    char name[50];    
}e1;  //declaring e1 variable for structure  
int main( )  
{  
   //store first employee information  
   e1.id=101;  
   strcpy(e1.name, "Rambo Azmi");//copying string into char array  
   //printing first employee information  
   printf( "employee 1 id : %d\n", e1.id);  
   printf( "employee 1 name : %s\n", e1.name);  
   return 0;  
}  
                        

🖥 Program Output

employee 1 id : 101
employee 1 name : Rambo Azmi
Press any key to continue . . .
                            

📘 Explanation

Arrays allow to define type of variables that can hold several data items of the same kind. Similarly structure is another user defined data type available in C that allows to combine data items of different kinds. Structure helps to construct a complex data type in more meaningful way. It is somewhat similar to an Array. The only difference is that array is used to store collection of similar datatypes while structure can store collection of any type of data. Structure is used to represent a record. Suppose you want to store record of Student which consists of student name, address, roll number and age. You can define a structure to hold this information.
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.