当前位置:网站首页>最新C语言入门与进阶 -史上最全最详细的C语言教程!! 第一节-总览C语言概括
最新C语言入门与进阶 -史上最全最详细的C语言教程!! 第一节-总览C语言概括
2022-07-26 22:48:00 【AF帆_】
C语言入门到进阶—入门第一节
前文
从本文开始,我们即将系统的进行C语言的入门到进阶教学,大纲如下:
本节文章目录
前言
从本节开始我们正式开始C语言的入门学习
一、数据类型
以下为我们常用的数据类型
为什么会存在如此多的数据类型?其实是为了更加丰富的表达生活中的各种值。
例如:我们在描述年龄,日期时我们使用整形类型。当我们描述体重,圆周率等等时我们常使用浮点数。描述字母,字符时使用字符型。
1.各个数据的大小
我们所有的数据都需要储存在内存中,那么我们常使用的数据都是多大呢?
(1)我们此时了解下我们常使用的各种内存大小单位
bit-比特位
byte 字节 (1字节等于8比特位)
KB =1024 byte
MB=1024KB
GB=1024MB
TB=1024GB
PB=1024TB
(2)计算大小的内置函数 sizeof()
计算如下:
二、变量常量
生活中的有些值是不变的(比如:圆周率,性别(通俗来说)等等)
有些值是可变的(比如:年龄,体重)。
1.变量
(1)定义变量的方法
代码如下(示例):
int age = 150;
float weight = 45.5f;
char ch = 'w';
(2)变量的分类
#include <stdio.h>
int global = 2019;//全局变量
int main()
{
int local = 888;//局部变量
int global = 2022;//局部变量
printf("global = %d\n", global);
return 0;
}
//打印出的结果是 2022
总结:
当局部变量和全局变量同名的时候,局部变量优先使用。
(3)变量的作用域与生命周期
作用域
作用域(scope)是程序设计概念,通常来说,一段程序代码中所用到的名字并不总是有效/可用
的
而限定这个名字的可用性的代码范围就是这个名字的作用域。
- 局部变量的作用域是变量所在的局部范围。
- 全局变量的作用域是整个工程。
生命周期
变量的生命周期指的是变量的创建到变量的销毁之间的一个时间段
1.局部变量的生命周期是:进入作用域生命周期开始,出作用域生命周期结束。
2.全局变量的生命周期是:整个程序的生命周期。
2.常量
C语言中的常量分为以下以下几种:
字面常量
const 修饰的常变量
#define 定义的标识符常量
枚举常量
#include <stdio.h>
enum Sex
{
MALE,
FEMALE,
SECRET
};
//括号中的MALE,FEMALE,SECRET是枚举常量
int main()
{
//字面常量演示
3.14;//字面常量
1000;//字面常量
//const 修饰的常变量
const float pai = 3.14f; //这里的pai是const修饰的常变量
pai = 3.14;//是不能直接修改的!
//#define的标识符常量 演示
#define MAX 100
printf("max = %d\n", MAX);
//枚举常量演示
printf("%d\n", MALE);
printf("%d\n", FEMALE);
printf("%d\n", SECRET);
//注:枚举常量的默认是从0开始,依次向下递增1的
return 0;
}
三、字符串 转义字符
字符串
“hello world\n”
这种由双引号(Double Quote)引起来的一串字符称为字符串字面值(String Literal),或者简称字符 串。
注:字符串的结束标志是一个 \0 的转义字符。在计算字符串长度的时候 \0 是结束标志,不算作字符串 内容。
#include <stdio.h>
(突出'\0'的重要性)
int main()
{
char arr1[] = "bit";
char arr2[] = {
'b', 'i', 't'};
char arr3[] = {
'b', 'i', 't', '\0'};
printf("%s\n", arr1);
printf("%s\n", arr2);
printf("%s\n", arr3);
return 0;
}

我们定义字符串时有两种常用的定义方法:
char arr[]=“”;
char arr[]={};
在使用{}定义时,我们可以这样理解 如果我们不人为加入结束标志\0的话,printf函数会在内存中不断地向下打印,寻找结束标志\0,所以第二句会出现乱码。 出了认为加入\0之外,我们人为给前面的[]中规定大小时也可以达到这样的目的
大小为:定义的字符数+一个预留给\0的位置
转义字符
转义字符顾名思义就是转变意思。

我们发现并没有按照理想情况打印,这时就需要用到转义字符。
转义字符 释义
\? 在书写连续多个问号时使用,防止他们被解析成三字母词
\ ’ 用于表示字符常量’
\“ 用于表示一个字符串内部的双引号
\ \ 用于表示一个反斜杠,防止它被解释为一个转义序列符。
\a 警告字符,蜂鸣
\b 退格符
\f 进纸符
\n 换行
\r 回车
\t水平制表符
\v 垂直制表符
\ddd ddd表示1~3个八进制的数字。
\xdd dd表示2个十六进制数字。
总结
例如:以上就是今天要讲的内容,本文仅仅简单介绍了数据结构,变量常量,字符串,转义字符的基本内容。
边栏推荐
- OSPF在MGRE环境下的实验
- Text to image intensive reading df-gan:a simple and effective baseline for text to image synthesis
- MySQL stored procedure function
- SQL anti injection regular expression
- Run NPM run dev to run 'NPM audit fix' to fix them, or 'NPM audit' for details
- mysql存储引擎及其区别
- Solution: various error reporting and pit stepping and pit avoiding records encountered in the alchemist cultivation plan pytoch+deeplearning (III)
- (atcoder contest 144) f - fork in the road (probability DP)
- 通过对射式红外传感器计次实验讲解EXTI中断
- 6.28大华笔试
猜你喜欢

测开基础 日常刷题 (持续更新ing...)

Removal and addition of reference types in template and generic programming
![[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

Gan's training skills: alchemist cultivation plan - generative confrontation network training, participation and improvement

Text to image paper intensive reading rat-gan: recursive affine transformation for text to image synthesis

Introduction to network - Introduction to home networking & basic network knowledge

MySQL index

Text to image intensive reading df-gan:a simple and effective baseline for text to image synthesis

FID index reproduction step on the pit to avoid the pit text generation image FID quantitative experiment whole process reproduction (FR é Chet inception distance) quantitative evaluation experiment s

Beyond hidden display ellipsis
随机推荐
Talking about server virtualization & hyper convergence & Storage
6.28同花顺笔试
[explain C language in detail] takes you to play with loop structure (for_while_do while)
STM32_HAL_SUMMARY_NOTE
GAN的训练技巧:炼丹师养成计划 ——生成式对抗网络训练、调参和改进
Hash索引和B+树相关知识
Js九九乘法表
count(*)为什么很慢
Text to image intensive reading df-gan:a simple and effective baseline for text to image synthesis
Solution to high collapse
指针常量与常量指针详细讲解
Beyond hidden display ellipsis
Acwing 1057. stock trading IV
通过对射式红外传感器计次实验讲解EXTI中断
Text to image论文精读DF-GAN:A Simple and Effective Baseline for Text-to-Image Synthesis一种简单有效的文本生成图像基准模型
7.16 多益网络笔试
[volatile principle] volatile principle
行,表,页,共享,排他,悲观,乐观,死锁
6.28大华笔试
Shell programming specifications and variables

