一、字符(char) 数字(int) 屏幕显示
'\n' 10 换行
'\0' 0 空格
'\t' 9 tab键
'\\' 92 \
'1' 49 1
! 33 !
二、字符串
char *a = "123";
int b = a[3]; 那么b就等于0,相当于a[0]是‘1’,a[1]是'2',a[2]是'3',a[3]是‘\0’
char *a[] = {"123","345"};
a[0][3] a[1][3]都是字符'\0'
三、
char *a = "123";
if(a[3] == 0) ....//字符'/0'变成数字0
char a[2];
a[0] = 'a';
a[1] = 0;//数字变成字符'/0',表示结束
四 、
char *y = "abc";
char *z;
z=malloc( strlen(y)+1 );
strcpy(z,y);
之所以要加1,是因为最后的位置要存‘\0’,strcpy之后,最后一位也被赋值为'\0'
strcpy源码:
char *
strcpy (dest, src)
char *dest;
const char *src;
{
char c;
char *s = (char *) src;
const ptrdiff_t off = dest - s - 1;
do
{
c = *s++;
s[off] = c;
}
while (c != '\0');
return dest;
}
五、NULL
#include <stdio.h>
int main()
{
int *a = NULL;
if(a == 0)
printf("%c",'2');
return 0;
}
#include <stdio.h>
int main()
{
int *a = 0;
if(a == NULL)
printf("%c",'2');
return 0;
}
NULL用来修改指针,表示a没有指向任何地址(空指针),NULL和0是一样的意思,0不是数字0,是编号0。