Answer to Question #211092 in C for Prasanna

Question #211092

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


1
Expert's answer
2021-06-27T14:12:30-0400
#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;
}




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