C ++ pointer

Source: Internet
Author: User
When the value of a pointer expression is a char * type pointer, the output pointer does not output the pointer value (address), but outputs the pointer to the value (that is, the header address). For example:
Int A, * ap = &;
Char * CP;
CP = "output ";
Cout <AP <''<CP <Endl;
Cout <(void *) CP <Endl;
After these statements are executed, the result is:
0x0065fdf4 output
0x000000b4
Only by converting a character pointer to a void * type value can the true address value be output.
Because the pointer is the address in the memory, as long as it is the address, it points to the first address of a string or the address of a character in the middle of the string, when this address is output, it is the sub-string that is included in the end mark of the string starting with this address. For example:
Char S1 [] = "stringpointer ";
Cout <& S1 [6] <Endl; // & S1 [6] is equivalent to S1 + 6
Program Output result:
Pointer
Here & S1 [6] is the address corresponding to the character P, which can be regarded as a pointer. However, because S1 is a string, the output is
Sub-string, you can perform a pointer operation on & S1 [6], such as :( void *) & S1 [6] to output the real address, * & S1 [6] outputs the real location
The character corresponding to the address, which is equivalent to S1 [6.

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.