Some tests for 32-bit system C pointers

xiaoxiao2021-03-05  20

The test procedure is as follows:

#include using namespace std;

Void try (Char a []) {cout << "SIZEOF (a): << SIZEOF (a) << endl; cout << a << endl;}

Void main () {char str [] = "Hello"; char * p = str; char * s = "hello"; int N = 10;

Char B [100] = {'A', 'B', 'C', 'D', 'E', 'F', 'g', 'h'};

COUT << "SIZEOF (STR):" << sizeof (STR) << endl; cout << & p << endl; cout << "SizeOf (P): << SizeOf (P) << Endl; Cout < <"SIZEOF (S): << SizeOf (s) << endl; cout <<" SIZEOF (N): << SizeOf (n) << endl;

Try (b); cout << "SIZEOF (B):" << sizeof (b) << endl;}

RESULTS: SIZEOF (STR): 60012F518SizeOf (P): 4SizeOf (s): 4SizeOf (N): 4SizeOf (a): 4abcdefghsizeof (b): 100 Summary: 100 of parameter a [100] is a number of obeys, actually When I clicked for a [], the function is called, a pointer A space is assigned, and the size of this pointer space is 4 bytes, like sizeof (p), sizeof (s) is the memory size of the pointer itself. , Not the size of the memory pointed. The problem here is: Where is the difference between array pointer STR and pointer S?

转载请注明原文地址:https://www.9cbs.com/read-39038.html

New Post(0)