#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char a = 'A';
char* b = "QWERT";
char c[]{"ABCDEF"};
char* d[] = { "QW", "YU", "JK", "LI", "OP" };
char** e = d;
cout << "a :" << a << endl; //输出A
//cout << "&a: " << &a << endl; //输出乱码
cout << "static_cast<void*>(&a): " << static_cast<void*>(&a) << endl;//输出a的地址
cout << endl;
cout << "strlen(b): " << strlen(b) << endl; //输出5
cout << "b: " << b << endl; //输出QWERT
cout << "&b: " << &b << endl; //输出b的地址
cout << "static_cast<void*>(&b): " << static_cast<void*>(&b) << endl; //输出b的地址
cout << "*b: " << *b << endl; //输出Q
cout << "b+1: " << b + 1 << endl; //输出WERT
cout << "&b+1: " << &b + 1 << endl; //输出(b的地址+4)4是一个指针的大小
cout << "*b+1: " << *b + 1 << endl; //输出82 (Q的ASCII值为81)
cout << "&(b+1): ERROR" << endl; //
cout << "*(b+1): " << *(b + 1) << endl; //输出W
cout << "sizeof(b): " << sizeof(b) << endl; //输出4 (b是指针,大小为4个字节)
cout << endl;
cout << "strlen(c): " << strlen(c) << endl; //输出6
cout << "c: " << c << endl; //输出ABCDEF
cout << "&c: " << &c << endl; //输出A的地址
cout << "static_cast<void*>(&c): " << static_cast<void*>(&c) << endl; //输出A的地址
cout << "*c: " << *c << endl; //输出A
cout << "c+1: " << c + 1 << endl; //输出BCDEF
cout << "&c+1: " << &c + 1 << endl; //输出(A的地址+6+1)其中1是 '\0'引起的
cout << "*c+1: " << *c + 1 << endl; //输出66 (A的ASCII值是65)
cout << "&(c+1): ERROR" << endl; //
cout << "*(c+1): " << *(c + 1) << endl; //输出B
cout << "c[0]: " << c[0] << endl; //输出A
cout << "&c[0]: " << &c[0] << endl; //输出ABCDEF
cout << "static_cast<void*>(&c[0]): " << static_cast<void*>(&c[0]) << endl;//输出A的地址
cout << "c[1]: " << c[1] << endl; //输出B
cout << "&c[1]: " << &c[1] << endl; //输出BCDEF
cout << "static_cast<void*>(&c[1]): " << static_cast<void*>(&c[1]) << endl;//输出B的地址
cout << "sizeof(c): " << sizeof(c) << endl; //输出7(=6+1)其中1是 '\0'引起的
cout << endl;
//char* d[] = { "QW", "YU", "JK", "LI", "OP"};
cout << "strlen(d): " << strlen(*d) << endl; //输出2
cout << "d: " << d << endl; //输出QW中Q的地址
cout << "&d: " << &d << endl; //输出QW中Q的地址
cout << "*d: " << *d << endl; //输出QW
cout << "d+1: " << d + 1 << endl; //输出YU中Y的地址
cout << "&d+1: " << &d + 1 << endl; //输出(QW中Q的地址 + 20)5个指针,每个指针4个字节
cout << "*d+1: " << *d + 1 << endl; //输出W
cout << "&(d+1): ERROR" << endl; //
cout << "*(d+1): " << *(d + 1) << endl; //输出YU
cout << "d[0]: " << d[0] << endl; //输出QW
cout << "&d[0]: " << &d[0] << endl; //输出QW中Q的地址
cout << "static_cast<void*>(&d[0]): " << static_cast<void*>(&d[0]) << endl;//输出QW中Q的地址
cout << "d[1]: " << d[1] << endl; //输出YU
cout << "&d[1]: " << &d[1] << endl; //输出YU中Y的地址
cout << "static_cast<void*>(&d[1]): " << static_cast<void*>(&d[1]) << endl;//输出YU中Y的地址
cout << "static_cast<void*>(&d[4]): " << static_cast<void*>(&d[4]) << endl;//输出OP中O的地址
cout << "sizeof(d): " << sizeof(d) << endl; //输出20(共5个指针,每个指针4个字节)
cout << endl;
cout << strlen(*e) << endl; //输出2
cout << e << endl; //输出QW中Q的地址
cout << &e << endl; //输出e的地址
cout << *e << endl; //输出QW
cout << e+1 << endl; //输出YU中Y的地址
cout << &e+1 << endl; //输出(e的地址+4)
cout << *e+1 << endl; //输出W
cout << *(e + 1) << endl; //输出YU
cout << "&(e + 1): ERROR" << endl; //
cout << *(e + 1)+1 << endl; //输出U
cout << sizeof(e) << endl; //输出4(e是指针,每个指针4个字节)
cout << endl;
system("pause");
return 0;
}
写给笨笨的自己。
QAQ
Fighting!!