C pointer (1) pointer is the address

Source: Internet
Author: User

(1) the pointer is the address.

First, let's clarify the point that the pointer is the address. This is the first step in understanding pointers.

Intuitively, the variable address

 
Int main () {int Foo; int * foo_p; Foo = 5; foo_p = & Foo; printf ("foo... % d \ n ", foo); printf (" * foo_p... % d \ n ", * foo_p); printf (" & FOO... % P \ n ", & Foo); printf (" foo_p... % P \ n ", foo_p); printf (" & foo_p... % P \ n ", & foo_p); Return 0 ;}
Run


Notes:

    1. P in % P refers to pointer (pointer), which is used to print the content in the pointer variable.
    2. Sometimes % x is used to print the pointer. Although the result is the same, the meaning is completely different. % P: output the address of another variable stored in the pointer variable in an appropriate way (usually in hexadecimal format); % x: print the value of the variable in hexadecimal format. In addition, if % x is used to print pointer variables in my environment, the preceding 0 is omitted.
Pointer variable
The variable name is in the upper left corner, the variable address is in the upper right corner, and the variable storage content is in the middle.
Check the memory size allocated for each basic type in my environment
Int main () {printf ("sizeof (char )... % d \ n ", sizeof (char); printf (" sizeof (INT )... % d \ n ", sizeof (INT); printf (" sizeof (float )... % d \ n ", sizeof (float); printf (" sizeof (double )... % d \ n ", sizeof (double); printf (" sizeof (int *)... % d \ n ", sizeof (int *); Return 0 ;}

In my environment, the size of pointer type allocation is sizeof (int *) = 4; that is to say, 4 bytes are used to store the variable address, this is also the result of most environments. Based on this result, we will discuss it later. As for the C standard, the size of the pointer type is not specified, and the specific size depends on the specific environment.





C pointer (1) pointer is the address

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.