Structure and Functions

Algorithm

Step 1: Start

Step 2: Define a structure student with members rno and perc

Step 3: Declare a structure variable s1

Step 4: Read rno and perc from user

Step 5: Call display1 with structure members as arguments

Step 6: Call display2 with structure variable

Step 7: Call display3 with address of structure

Step 8: Display values inside respective functions

Step 9: End

Flowchart

graph TD; A([Start]) --> B[Define structure]; B --> C[Declare structure variable]; C --> D[/Input rno, perc/]; D --> E[/Call display1 with members/]; E --> F[/Call display2 with structure/]; F --> G[/Call display3 with address/]; G --> H([End]); classDef start fill:#00cc44,color:#fff; classDef stop fill:#ff4444,color:#fff; classDef process fill:#4488ff,color:#fff; classDef input_output fill:#ffdd44,stroke:#cc9900,stroke-width:2px,color:#000000; class A start; class H stop; class B,C process; class D,E,F,G input_output;

Program

//Passing the address of a structure
#include <stdio.h>

struct student {
    int rno;
    float perc;
};

int display1(int, float);
int display2(struct student);
int display3(struct student *);

int main() {
    struct student s1;
    printf("Enter Rno. :");
    scanf("%d", &s1.rno);

    printf("Enter Percentage :");
    scanf("%f", &s1.perc);

    display1(s1.rno, s1.perc);
    display2(s1);
    display3(&s1);

    return 0;
}

int display1(int a, float b) {
    printf("\n\nPassing Structure Members as arguments :");
    printf("\nR.No : %d", a);
    printf("\nPercentage : %.2f", b);
    return 0;
}

int display2(struct student s2) {
    printf("\n\nPassing Structure as argument :");
    printf("\nR.No : %d", s2.rno);
    printf("\nPercentage : %.2f", s2.perc);
    return 0;
}

int display3(struct student *p) {
    printf("\n\nPassing Structure Address as argument :");
    printf("\nR.No : %d", p->rno);
    printf("\nPercentage : %.2f", p->perc);
    return 0;
}

Test Case Output
Enter Rno. : 101
Enter Percentage : 87.5

Passing Structure Members as arguments :
R.No : 101
Percentage : 87.50

Passing Structure as argument :
R.No : 101
Percentage : 87.50

Passing Structure Address as argument :
R.No : 101
Percentage : 87.50