c program structure using function
write a simple c program which accept structure element and print it using function. (use call by value )
how to write a simple c program which accept structure element and print it using function use call by value and call by reference example with source code , structure using function and pointer program example with source code.
#include<stdio.h>
#include<conio.h>
struct stud{ int rno;char nm[20];};
void pr(struct stud s);
void main()
{
struct stud s1;
clrscr();
printf("enter structure element : \n ");
scanf("%d",&s1.rno);
fflush(stdin);
gets(s1.nm);
pr(s1);
getch();
}
void pr(struct stud s)
{ printf("\n_____________________\n");
printf("id=%d Name=%s",s.rno,s.nm);
}
output:
c program structure using function and Pointer
write a simple c program which accept structure element and print it using function (use call by reference )
#include<stdio.h>
#include<conio.h>
struct stud{ int rno;char nm[20];};
void pr(struct stud *s);
void main()
{
struct stud s1;
clrscr();
printf("enter structure element : \n ");
scanf("%d",&s1.rno);
fflush(stdin);
gets(s1.nm);
pr(&s1);
getch();
}
void pr(struct stud *s)
{
printf("\n_____________________\n");
printf("id=%d Name=%s",s->rno,s->nm);
}