Guest User

Untitled

a guest
Aug 23rd, 2022
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <cstdio>
  2. class Test{
  3.     public:
  4.     int accumulate;
  5.     int id;
  6.     static int counter;
  7.     Test(){
  8.         id=counter++;
  9.         accumulate=0;
  10.         printf("%d at %p says hi!\n",id, this);
  11.     }
  12.     ~Test(){
  13.         printf("%d at %p says bye!\n",id, this);
  14.     }
  15.     void add(int x){
  16.         accumulate+=x;
  17.     }
  18. };
  19. int Test::counter=0;
  20. int global_int=0;
  21. char global_str[]="Hello";
  22. int main(int argc, char** argv){
  23.     int index;
  24.     int* ptr;
  25.     for(int index=0;index<10;++index){
  26.         Test acc;
  27.         acc.add(index);
  28.         ptr=&acc.accumulate;
  29.         printf("%p: %d | %p: %d\n",&acc, acc.accumulate, ptr, *ptr);
  30.     }
  31.     printf("argc is located at %p, index is located at %p, ptr is located at %p\n",&argc,&index,&ptr);
  32.     printf("global_int is located at %p, global_str is located at %p Test::counter is located at %p\n",
  33.             &global_int,&global_str,&Test::counter);
  34.     return 0;
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment