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:

Published by

admin

I am a computer teacher, programmer and web developer