Created
April 12, 2020 06:26
-
-
Save webber2408/7af3807cc989f3482c09141b6e019bb8 to your computer and use it in GitHub Desktop.
Structs in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
struct Country{ | |
string name; | |
int populationCount; | |
Country(string s, int n){ | |
name = s; | |
populationCount = n; | |
} | |
void showCountryDetails(){ | |
cout<<"Country Name: "<<name<<endl; | |
cout<<"Country Population: "<<populationCount<<endl; | |
} | |
}; | |
int main(){ | |
struct Country c1 = Country("India", 1300000000); | |
c1.showCountryDetails(); | |
return 0; | |
} | |
/* | |
Output: | |
Country Name: India | |
Country Population: 1300000000 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment