The most powerful of C language--pointers

Source: Internet
Author: User

The pointer is inseparable from the address, referring to the pointer should think of the address, because in the C language, the value of the pointer variable is an address, through which it can point to the address of the memory location, you can access the memory location of the content through this pointer variable.

The method that defines a pointer variable is the same as the other variables:

int *a;

Char *b;

...

Here the pointer variable A is a pointer to the shaping, where the value of a is the address of the first byte of the four bytes of the shaping space pointed to, B is a pointer to the character type, and the value of B is the address of the character.

To initialize a pointer:

int a=123;

int *p=&a;

int *pi;

p=&a;

This defines the shaping variable A, which defines the pointer p, PI, and they all point to a, both of which are initialized so that they point to a.

Operation of the pointer:

The process of accessing the address it points to by a pointer is called an indirect access or a pointer dereference, and its operator is *. For example, the following definition

int a=12;

int b;

int *p;

p=&a;

B=*p;

Define the pointer p it points to the variable a, if you want to assign a value to B, you can use the pointer p to manipulate, the pointer p to dereference *p can get p point to the content of the address, you can assign the value of a to B.

Pointers and Arrays:

The value of the array name is a pointer constant, that is, the address of the first element of the array, when the pointer is dereferenced and an array of subscript access is equivalent, we can assume that the subscript access operator [] and the reference operator * can be swapped with each other.

int arr[5]={1,2,3,4,5};

The value of arr[0] is 1

The value of *arr is also 1, which is equivalent to * (arr+0)

How to feel the more write more feel the more useless!!!!

This article is from the "Aiali" blog, make sure to keep this source http://aliddd.blog.51cto.com/10780547/1711614

The most powerful of C language--pointers

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.