如上两张是C语言基础的思维导图:从上图看了C语言基础知识包括如下:
I/O 函数: 需要掌握各种输入输出函数(printf | scanf | getchar | putchar | puts | gets),以及printf中所用到的格式控制符和对齐输出 (%5d 等等)
语法:和其他语言一样必须要掌握其语法,如判断 循环 条件 选择 continue break goto 等等辅助语句的用法
函数:相当于其他高级语言中的方法,有自己写的函数和库函数,使用库函数时需要导入头文件以及库的加载路径,其他语言使用系统函数时也是要导入命名空间的
数组:掌握数据的本质,定义,在内存中的存储布局,数组两中访问数据的方式,数组之间的赋值(不能使用赋值运算符),数组的大小(实参数组的大小和形参数组的大小不一样的,需要注意,用sizeof测试)
字符串数组:掌握字符串的定义,字符串数组和字符串指针的区别,字符串指针所指向的地址如何在内存中分配,字符串的一些操作函数
如上总结的知识点是上部分,主要看标红的难点。
1.变量存储分配
2.字符串数组和字符串指针的区别
2.1指针自加误区
#include <stdio.h>
int main(void)
{
char *p="beautiful";
printf("%c\n",*p);
getchar();
return 0;
}
如上代码:
2.2 数组和指针的区别
2.2.1 误区1
#include <stdio.h>
#include <stdlib.h>
int main()
{
/*char str[]="hello";
str[0]='H';
printf("%s\n",str);*/
char *str="hello";
*str='H';
printf("%s\n",str);
system("pause");
return 0;
}
2.2.2 误区2
#include <stdio.h>
#include <stdlib.h>
int main()
{
char str[]="hello";
while (*str!='\0')
{
putchar(*str++);
}
char *str="hello";
while (*str!='\0')
{
putchar(*str++);
}
system("pause");
return 0;
}
上续代码,用指针没问题,用数组就出错
2.2.3 误区3
#include <stdio.h>
#include <stdlib.h>
int main()
{
char str[5];
str="nice";
char *str;
str="nice";
system("pause");
return 0;
}