The pointer must look!!! Detailed parsing of pointers

Source: Internet
Author: User

1. The difference between a pointer and a general variable
A variable is a data type used to store data, which is actually an address, and the data stored in the address is the value that the variable stores. You use scanf to assign values to a variable (such as a): scanf ("%d", &a); &a represents the address of variable a, which means entering a number and then putting the number in the address of a variable called a. Here's another way to assign a value to a. int *b = &a; scanf ("%d", b). Because the scanf parameter is ("A number", the address of the destination variable).

The pointer is a special variable, and it exists inside the stack, but the data it stores is the address of the other variable. Like what
int b = 1; int *a = &b; This means that a variable is defined and then its stored value is the address of variable B. So a = (address of b), *a = (the value (i.e. 1) of the address of B is stored). The pointer variable type int * float* double* char* depends on the data type of the normal variable it points to when you define the pointer variable.

2. Level Two Hands
int a = 1; int * b = &a; int **c = &b;
Here a pointer b is defined to store the address of a, and C is a level two pointer to store B's address. So C = (address of b), *c = (the value of the address stored by B, that is, B, that is, the address of a), **c = (the value of the address stored in B, that is, *b, that is, a stored value)

3. Replace array
int a[3] = {n/a};
int *b = A;
b = &a[0], *b = a[0], b+1 = a[1], * (b+1) = A[1], (b+2) = a[2],* (b+2) = a[2]

int A[3][3] = {{1,2,3},{4,5,6},{7,8,9}}
int *b[3];
int **c;
b = a ====> B = a[0], B = {)
b = A; B[1] = a[0][1];

c = A; c = {{1,2,3},{4,5,6},{7,8,9}} c[1] = a[1] = {4,5,6}
C[2][2] = a[2][2]

Hope can solve your doubts!!!

The pointer must look!!! Detailed parsing of 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.