Created
February 6, 2013 18:05
-
-
Save speedsticko/4724510 to your computer and use it in GitHub Desktop.
dereferencing pointer to struct creates copy?
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; | |
typedef struct Something | |
{ | |
int number; | |
} Something, *PSomething; | |
#define UPDATE_SOMETHING(something, n) (something).number = n; | |
void modifySomething(PSomething pSomething) { | |
// 1. | |
pSomething->number = 99; | |
// 2. | |
(*pSomething).number = 99; | |
/* 3. | |
Something s = *pSomething; | |
UPDATE_SOMETHING(s, 9); | |
cout<<"addr: "<<&s<<endl; | |
cout<<" .number: "<<s.number<<endl; | |
*/ | |
} | |
int main(int argc, char *argv[]) { | |
Something s1 = {0}; | |
modifySomething(&s1); | |
cout<<"addr: "<<&s1<<endl; | |
cout<<" .number: "<<s1.number<<endl; | |
char line[80]; | |
cin>>line; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment