Create a structure named student consists of members name ,age and mobileno. create structure variable to use both dot and arrow operator to access structure members.
Runtime Input :
#include <stdio.h>
#include <stdlib.h>
struct student {
char name[30];
int age;
int mobileno;
};
struct student* st1 = NULL;
struct student st2;
int main()
{
st1 = (struct student*)
malloc(sizeof(struct student));
// Assigning value to age variable
// of emp using arrow operator
st1->age = 18;
// Printing the assigned value to the variable
printf("Age: %d \n", st1->age);
// Assigning value to mobilenovariable
// of emp using dot operator
st2.mobileno = 128937128;
// Printing the assigned value to the variable
printf("Mobile No: %d\n", st2.mobileno);
return 0;
}
Comments
Leave a comment