C + +-pointer summary

Source: Internet
Author: User
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 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.