const
时间:2010-06-02 来源:checl1987_EE
#include<stdio.h>
/* const usage
* const int *a= b; //b is not variable, do not change b via a.
* int * const a = b //a is not variable, do not change a.
* const int * const a = b //a and b are not variable
*/
int main(int argc, char *argv[])
{
int str[4] = {1,2,3,4};
int str_dif[4] = {5,6,7,8};
const char *a = "abc";
*a = 4; //error: assignment of read-only location
int * const p = str;
p = str_dif ; // error: increment of read-only variable ‘p’
const int * const q = str; //combine up 2
return 0;
}
/* const usage
* const int *a= b; //b is not variable, do not change b via a.
* int * const a = b //a is not variable, do not change a.
* const int * const a = b //a and b are not variable
*/
int main(int argc, char *argv[])
{
int str[4] = {1,2,3,4};
int str_dif[4] = {5,6,7,8};
const char *a = "abc";
*a = 4; //error: assignment of read-only location
int * const p = str;
p = str_dif ; // error: increment of read-only variable ‘p’
const int * const q = str; //combine up 2
return 0;
}
相关阅读 更多 +