Answer to Question #206500 in C for Steve

Question #206500

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 :









1
Expert's answer
2021-06-14T03:00:18-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS