struct c++
//Struct is a compound data type that contains different variables of different types.
struct Student
{
char stuName[30];
int stuRollNo;
int stuAge;
};
struct c++
//Struct is a compound data type that contains different variables of different types.
struct Student
{
char stuName[30];
int stuRollNo;
int stuAge;
};
structs in c++
#include <bits/stdc++.h>
#include <iostream>
#define ll long long
using namespace std;
struct student{
int roll;
string name;
int age;
void studentDetails(){
cout<<"Name is "<<name<<" Age is "<<age<<" roll no is "<<roll<<endl;
}
};
int main(){
student sumant;
sumant.roll = 30;
sumant.name = "Sumant Tirkey";
sumant.age = 18;
sumant.studentDetails();
cout<<endl;
return 0;
}
constructor c++ struct
struct Rectangle {
int width; // member variable
int height; // member variable
// C++ constructors
Rectangle()
{
width = 1;
height = 1;
}
Rectangle( int width_ )
{
width = width_;
height = width_ ;
}
Rectangle( int width_ , int height_ )
{
width = width_;
height = height_;
}
// ...
};
how to create a struct in c++
struct product {
int weight;
double price;
} ;
product apple;
product banana, melon;
what is a struct in c++
struct Person
{
char name[50];
int age;
float salary;
};
c++ struct
#include<iostream>
#include<string>
using namespace std;
struct student
{
char name [20];
int age;
float marks;
};
int main()
{
student s;
cout<<"enter student name : "<<endl;
cin>>s.name;
cout<<"enter age : "<<endl;
cin>>s.age;
cout<<"enter marks : "<<endl;
cin>>s.marks;
cout<<"***********************"<<endl;
cout<<"name : "<<s.name<<endl;
cout<<"age : "<<s.age<<endl;
cout<<"marks : "<<s.marks<<endl;
return 0;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us