What is pointer?
The memory address of a variable or function of the pointer. It is an unsigned integer. It is a 32-bit, 4-byte system addressing range.
Pointer variable:
The variable that stores the address. In C ++, the pointer variable makes sense only when it has a clear point.
Pointer type
Int * ptr; // pointer variable pointing to the int type
Char * ptr;
Float * ptr;
Pointer:
Char * a [] = {"hello", "the", "world "};
Char ** p =;
P ++;
Cout <* p <endl; // output
Function pointer:
A pointer to a function. You can call a function by calling the pointer.
Example:
Int max (int, int );
Int (* f) (int) = & max;
D = (* f) (a, B), c ));
Pointer array:
Point to a group of pointers of a certain type (each array variable contains an address)
Int * ptr [10];
Array pointer:
A pointer to a type of array.
Int v [2] [10] = {1, 3, 4, 5, 6, 7, 8, 9, 10}, {11, 12, 13, 14, 15, 16, 17,18, 19,20 }};
Int (* a) [10] = v; // array pointer
Cout <** a <endl; // output 1
Cout <** (a + 1) <endl; // output 11
Cout <* (* a + 1) <endl; // output 2
Cout <* (a [0] + 1) <endl; // output 2
Cout <* (a [1] + 1) <endl; // OUTPUT 12
Cout <a [0] <endl; // output v [0] first address
Cout <a [1] <endl; // output v [1] first address
Int * p and (int *) p
Int * p: p indicates the integer pointer variable.
(Int *) p: converts the p type to an integer pointer.
The array name is equivalent to a pointer, And the array name is equivalent to a double pointer.
Int a [] = {1, 2, 3, 4, 5 };
Int * ptr = (int *) (& a + 1); // two-dimensional array, adding a row as a whole
Printf ("% d", * (a + 1), * (ptr-1); // output 25
Char * str = "helloworld" and char str [] = "helloworld"
Char * str = "helloworld": allocating global arrays and sharing buckets
Char str [] = "helloworld": allocating partial Arrays
Author: "My it World"