C Structure

Giving values to members

/* Example program for using a structure*/ 
#include  <stdio.h> 
void main() 
     int id_no; 
	 char name[20]; 
	 char address[20]; 
	 char combination[3]; 
	 int age;  
	printf(“Enter the student information”); 
	printf(“Now Enter the student id_no”); 
	printf(“Enter the name of the student”); 
	scanf(“%s”,&new student.name); 
	printf(“Enter the address of the student”);
 	scanf(“%s”,&new student.address); 
    printf(“Enter the cmbination of the student”); 
	scanf(“%d”,&new student.combination);
	printf(“Enter the age of the student”); 
	scanf(“%d”,&new student.age); 
	printf(“Student information\n”); 
	printf(“student id_number=%d\n”,newstudent.id_no);
	printf(“student name=%s\n”,newstudent.name); 
	printf(“student Address=%s\n”,newstudent.address); 
	printf(“students combination=%s\n”,newstudent.combination); 
	printf(“Age of student=%d\n”,newstudent.age); 

Giving values to members

As mentioned earlier the members themselves are not variables they should be linked to structure variables in order to make them meaningful members. The link between a member and a variable is established using the member operator ‘.’ Which is known as dot operator or period operator.
   For example: 
Is the variable representing the price of book1 and can be treated like any other ordinary variable. We can use scanf statement to assign values like
			scanf(“%d”,& book1.pages);

Make Comments..!!

Oops!! No posts from user.

Download Android App