1.结构体
#include <stdio.h>
struct Book
{
char name[20];
int price;
};
int main(){
struct Book b1 = {"C语言", 55};
printf("书名%s\n", b1.name);
printf("原价%d\n", b1.price);
b1.price = 15;
printf("修改后价格%d\n", b1.price);
return 0;
}//结果为书名C语言
??????原价55
??????修改后价格15
2.指针型
#include <stdio.h>
struct Book
{
char name[20];
int price;
};
int main(){
struct Book b1 = {"C语言", 55};
struct Book *pb=&b1;
printf("书名%s\n",(*pb).name);??//[printf("书名%s\n",pb->name);
printf("原价%d\n", (*pb).price);?//?printf("原价%d\n",pb->price);]二者等价
return 0;???????????????????????????//?pb->意思是指向成员
}//结果为书名C语言
??????原价55
改变数组中的数据,且其中的成员是字符串要用strcpy(string copy字符串拷贝)且头文件要加上
#include <string.h>
#include <stdio.h>
#include <string.h>
struct Book
{
char name[20];
int price;
};
int main(){
struct Book b1 = {"C语言", 55};
struct Book *pb=&b1;
strcpy(b1.name, "math"); ?
printf("书名%s\n",pb->name);
printf("原价%d\n",pb->price);
return 0;
}
3.break;和continue;的区别
#include <stdio.h>
int main(){
int ch = 0;
while ((ch = getchar()) != EOF)
{
if (ch<'0' || ch>'9')
break;???//【continue;】break是终止循环,直接结束进程。而continue putchar(ch);??则是终止本次
//循环,还会将值返回判断是否满足条件。
}
return 0;
}
|