C++

Structure in C++ programming language

Structure in C++ programming language

In this tutorial, we will discuss the concept of Structure in C++programming language

In the C++ programming language, the structure is a collection of a variety of different data types under a single unit with a name.

 

How to declare a structure

The struct keyword defines a structure in the name of the structure. Then we can declare  one or more data members inside the curly braces  of the structure

Syntax

Example

struct – it is a keyword in C++
student – structure name
The structure student is defined. It has four members for access data,  name, age, marks and average      

Always use structure to end a declaration with a semicolon(;)


Program 1

When the above program is executed, it produces the following results


Enter name :
Kamalraj
Enter student id :
12
Enter age :
23
Enter payment :
600
Student information
...............................
Student Name : Kamalraj
Student age : 23
Student id : 12
Student marks : 70
Student payment : 600
In this program, first, variables name, age, marks and pay are declared inside the student structure
Then the user is asked to enter the name, age, pay and marks of a student inside the main() function and it is stored in their variables
Finally, student information is displayed on the screen

Program 2




When the above program is executed, it produces the following result.


rahulan Emp no is: 123
rahulan sex is: m
samanthy Emp no is: 234
Samantha sex is: f

 

Related post

Structure in C Language                                      
Karmehavannan

Recent Posts

Subtract two numbers using method overriding

Subtract two numbers using method overriding   Program 1

3 months ago

PHP Star triangle Pattern program

PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…

3 months ago

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

1 year ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

1 year ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

1 year ago

This website uses cookies.