Example program passing structure as function argument C C++

Example program passing structure as function argument C C++

C Language में Pointer क्या प्रयोग करते हुए किसी Function को कैसे point किया जा सकता है जानने के लिए देखें—Pointer to function

C Language में उपलब्ध विभिन्न प्रकार के Pointers और उनके उपयोग को जानने के लिए देखें—Types of Pointer in C

C के विभिन्न control statements को जानने के लिए देखें— Control statements in C

Example program passing structure as function argument C

#include<stdio.h>
struct student
{
    char grade;
    int marks;
    float per;
};
void display(struct student);
int main()
{
    struct student s;
    printf("Enter grade  : ");
    scanf("%c",&s.grade);
    printf("Enter marks  : ");
    scanf("%d",&s.marks);
    printf("Enter Percent: ");
    scanf("%f",&s.per);
    display(s);
    return 0;
}
void display(struct student s)
{
    printf("Grade  = %c\n",s.grade);
    printf("Marks  = %d\n",s.marks);
    printf("Percent= %f\n",s.per);
}

Example program passing structure as function argument C++

#include<iostream>
using namespace std;
struct student
{
    char grade;
    int marks;
    float per;
};
void display(struct student);
int main()
{
    struct student s;
    cout<<"Enter grade  :  ";
    cin>>s.grade;
    cout<<"Enter marks  :  ";
    cin>>s.marks;
    cout<<"Enter percent:  ";
    cin>>s.per;
    display(s);
    return 0;
}
void display(struct student s)
{
    cout<<"Grade    = "<<s.grade<<endl;
    cout<<"Marks    = "<<s.marks<<endl;
    cout<<"Percent  = "<<s.per<<endl;
}

Output of Example program passing structure as function argument C C++

Similar C C++ function example programs

  1. Sum of two numbers using function
  2. Average of three numbers using function
  3. Swapping using function call by value
  4. Swapping using function call by reference
  5. Passing array as function argument
  6. Pointer to Function
Share it to:

Published by

admin

I am a computer teacher, programmer and web developer