#include <stdio.h>int main () { int i = 10;//an int variable, named i int *p;/ /defines a pointer variable //p = 10;//error that points to an integer, it is not possible to assign an integer directly to the pointer variable. Each variable in the &NBSP;//C language has its own memory address. The & symbol is the variable address operator. &i;//takes the address of the variable I. p = &i;//points the pointer variable p to the address of I. *p = 100;// Assign the value of the memory area that P points to 100; printf ("i = %d\n", i); int *p1 = &i; int a = *p;//* is the value of the pointer pointing to memory in C language //int b = null; int *p2 = null; int *p3;//defines a pointer variable that points to int, without assigning an initial value, which is a wild pointer to what memory address is not known. The //of the wild pointer is only the program itself, does not affect the operating system. //If you are doing a driver or kernel code, then it can be fatal and the operating system crashes. The //*p3 = 10;//field pointer is also called a dangling pointer, and cannot assign a value to the area of memory that the wild pointer points to. char c = ' a '; //p3 = &c;//in the C language, when the pointer is assigned to a value, be sure to type compatible unsigned int ui = 10; p3 = &ui; void *p4;//defines an untyped pointer. p4 = &i;//can assign any type of address to void * //p1 = p4;//(You can assign void * to any type of pointer variable in the C language). But the C + + statement is illegal printf ("*p4 = %d\n", * (int * P4); //P4 this value into a pointer, and then see what is inside the pointer printf ("*p = %d\n", &NBSP;*P3); printf ("a = % D\n ", a); getchar (); return 0;}
This article from "Soul Bucket Luo" blog, declined reprint!
C language pointers