Monday, June 18, 2012

To demonstrate passing structures to functions


/* Program to demonstrate passing structures to functions */

#include<stdio.h>

#include<conio.h>

#include<string.h>

  struct record

  {

    char name[10];

    int rollno;

    float percent;

  }r;

void display(struct record r);

void main()

{

  clrscr();

  strcpy(r.name,"Arnav");

  r.rollno=20;

  r.percent=92.0;

  display(r); 

  getch();

}

 

void display(struct record r)

{

  printf("\nSTUDENT RECORD");

  printf("\nName:");

  puts(r.name);

  printf("Roll#:%d",r.rollno);

  printf("\nPercentage:%f",r.percent);

}

 

OUTPUT

 

STUDENT RECORD

Name:Arnav

Roll#:20

Percentage:92.000000

 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.