forked from tridibsamanta/CPP_Beginner_to_Expert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CPP030_Structure.cpp
56 lines (40 loc) · 1.03 KB
/
CPP030_Structure.cpp
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* Author: Tridib Samanta
* Created: 02.02.2020
**/
#include<iostream>
using namespace std;
struct personalData {
string name;
string address;
string contactNo;
short age;
};
void modify(personalData *);
int main() {
personalData person[5];
person[0].name = "Tridib Samanta";
person[0].address = "Kolkata";
person[0].contactNo = "+91 9000000000";
person[0].age = 21;
person[1].name = "Nikola Tesla";
cout<<person[0].name<<endl;
cout<<person[0].address<<endl;
cout<<person[0].contactNo<<endl;
cout<<person[0].age<<endl;
cout<<endl;
//Ways of fetching the values using pointer
cout<<(*person).name<<endl;
cout<<(*(person+1)).name<<endl;
cout<<(*&person[0]).name<<endl;
cout<<(person+1)->name<<endl;
personalData *p = person;
cout<<p->name<<endl;
cout<<endl;
modify(p);
cout<<(p+1)->name<<endl;
return 0;
}
void modify(personalData *person) {
(person+1)->name="Peter";
}