const int和int const相同。
const int *p定义的是指向常量的整型指针.不能通过指针改变所指对象的值,但指针本身值可以改变。 int* const p 定义的是指针常量,指针本身的值不能改变。
const int *p与int const *p相同。
例子:
#include <stdio.h>
#include <stdlib.h> int main()
{ const int a = 1; // a = 2; //wrong int const b = 2;
// b = 3; //wrong int *c = (int*)malloc(sizeof(int)); *c = 4; //right const int *d = (int*)malloc(sizeof(int));
// *d = 4; //wrong d = c; //right int* const e = (int*)malloc(sizeof(int));
*e = 6; //right // e = c; //wrong int const *f = (int*)malloc(sizeof(int));
// *f = 7; //wrong f = c; //right return 0; } |
|
来自: dingzi4178 > 《程序语言》