Perspective

xiaoxiao2021-03-06  14

INT A = 1;

INT * b = & a;

INT ** C = & B;

Printf ("& a:% d \ n", & a);

Printf ("B:% D \ N", B);

Printf ("& b:% d \ n", & b);

Printf ("* b:% d \ n", * b);

Printf ("** c:% d \ n", ** c);

Printf ("* c:% d \ n", * c);

Printf ("C:% D \ N", C);

Printf ("& C:% D \ N", & C);

operation result:

Use the VS2010 with VS2010 under Windows:

& a = b = * c = is address

A = * b = ** c = 1 is a value

& b = c is address

& c is address

When you declare, you can't have two heads.

First-level pointer B corresponds to one level pointer & a

Secondary pointer C corresponds to secondary pointers & b

Pointer to correspond to the level!

Aggregate string

Char * a = "abc";

Char * b = a;

Printf ("a:% s \ n", a);

Printf ("B:% S \ N", B);

Output:

A: ABC

B: ABC

See a program understanding address

Char * p = "a";

Char * p1 = p;

INT A = 1;

INT * b = & a;

Printf ("p:% s \ n", p);

Printf ("* p:% d \ n", * p);

Printf ("& P:% D \ N", & P);

Printf ("& P [0]:% D \ N", & P [0]);

Printf ("P1:% S \ N", P1);

Printf ("* p1:% d \ n", * p1);

Printf ("& P1:% D \ N", & P1);

Printf ("& P1 [0]:% D \ N", & P1 [0]);

Printf ("* b:% d \ n", * b);

Printf ("B:% D \ N", B);

Printf ("& a:% d \ n", & a);

Printf ("& b:% d \ n", & b);

Note: When the pointer points to the string pointer, it will not bring *, and the pointer is a value of the value pointer & address.

Char * menu [] = {

"ABC",

"DEF",

"MNP",

NULL,

}

Main ()

{

CHAR ** OPT;

Opt = menu;

Printf ("% d \ n", OPT);

Printf ("% s \ n", * OPT);

}

Output:

134518260ABC

Pointer role

Use only pointer

SWAP (int * a, int * b)

{

INT C = 0;

C = * a;

* a = * b;

* b = C;

}

int main ()

{

INT A = 1;

INT C = 2;

INT * B = & C;

SWAP (& A, B);

Printf ("a:% d \ n", a);

Printf ("B:% D \ n", * b);

Return 0;

}

Pointer using a pointer

SWAP (int * a, int ** b)

{

INT C = 0; c = * a;

* a = ** b;

** b = C;

}

int main ()

{

INT A = 1;

INT C = 2;

INT * B = & C;

SWAP (& A, & B);

Printf ("a:% d \ n", a);

Printf ("B:% D \ n", * b);

Return 0;

}

Passing the address of the pointer to the pointer of the pointer, the function is called!

Not a function call, directly assign a value.

转载请注明原文地址:https://www.9cbs.com/read-48087.html

New Post(0)