C语言第四课
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
struct Book
{
?? ?char name[20];//c語言程序設計
?? ?short prize;//55
};
int main()
{
?? ?
?? ?struct Book b1 = { "c語言程序設計",55 };
?? ?printf("書名:%s\n", b1.name);
?? ?printf("價格:%d元\n",b1.prize);
?? ?b1.prize = 15;
?? ?printf("修改后的價格%d\n", b1.prize);
?? ?return 0;
}
結構體的使用
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
struct Book
{
?? ?char name[20];//c語言程序設計
?? ?short prize;//55
};
int main()
{
?? ?
?? ?struct Book b1 = { "c語言程序設計",55 };
?? ?printf("書名:%s\n", b1.name);
?? ?printf("價格:%d元\n",b1.prize);
?? ?b1.prize = 15;
?? ?printf("修改后的價格%d\n", b1.prize);
?? ? struct Book *pb = &b1;
?? ? printf("%s\n", pb->name);
?? ? printf("%d\n", pb->prize);
?? ?
?? ?return 0;
}
結構體變量.成員
結構體指針->成員
strcpy(b1.name,"c++")字符串拷貝函數,左邊是目的地,右邊是內容。
學習(c/c++)
學習數據結構(DS)
學習系統&網絡(Linux+系統編程+網絡基礎+網絡編程)
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
//struct Book
//{
//?? ?char name[20];//c語言程序設計
//?? ?short prize;//55
//};
int main()
{
?? ?int age = 100;
?? ?if (age < 18)
?? ??? ?printf("weichengnian\n");
?? ?else if (age >= 18 && age <= 28)
?? ??? ?printf("qingnian\n");
?? ?else if (age > 28 && age < 50)
?? ??? ?printf("zhuangnian");
?? ?else
?? ??? ?printf("laobusi");
?? ?
?? ?return 0;
}
多次選擇其中使用else if
else與最近的if進行匹配
switch 跟default匹配
假如所有的case沒有,則走default!
?int ch = getchar();
?? ? putchar(ch);
一個是輸入字符,一個是輸出字符。
?while ((ch = getchar()) != EOF)
Ctrl?+z才會停止。
總結
- 上一篇: 梯度化一张图片
- 下一篇: loadrunner11下载