C + + Learning (18) (C language part) pointer 2

Pointer
1. Overview of pointers
What is the pointer?
Pointer is an address is a constant
Int int a a is a variable
What does the pointer do?
Easy to use arrays or strings to process memory addresses like assembly language
2. Pointer variable
What is a pointer variable?
Is a "container" that can store addresses
Often, the pointer variable is read after the pointer, the address is used as the pointer, and the variable storing the address is called the pointer variable


3. Pointer assignment
Type specifier * variable name = address value;

int a=89;
Int * P = & A; defines a variable p of type int * (type and * are good friends)
Then assign the address of a to this variable & take the address symbol

 

 

 

 1 #include<stdio.h>
 2 int main()
 3 {
 4     //int a = 520;
 5     //int *p = &a;
 6     //printf("p=%d\n",p);
 7     //printf("a Address=%d\n",&a);
 8 
 9     //int a = 520;
10     //int *p = &a;//First, initialize when defining pointer variables
11     //int *pp;
12     //pp = &a;//Second, assign the address value of a variable to a pointer variable of the same type
13     ////Be similar to
14     //int c;
15     //c = 5;
16     //int *ppp = pp;//Assign a pointer variable to another pointer variable with the same data
17     //printf("ppp=%d\n",ppp);
18     //printf("pp=%d\n", pp);
19     //printf("pp=%d\n", &a);
20 
21     //int a = 5;
22     //char xiaoming = 'A';
23     //int *PangQi = &a;
24     //PangQi = (int*)&xiaoming;//Pointer assignment can only be of the same type. If you have to assign addresses of different types, you need to force the type conversion
25     //printf("%d\n",*PangQi);
26 
27     //int a = 4407873;//int Is 4 bytes 32 bits
28     //char *p = (char *)&a;//char Is 1 byte 8 bits
29     //printf("%s\n",p);//output ABC
30     ////ABCD 0100 0100  0100 0011 0100 0010 0100 0001
31 
32     //Quoting c There are two operators about pointer in language  *  &
33     /*
34     & Take the address sign int a & A to get the address of a
35     * Pointer operator or join operator between pointer operators
36     "*"Its function is to refer to the variable value pointed to by the pointer. The reference is actually the address of the variable
37     "To solve "is to find out what the address corresponds to
38     */
39     int xiaoming = 10000;
40     int *pangqi = &xiaoming;
41     *pangqi = 10000-8880;
42     printf("%d\n",*pangqi);
43 
44 
45 
46     getchar();
47     return 0;
48 }

 

 

 

 

2018-07-24  16:32:13 

Tags: C++

Posted on Fri, 31 Jan 2020 14:06:25 -0500 by doofystyle