定義指針變量:數(shù)據(jù)類型 * 變量名 /*表示定義一個變量(指針變量)指向該數(shù)據(jù)類型*/
例如: int *p /*p保存一個int類型變量的地址*/
int a = 10;
指針變量賦值 p = &a; /*p保存a的地址*/
指針訪問變量值 int b = *p; /*訪問p中保存地址上的值*/
#include<iostream>usingnamespace std;intmain(){int array[4]={13,14,35,33};int*p = array;//相當(dāng)于int *p1 = &array[0]int*p1 =&array[1];cout<<array<<endl;//數(shù)組名相當(dāng)于數(shù)組首地址cout<<*p<<endl;//返回數(shù)組首地址上的值cout<<*p1<<endl;//返回數(shù)組首地址偏移4個字節(jié)上的值cout<<"//"<<endl;for(int i =0; i <4; i++){cout<<p[i]<<endl;}cout<<"//"<<endl;for(int i =0; i <4; i++){cout<<*(p+i)<<endl;}cout<<"//"<<endl;for(int i =0; i <4; i++){cout<<*p++<<endl;}system("pause");}創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎