C Pointer base

Source: Internet
Author: User

Any data type we can think of as a mold, and then into various types of data;

Any mold is of its particular size.

int *p;

With sizeof test, sizeof (p) or sizeof (int) is 4byte, so it can be defined as:

A mold of type int carves a space of 4 bytes in memory and then names the 4 byte size space as P. Also limit the 4 bytes of contiguous space can only store a memory address, even if you deposit any other data, will be treated as an address, and the memory address of the beginning of a continuous 4 bytes can only store an int data.

We refer to p as the pointer variable, and memory at the memory address stored in P is called P-pointing memory.

int *p = null and *p = NULL

The first one is initialization. What is the initial, that is, the address of P itself is initially 0.

*p = null is the initial content of P pointing to 0.

Double *p = NULL;
printf ("%d\n", sizeof (p)); is always 4byte, the space of the pointer variable itself
int *pt = NULL;
printf ("%ox\n", PT); View PT value As ox through the compiler
int i = 10;
int *pp = &i;
printf ("%d\n", I);
*PP = NULL;
printf ("%d", I); The value of the last I becomes 0

Look again:

int *p;

*p = NULL;

A pointer variable p is defined, but the address of P itself is not known, perhaps it is illegal, the role of subsequent may also be error.

Improved:

int i = 20;

int *p = &i;

*p = NULL;

Stores a value to the specified memory address:

Assuming that the value 0x100 stored on the address of 0x12ff7c, then this address can be obtained: I can arbitrarily define a variable, such as int i, and then take the address, then this address must be accessible.

int *p = (int *) 0x12ff7c;

*p = 0x100;

You can also do this: * ((int *) 0x12ff7c) = 0x100;

This article is from the "Genius Strength" blog, please be sure to keep this source http://8299474.blog.51cto.com/8289474/1583540

C Pointer base

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.