C language pointer

What exactly is it a pointer?

Pointer is a pointer to the address of the variable as a variable of type char character as its value, and the value of Int is an integer type variable, the value represented by the address pointer variable

If a pointer variable named pas, then you can get about the statement:

pas=&passwd 

Here is the address assigned to the pas passwd

 

 Pointer need symbols: * &

Address operator (&): followed by a variable name, the address of the variable & give

E.g:

& Num num represents the variable address

Indirection operator (*): here to say here do not represent the binary operation * * (multiplication), when followed by a name or an address pointer, * given point value stored in the address

E.g:

a = 2;

pas = & num; // pas pointer pointing num

vps = * pas; // assigns the value of the point pas vps

The above statement is assigned to the 2 vps

Pointer declaration:

int * pi; // pi is a pointer to an integer variable

char * p; // p is a pointer to a pointer variable character

float * p, * g; // p and g are floating-point pointer variable

Summary: type identifier indicates the type of points to be variable, and the asterisk (*) is a variable pointer

         Statement Int * pi; means pi is a pointer, and is of type int * pi

Next, write a piece of code to see results

#include <stdio.h>
 void Chang ( int * P, int * Q); // declare a pointer 
int main ( void ) {
 int X = . 5 , Y = 15 ;
the printf ( " x =% Dy =% D \ n- " , x, y); // this is a common output 
Chang (& x, & y); // function to pass the x and y address rather than its value, This means that the function prototype declaration chang parameter q, p uses the address as their value, therefore, they should be declared as a pointer. It is declared before 
the printf ( " X1 = Y1 = D% D% \ n- " , X, Y);
renturn 0 ;
}
void chang(int *p,int *q){
int temp;
temp=*p;
*p=*q;
*q=temp;
}
/*
When the exchange function, the first function using the x and y exchanged, it can access the x, y variables and operators by the pointer *, a corresponding function may be obtained storage address data, so that data can change,

*/

operation result:

 

Guess you like

Origin www.cnblogs.com/X404/p/12078062.html