C ++ pointer Summary

Source: Internet
Author: User

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"

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.