Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- class Test{
- public:
- int accumulate;
- int id;
- static int counter;
- Test(){
- id=counter++;
- accumulate=0;
- printf("%d at %p says hi!\n",id, this);
- }
- ~Test(){
- printf("%d at %p says bye!\n",id, this);
- }
- void add(int x){
- accumulate+=x;
- }
- };
- int Test::counter=0;
- int global_int=0;
- char global_str[]="Hello";
- int main(int argc, char** argv){
- int index;
- int* ptr;
- for(int index=0;index<10;++index){
- Test acc;
- acc.add(index);
- ptr=&acc.accumulate;
- printf("%p: %d | %p: %d\n",&acc, acc.accumulate, ptr, *ptr);
- }
- printf("argc is located at %p, index is located at %p, ptr is located at %p\n",&argc,&index,&ptr);
- printf("global_int is located at %p, global_str is located at %p Test::counter is located at %p\n",
- &global_int,&global_str,&Test::counter);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment