int x[10]; x++; //illegal int* p = x; p++; //legal
char string[] = "hello";
printf("%s\n",string);
char *str = "hello"
char *str = "hello"; *(str+1) = 'w'; // 错误
char *str;
scanf("%s", str);
/* str是一个野指针,他并没有指向某一块内存空间,所以不允许这样写。如果给str分配内存空间是可以这样用的 */
/********* 数组的方法****************/
char name[20];
scanf("%s",name);
/************* 给字符针针分配内存空间的办法***********/
char *name;
name=(char*)malloc(50); //此时name已经指向一个刚刚分配的地址空间。
scanf("%s",name);
char *test() {
return "hello";
}
int main(int argc, const char * argv[]) {
char names[10];
names = test();
return 0;
}
int sum(int a,int b)
{
return a + b;
}
int (*p)(int,int);
p = sum;
int minus(int a, int b)
{
return (a - b);
}
int add(int a, int b)
{
return (a + b);
}
int myFunction(int a, int b, int (*funcP) (int, int))
{
return funcP(a, b);
}
int main()
{
int minusResult = myFunction(10, 20, minus);
int addResult = myFunction(10, 20, add);
...
return 0;
}
/*
函数指针能让程序更灵活,比如后续有乘、除函数的时候,只需实现这两个函数然后在主函数调用myFunction函数即可。如果是多人协作,不同的人写不同的功能,如果我们来写myFunction那么基本就不用修改就可以一直使用,非常灵活。
*/
int result = p(10, 10);
int result = (*p)(10, 10);
struct Student {
char *name;
int age;
};
struct Student stu;
struct Student {
char *name;
int age;
} stu;
struct Student {
char *name;
int age;
};
struct Student stu;
struct Student newStu;
struct {
char *name;
int age;
} stu;
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有