c 语言中带const 的指针小记
一、有如下代码:
int age = 25;
const int *pAge = &age;
上面的代码表示:
1、指针变量pAge存放变量age的地址,且不能通过 *pAge = 30,来改变指针变量pAge所指向的存储空间的值,但是 对于 age = 30,则是没有问题的。
2、pAge 本身可以再存放其它变量的地址,也可以指向NULL,如 pAge = NULL;是正确的。
二、有如下代码:
int age = 25;
int *const pAge = &age;
上面的代码表示:
1、指针变量pAge用const限定了,所以pAge不能再存储其它变量的值,也不能指向NULL;所以 pAge = NULL;是不正确的
2、对于*page = 30,是正确的;
三、有如下代码:
int age = 25;
const int *const pAge = &age;
上面的代码表示:
1、指针变量pAge不能再存储其它变量的值或NULL
2、对于通过*pAge = 30 的形式改变指针变量pAge指向的存储空间的值是不正确的
3、对于 age = 30 没有问题
相关文档:
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 100
main()
{
FILE *fp;
if ( (fp = fopen( "c:\\a.txt", "r" )) == NULL ) printf("ERROR!\n");
int tmp[MAXSIZE];
int i;
for ( i=0; i<MAXSIZE; i++ )
{
tmp[i] = 0; ......
这几天我安装了一个Linux系统,想在里面学一下C语言的编写,发现在里面运行有一个好奇怪的现象:如下面
#include<stdio.h>
void mian(){
printf("hello world!");
}
输出没有结果!搞的我看了半天,程序没有错误啊!怎么这样!后来我把程序改为
#include<stdio.h>
void mian(){
printf("hello ......
Turbo C 2.0 函数中文说明大全
分类函数,所在函数库为ctype.h
int isalpha(int ch) 若ch是字母('A'-'Z','a'-'z')返回非0值,否则返回0
int isalnum(int ch) 若ch是字母('A'-'Z','a'-'z')或数字('0'-'9'),返回非0值,否则返回0
int isascii(int ch) 若ch是字符(ASCII码中的0-127)返回非0值,否则返回0
int iscntrl(int ......
C语言中有几个基本输入函数:
//获取字符系列
int fgetc(FILE *stream);
int getc(FILE *stream);
int getchar(void);
//获取行系列
char *fgets(char * restrict s, int n, FILE * restrict stream);
char *gets(char *s);//可能导致溢出,用fgets代替之。
//格式化输入系列
int fscanf(FILE * r ......