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:

Published by

admin

I am a computer teacher, programmer and web developer