1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| #include <stdio.h> #include <iostream> using namespace std; void fun(char a[100]){ cout << sizeof(a) << endl; cout << strlen(a) << endl; } int main() { char *p1 = "Hello world!"; char p2[] = "Hello world!"; char p3[] = {'H','e','l','l','o',' ','w','o','r','l','d','!'}; char p4[] = {'H','e','l','l','o','\0','w','o','r','l','d','!'}; char p5[100] = {'H','e','l','l','o','\0','w','o','r','l','d','!'}; char *p6 = "Hello world!"; cout << int(p1) << "\t" << int(p6) << endl; cout << sizeof(p1) << endl; cout << sizeof(p2) << endl; cout << sizeof(p3) << endl; cout << sizeof(p4) << endl; cout << sizeof(p5) << endl; cout << sizeof(short) << endl; cout << sizeof(int) << endl; cout << sizeof(long) << endl; cout << sizeof(long long) << endl; cout << sizeof(__int64) << endl; cout << sizeof(float) << endl; cout << sizeof(double) << endl; cout << strlen(p1) << endl; cout << strlen(p2) << endl; cout << strlen(p3) << endl; cout << strlen(p4) << endl; cout << strlen(p5) << endl; fun(p5); system("pause"); return 0; }
|