当前位置:网站首页>C语言——第一个程序、打印、变量和常量
C语言——第一个程序、打印、变量和常量
2022-07-26 22:49:00 【Lydialyy】
目录
一、C语言的特点:
灵活度高、效率高、可移植性高
二、第一个程序
1.软件:Dev-C++ 5.11
2.步骤:
文件→新建→源代码
运行→编译运行→(保存类型)C source files(*.c)→(文件名)test.c→保存
#include <stdio.h>
int main()
{
printf("Hello World\n");
return 0;
}3.代码运行结果

三、转义字符
| 转义字符 | 含义 |
| \a | 响铃(BEL) |
| \b | 退格(BS),将当前位置移到前一列 |
| \f | 换页(FF),将当前位置移到下页开头 |
| \n | 换行(LF),将当前位置移到下一行开头 |
| \r | 回车(CR),将当前位置移到本行开头 |
| \t | 水平制表(HT),跳到下一个TAB位置 |
| \v | 垂直制表(VT) |
| \\ | 表示反斜杠本身(\) |
| \' | 表示单引号(’) |
| \" | 表示双引号(") |
| \? | 表示问号(?) |
| \0 | 表示空字符(NULL) |
| \ddd | 1到3位八进制数所代表的任意字符 |
| \xhh | 1到2位十六进制所代表的任意字符 |
四、变量和常量
变量和常量是程序处理的两种基本数据对象。
1.变量
(1)变量的意义就是确定目标并提供存放的空间.
(2)变量名:变量名只能是英文字母(A-Z,a-z)和数字(0-9)或者下划线(_)组成。
命名规则:① 第一个字母必须是字母或者下划线开头;
② 变量名区分大小写;
eg:_FISHC ≠ fishc
③ 不能使用关键字来命名变量。
(3)关键字
| auto | break | case | char | const | continue | default | do |
| double | else | enum | extern | float | for | goto | if |
| int | long | register | return | short | signed | sizeof | static |
| struct | switch | typedef | union | unsigned | void | volatile | while |
| inline | restrict | _Bool | _Complex | _Imaginary |
| _Alignas | _Alignof | _Atomic | _Static_assert | _Noreturn | _Thread_local | _Generic |
(4)数据类型
- char — 字符型,占用一个字节
- int — 整型,通常反映了所用机器中整数的最自然长度
- float — 单精度浮点型
- double — 双精度浮点型
eg:int a;char b;float c;double d
(5)代码:
#include <stdio.h>
int main()
{
int a;
char b;
float c;
double d;
a = 520;
b = 'F';
c = 3.14;
d = 3.141592653;
printf("鱼C工作室创办于2010年的%d\n",a);
printf("I love %cishC.com!\n",b);
printf("圆周率是:%.2f\n",c);
printf("精确到小数点后9位的圆周率是:%11.9f\n",d);
return 0;
}运行结果:

2.常量
- 整型常量:520,1314,123
- 实型常量:3.14,5.12,8.97
- 字符常量 :普通字符:'L','O','V','E';转义字符:'\b','\t','\n'
- 字符串常量:“FishC”
- 符号常量:使用之前必须先定义
3.定义符号常量
(1) 格式:#define 标识符 常量
比如:- #define URL"http://www.fishc.com"
- #define NAME"鱼C工作室”
- #define BoSS“小甲鱼”
- #define YEAR 2010
- #define MONTH5
- #define DAY 20
代码:
#include <stdio.h>
#define URL "http://www.fishc.com"
#define NAME "鱼C工作室"
#define BOSS "小甲鱼"
#define YEAR 2010
#define MONTH 5
#define DAY 20
int main()
{
printf("%s成立于%d年%d月%d日\n",NAME,YEAR,MONTH,DAY);
printf("%s是%s创立的……\n",NAME,BOSS);
printf("%s的域名是%s\n",NAME,URL);
return 0;
}运行结果:

(2)标识符(identifier)
- 标识符只能是英文字母(A-Z,a-z)和数字(0-9)或者下划线(_)组成(eg:_ i_love_fishC_520)
- 第一个字母必须是字母或者下划线开头
- 标识符区分大小写(eg:_ FISHC ≠ fishc)
- 不能使用关键字来命名标识符
(3)字符串常量
- 字符:'F','I','S','H','C'
| 'F' | 'I' | 'S' | 'H' | 'C' |
- 字符串:
——"Hello World"
| 'H' | 'e' | 'l' | 'l' | 'o' | ' ' | 'W' | 'o' | 'r' | 'l' | 'd' | '\0' |
——"I love FishC.com!"
| 'I' | ' ' | 'l' | 'o' | 'v' | 'e' | ' ' | 'F' | 'i' |
| 's' | 'h' | 'C' | '.' | 'c' | 'o' | 'm' | '!' | '\0' |
边栏推荐
- 【mysql】mysql启动关闭命令以及一些报错解决问题
- 7.7 SHEIN希音笔试
- 6.30滴滴面经(一面+二面)
- HCIA(网络初级综合实验练习)
- Ospf基础配置应用( 综合实验: 干涉选举 缺省路由 区域汇总 认证--接口认证)
- Freytek central computing platform 360 degree sensing system solves the challenges behind NOA mass production
- Autojs learning - realize the display of date and lunar time
- [translation] explicit and implicit batch in tensorrt
- Static comprehensive experiment (comprehensive exercise of static route, loopback interface, default route, empty interface, floating static)
- OSPF static experiment
猜你喜欢

IS指标复现 文本生成图像IS分数定量实验全流程复现 Inception Score定量评价实验踩坑避坑流程

mgre的全连和星型拓扑实验

DF-GAN实验复现——复现DFGAN详细步骤 及使用MobaXtem实现远程端口到本机端口的转发查看Tensorboard

HCIA动态路由RIP基础实验

动态路由rip协议实验
![Unity Huatuo revolutionary hot update series [1]](/img/bc/ed480fc979c08c362784a3956d7fe2.jpg)
Unity Huatuo revolutionary hot update series [1]

关于在VS2022或者高级版本运行环境下遇到fopen,strerror等不安全的问题
![C language implementation of the small game [sanziqi] Notes detailed logic clear, come and have a look!!](/img/b9/ade9a808a3f6d24cd9825dc9b010c1.png)
C language implementation of the small game [sanziqi] Notes detailed logic clear, come and have a look!!
![[explain C language in detail] takes you to play with the choice (Branch) structure](/img/ca/7ee9f62a2478785c97684c7a0cc749.png)
[explain C language in detail] takes you to play with the choice (Branch) structure
![[explain C language in detail] takes you to play with loop structure (for_while_do while)](/img/d9/75053297873a5b5458514e7f557cdc.png)
[explain C language in detail] takes you to play with loop structure (for_while_do while)
随机推荐
6.29 Zhong'an Summer Internship
ViTGAN:用视觉Transformer训练生成性对抗网络 Training GANs with Vision Transformers
Text to image paper intensive reading rat-gan: recursive affine transformation for text to image synthesis
[explain C language in detail] takes you to play with the choice (Branch) structure
最新C语言入门与进阶 -史上最全最详细的C语言教程!! 第一节-总览C语言概括
OSPF static experiment
Solution: various error reports and pit stepping and pit avoidance records encountered in the alchemist cultivation plan pytoch+deeplearning (II)
6.28同花顺笔试
Js九九乘法表
Pseudo class of a element
ensp中的简单静态路由
a元素的伪类
[FPGA tutorial case 28] one of DDS direct digital frequency synthesizers based on FPGA -- principle introduction
JS——初识JS、变量的命名规则,数据类型
HCIA静态路由综合实验
2022年最新文本生成图像研究 开源工作速览(Papers with code)
TCP的三次握手与四次断开
TCP's three handshakes and four waves (brief introduction)
HCIA(网络初级综合实验练习)
7.16 多益网络笔试