const function

const int * p // modified * p, p pointer may change, but the value of * p is unchanged

example:

int a = 5;

int b = 10;

const *p = &a;

* P = 10; // not

p = & b; // can

 

 

int * cont p // modified p, p pointer immutable, but can be changed * p value

example:

int a = 5;

int b = 10;

int *const p  = &a;

p = & b; // not

* P = 11; // can

 

const major global variables that can not be changed

 

But not impossible to change const

#include<stdio.h>

int main () {

const  int c =30;

int *d = &c;

*d = 40;

printf("c = %d",c)

return 0;

}

The result is 40.

Guess you like

Origin www.cnblogs.com/zijidefengge/p/12154526.html