分享一个 const char 数组和 const char* 数组以及跟 int 数组指针输出案例。
#include
usingnamespace std;
void main(){
//const char的变
constchar aa[8]="abcdefg";
constchar* bb ="1234567";
cout << bb << endl; //输出1234567
cout <<*bb << endl; //输出1
cout << bb+1<< endl;//输出234567
cout <<*(bb +1)<< endl;//输出2
cout <<(*bb +2)<< endl;//bb指针地址123456,指向的内容为1,所以*bb='1',1的ASCII为49,所以输出(*bb + 2)=51
cout <<"--------------"<< endl;
constchar*charp,*charp2;
cout << aa<< endl;//输出abcdefg
cout <<*aa << endl;//输出a
charp = aa; //此时如果调用cout << charp << endl;输出abcdefg;调用cout << *charp << endl;输出a
charp=&aa[0];
charp2=&aa[1]; //charp2为const char*指向aa[1]='b'字符,调用*charp2输出b,但是调用charp2将会输出bcdefg
cout <<*charp << endl;//输出字符a
cout << charp << endl;//输出字符串abcdefg
cout <<*charp2 << endl;//输出字符b
cout << charp2 << endl;//输出字符串bcdefg
cout <<"--------------"<< endl;
int i[5]={1,2,3,4,5};
int*ip,*ip2;
ip = i;
cout << i << endl;//输出00CFFE44地址
cout <<*i << endl;//输出数值1
cout << ip << endl;//输出00CFFE44地址,地址指向的内容为数值1
cout <<*ip << endl;//输出数值1
system("pause");
}