Ticker

6/recent/ticker-posts

C Language (Structure in C)

STRUCTURE IN C

Structure in an user defined data type and unlike Array, it is a collection of different data type values.
In C language, structures are declares with help of the struct keyword.






HOW TO ACCESS STRUCTURE MEMBERS
To access structure members, we need to declare structure's object (a special variable) first and then use the dot (.) operator to access member of structure. 


EXAMPLE OF STRUCTURE IN C
#include<stdio.h>
#include<conio.h>
struct student
{
int roll;
char name[40];
float marks;
};

void main()
{
clrscr();
student ob;   //Declaring an object of student class

printf("Enter your roll number: ");
scanf("%d", &ob.roll);

printf("Enter your name: ");
scanf("%s", &ob.name);

printf("Enter the marks: ");
scanf("%f", &ob.marks);

// Print the details 
printf("\nRoll number is: %d", ob.roll);
printf("\nStudent  name is: %s", ob.name);
printf("\nMarks is: %f", ob.marks);
getch();
}














Post a Comment

0 Comments