Explain the Structure of C++ Program With an Example
- Basic Structure of C++ Program
- Briefly Explain About Structure of a C++ Program
- Write the Structure of a C++ Program with an Example
1. Basic Structure of C++ Program
The struct keyword is used to define a structure. struct define a new data type which is a collection of different type of data.
Structure Syntax:
struct structure_name
{
Statement...........1
Statement...........2
Statement...........3
.
.
.
Statement...........n
};
Defining a Structure
struct keyword is used to define a structure. struct defines a new data type, a collection of different data types. Below is the Syntax of the Structure for the C Program to Display Student Details Using Structure.
Syntax of Structure
struct structure_name
{
//Statements
};
Briefly Explain About Structure of a C++ Program.
Here we are Defining the Structure and the Data Types with Structure. structure program for student details in c to store the Student Name, Roll no, and Student Marks.
Here we are storing single student information ie, Student Name, Student Roll Number and Student Marks without using the FOR LOOP.
Here we are Printing the Output of the Structure Details, Student Name, Student Roll Number and Student Marks without using any LOOPS.
struct student
{
char name[50];
int roll;
float marks;
};
Here we are storing single student information ie, Student Name, Student Roll Number and Student Marks without using the FOR LOOP.
printf("Enter The Information of Students :\n\n");
scanf("%s",s.name);
scanf("%d",&s.roll);
scanf("%f",&s.marks);
Here we are Printing the Output of the Structure Details, Student Name, Student Roll Number and Student Marks without using any LOOPS.
printf("Name: %s\n",s.name);
printf("Roll: %d\n",s.roll);
printf("Marks: %.2f\n",s.marks);
Write the Structure of a C++ Program with an Example
#include <stdio.h>
struct student
{
char name[50];
int roll;
float marks;
};
int main()
{
struct student s;
printf("Enter the Students Information:\n\n");
printf("Enter Name: ");
scanf("%s", s.name);
printf("Enter Roll No.: ");
scanf("%d", &s.roll);
printf("Enter Marks: ");
scanf("%f", &s.marks);
printf("\nStudents Information\n");
printf("Name: %s\n", s.name);
printf("Roll: %d\n", s.roll);
printf("Marks: %.2f\n", s.marks);
return 0;
}
0 Comments: