#include<stdio.h> #include<stdlib.h> #include<iostream> usingnamespacestd; voidtest() { int i=0; cout<<"func() int: "<<&i<<endl; int *j=newint; cout<<"func() new int: "<<j<<endl; delete j; } int global=10; int *gp=newint; intmain() { int s=sizeof(int); int s1=sizeof(long); printf("%d\n",s); printf("%d\n",s1); printf("hello\n"); int i=0; int *j=newint; int *k=newint; int *ii=&i; int *iii=newint; iii=&i; int *a=(int*)malloc(sizeof(int)*10); int *p=NULL; conststaticint x=1; cout<<"& int: "<<&i<<endl; cout<<"new int: "<<j<<endl; cout<<"new int: "<<k<<endl; cout<<"malloc int: "<<a<<endl; cout<<"int*: "<<p<<endl; cout<<"int*=&int: "<<ii<<endl; cout<<"new int*=&int: "<<iii<<endl; cout<<"const static int :"<<&x<<endl; cout<<"global int"<<&global<<endl; cout<<"global new int*"<<gp<<endl; test(); delete j; delete k; free(a); delete gp; return0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
4 8 hello & int: 0x7ffff146db8c new int: 0x1156050 new int: 0x1156070 malloc int: 0x11560b0 int*: 0 int*=&int: 0x7ffff146db8c new int*=&int: 0x7ffff146db8c const static int :0x400fd4 global int0x6020a0 global new int*0x1155c20 func() int: 0x7ffff146db5c func() new int: 0x11560e0