Write a C program for printing roll number, name and phone number of a student using function. First declare a structure named student with roll_no, name and phone number as its members and 's' as its pointer variable. Then assign the values of roll number, name and phone number to the structure variable s. In passing by reference, address of structure variable is passed to the function. Now, while defining the function, Pass a copy of the pointer variable 's' as its argument with 'struct student' written before it because the variable which we have passed is of type structure named student.
Runtime Input:
30
Ragav
9998766563
Output:
30
Ragav
9998766563
#include <stdio.h>
#include <string.h>
struct student
{
int roll_no;
char name[20];
int phone_number;
};
void display(struct student *s)
{
printf("%d\n", s -> roll_no);
printf("%s\n", s -> name);
printf("%d\n", s -> phone_number);
}
int main()
{
struct student s;
scanf("%d",&s.roll_no);
fflush(stdin);
gets(s.name);
scanf("%d",&s.phone_number);
display(&s);
getchar();
getchar();
return 0;
}
Comments
Leave a comment