what the pointer is. A pointer is the memory address of a variable or function, an unsigned integer that is scoped to the system addressing range, 32 bits, 4 bytes.
pointer variable:The variable that holds the address. In C + +, pointer variables are meaningful only if they have a clear point of reference.
pointer type
Int*ptr; Pointer variable char*ptr pointing to int type
;
Float*ptr;
Pointer to pointer:
char*a[]={"Hello", "the", "World"};
Char**p=a;
p++;
cout<<*p<<endl; Output the
function Pointers:A pointer to a function that can be invoked by calling the pointer.
Example:
#include <stdio.h>
#include <io.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int max (int a, int b)
{return
a>b?a:b;
}
int main (int argc, char* argv[])
{
int a=2,b=6,c=3;
int max (int, int);
Int (*f) (int, int) =&max;
cout<< (*f) (*f) (a,b), c);
return 0;
}
Output:/
*
6
* *
pointer array: a set of pointers to a type (the address is stored in each array variable)
int* PTR[10];
array pointer: A pointer to an array of types
int v[2][10]={{1,2,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 one
cout<<* (*a+1 ) <<endl; Output 2
cout<<* (a[0]+1) <<endl;//Output 2
cout<<* (a[1]+1) <<endl;//Output
cout< <a[0]<<endl; Output V[0] First address
cout<<a[1]<<endl;//output V[1] first address
the difference between int* P and (int*) p
int* p; P is a pointer variable (int*) that points to the shape of the shape P
;//casts a P type to a pointer to an integer
array name equals pointer,& array name equals double pointer
The difference between char* str= "HelloWorld" and char str[]= "HelloWorld"
char* str= "HelloWorld";//Allocate global array, shared store char str[]= "HelloWorld";//allocate local array