-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstructs.cpp
More file actions
40 lines (31 loc) · 928 Bytes
/
structs.cpp
File metadata and controls
40 lines (31 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <string>
// Define a struct to represent a Person
struct Person {
std::string name;
int age;
double height;
};
void printPerson(Person person);
int main() {
// Create an instance of Person and assign values
Person person1;
person1.name = "Alice";
person1.age = 30;
person1.height = 1.65;
// Create another instance using aggregate initialization
Person person2 = {"Bob", 25, 1.80};
// Print the details of person1
std::cout << "Person 1:" << std::endl;
printPerson(person1);
std::cout << std::endl;
std::cout << "Person 2:" << std::endl;
// Print the details of person2
printPerson(person2);
return 0;
}
void printPerson(Person person) {
std::cout << "Name: " << person.name << std::endl;
std::cout << "Age: " << person.age << std::endl;
std::cout << "Height: " << person.height << " m" << std::endl;
}