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:

C C++ program to differentiate between structure and union

C C++ program to differentiate between structure and union

Function क्या है इसका प्रयोग क्यो किया जाता है यह कितने प्रकार का होता है जानने के लिए देखें—Functions in C

C Language में Character Array या String किसे कहते है जानने के लिए देखें हमारा यह पोस्ट— Strings in C

C Language में Union क्या होता है और यह Structure से किस तरह भिन्न है जानने के लिए देखें—Unions in C

C program to differentiate between structure and union

#include<stdio.h>

struct s
{
    char c;
    int i;
    float f;
}sv;

union u
{
    char c;
    int i;
    float f;
}uv;

int main()
{
    printf("Size of sv = %d\n",sizeof(sv));
    printf("Size of uv = %d\n",sizeof(uv));
    printf("Addresses of sv = %u %u %u\n",&sv.c,&sv.i,&sv.f);
    printf("Addresses of uv = %u %u %u\n",&uv.c,&uv.i,&uv.f);
    return 0;
}

C++ program to differentiate between structure and union

#include<iostream>
using namespace std;

struct s
{
    char c;
    int i;
    float f;
}sv;

union u
{
    char c;
    int i;
    float f;
}uv;

int main()
{
    cout<<"Size of sv = "<<sizeof(sv)<<endl;
    cout<<"Size of uv = "<<sizeof(uv)<<endl;
    cout<<"Addresses of sv = "<<&sv.c<<" "<<&sv.i<<" "<<&sv.f<<endl;
    cout<<"Addresses of uv = "<<&uv.c<<" "<<&uv.i<<" "<<&uv.f<<endl;
    return 0;
}

Output of C C++ program to differentiate between structure and union

C C++ program to differentiate between structure and union

Other union programs in C C++

  1. Declaration and initialization of union
  2. Declaration and initialization of structure
  3. Array of structure
  4. Pointer to structure
Share it to:

Pointer to structure example program in C C++

Pointer to structure example program in C C++

C Language में Character Array या String किसे कहते है जानने के लिए देखें हमारा यह पोस्ट— Strings in C

C Language में Structure क्या होता है और इसका प्रयोग क्यो किया जाता है जानने के लिए देखें—Structures in C

Pointer और इसके कार्य करने के तरीके को आधिक जानने के लिए देखें यह पोस्ट—Pointers in C

Pointer to structure example program in C

#include<stdio.h>

struct student
{
    char grade;
    int marks;
    float percent;
};

int main()
{
    struct student std;
    struct student *ptr;
    ptr=&std;
    printf("Enter Grade   : ");
    scanf("%c",&std.grade);
    printf("Enter Marks   : ");
    scanf("%d",&std.marks);
    printf("Enter Percent : ");
    scanf("%f",&std.percent);
    printf("The Grade is  : %c",ptr->grade);
    printf("\nThe Marks is  : %d",ptr->marks);
    printf("\nThe Percent is: %f",ptr->percent);
    return 0;
}

Pointer to structure example program in C++

#include<iostream>
using namespace std;

struct student
{
    char grade;
    int marks;
    float percent;
};

int main()
{
    struct student std;
    struct student *ptr;
    ptr=&std;
    cout<<"Enter Grade    : ";
    cin>>std.grade;
    cout<<"Enter Marks    : ";
    cin>>std.marks;
    cout<<"Enter Percent  : ";
    cin>>std.percent;
    cout<<"The Grade is   : "<<ptr->grade<<endl;
    cout<<"The Marks is   : "<<ptr->marks<<endl;
    cout<<"The Percent is : "<<ptr->percent<<endl;
    return 0;
}

Output of Pointer to structure example program in C C++

Pointer to structure example program in C C++

Related structure example programs in C C++

  1. Declaration and initialization of structure
  2. Array of structure
Share it to:

Example program for array of structure in C C++

Example program for array of structure in C C++

C Language में Character Array या String किसे कहते है जानने के लिए देखें हमारा यह पोस्ट— Strings in C

Function क्या है इसका प्रयोग क्यो किया जाता है यह कितने प्रकार का होता है जानने के लिए देखें—Functions in C

C Language में Structure क्या होता है और इसका प्रयोग क्यो किया जाता है जानने के लिए देखें—Structures in C

Example program for array of structure in C

#include<stdio.h>

struct student
{
    char grade;
    int marks;
    float percent;
};

int main()
{
    struct student s[3];
    int i;
    for(i=0;i<3;i++)
    {
        printf("Enter Grade   : ");
        scanf("%c",&s[i].grade);
        printf("Enter Marks   : ");
        scanf("%d",&s[i].marks);
        printf("Enter Percent : ");
        scanf("%f",&s[i].percent);
    }
    for(i=0;i<3;i++)
    {
        printf("The Grade is  : %c",s[i].grade);
        printf("\nThe Marks is  : %d",s[i].marks);
        printf("\nThe Percent is: %f",s[i].percent);
    }

    return 0;
}

Example program for array of structure in C++

#include<iostream>
using namespace std;

struct student
{
    char grade;
    int marks;
    float percent;
};

int main()
{
    student s[3];
    int i;

    for(i=0;i<3;i++)
    {
        cout<<"Enter Grade    : ";
        cin>>s[i].grade;
        cout<<"Enter Marks    : ";
        cin>>s[i].marks;
        cout<<"Enter Percent  : ";
        cin>>s[i].percent;
    }

    for(i=0;i<3;i++)
    {
        cout<<"The Grade is   : "<<s[i].grade<<endl;
        cout<<"The Marks is   : "<<s[i].marks<<endl;
        cout<<"The Percent is : "<<s[i].percent<<endl;
    }

    return 0;
}

Output of Example program for array of structure in C C++

Example program for array of structure in C C++

Important structure example programs in C C++

  1. Declaration and initialization of structure
  2. Pointer to structure
Share it to:

Program for declaration and initialization of structure in C C++

Program for declaration and initialization of structure in C C++

C Language में Structure क्या होता है और इसका प्रयोग क्यो किया जाता है जानने के लिए देखें—Structures in C

C Language में Union क्या होता है और यह Structure से किस तरह भिन्न है जानने के लिए देखें—Unions in C

Structure और Union के मध्य क्या अंतर होता है समझने के लिए देखें यह पोस्ट—Structure vs Union

Program for declaration and initialization of structure in C

#include<stdio.h>

struct student
{
    char grade;
    int marks;
    float percent;
};

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.percent);
    printf("The Grade is  : %c",s.grade);
    printf("\nThe Marks is  : %d",s.marks);
    printf("\nThe Percent is: %f",s.percent);
    return 0;
}

Program for declaration and initialization of structure in C++

#include<iostream>
using namespace std;

struct student
{
    char grade;
    int marks;
    float percent;
};

int main()
{
    student s;
    cout<<"Enter Grade    : ";
    cin>>s.grade;
    cout<<"Enter Marks    : ";
    cin>>s.marks;
    cout<<"Enter Percent  : ";
    cin>>s.percent;
    cout<<"The Grade is   : "<<s.grade<<endl;
    cout<<"The Marks is   : "<<s.marks<<endl;
    cout<<"The Percent is : "<<s.percent<<endl;
    return 0;
}

Output of Program for declaration and initialization of structure in C C++

Program for declaration and initialization of structure in C C++

Similar structure example programs in C C++

  1. Array of structure
  2. Pointer to structure
Share it to: