#include<iostream> using namespace std; int main(){ int a=10; int *p; p=&a; cout<<"a的地址为: "<<&a<<endl; cout<<"指针p为:"<<p<<endl; *p=1000; cout<<"a= "<<a<<endl; cout<<"*p= "<<*p<<endl; return 0; }
#include<iostream> using namespace std; int main(){ // int a=10; // int *p; // p=&a; // cout<<"a的地址为: "<<&a<<endl; // cout<<"指针p为:"<<p<<endl; // *p=1000; // cout<<"a= "<<a<<endl; // cout<<"*p= "<<*p<<endl; //指针所占内存空间 //32位操作系统下,指针是占4个字节空间大小,不管是什么数据类型 cout<<"sizeof(int *)="<<sizeof(int *)<<endl; cout<<"sizeof(int *)="<<sizeof(float *)<<endl; cout<<"sizeof(int *)="<<sizeof(double *)<<endl; cout<<"sizeof(int *)="<<sizeof(char *)<<endl; return 0; }
64位操作系统下,指针是占8个字节