当前位置:网站首页>The latest C language introduction and advanced - the most complete and detailed C language tutorial in history!! Section 1 - overview of C language
The latest C language introduction and advanced - the most complete and detailed C language tutorial in history!! Section 1 - overview of C language
2022-07-27 02:15:00 【AF sail_】
C Language introduction to advanced — Introduction section 1
above
Start with this article , We are about to proceed systematically C Language introduction to advanced teaching , The outline is as follows :
Contents of this section
Preface
From this section, we officially begin C Introduction to language learning
One 、 data type
The following are our common data types 
Why are there so many data types ? In fact, it is to express various values in life more abundantly .
for example : We are describing age , We use an integer type for dates . When we describe weight , We often use floating-point numbers for PI and so on . Description letter , Use character type when writing characters .
1. The size of each data
All our data needs to be stored in memory , So how big is the data we often use ?
(1) At this time, let's learn about the various memory size units we often use
bit- bits
byte byte (1 Bytes equal to 8 bits )
KB =1024 byte
MB=1024KB
GB=1024MB
TB=1024GB
PB=1024TB
(2) Built in function for calculating size sizeof()
The calculation is as follows :
Two 、 Variable constant
Some values in life are constant ( such as : PI , Gender ( Generally speaking ) wait )
Some values are variable ( such as : Age , weight ).
1. Variable
(1) How to define variables
The code is as follows ( Example ):
int age = 150;
float weight = 45.5f;
char ch = 'w';
(2) Classification of variables
#include <stdio.h>
int global = 2019;// Global variables
int main()
{
int local = 888;// local variable
int global = 2022;// local variable
printf("global = %d\n", global);
return 0;
}
// The printed result is 2022
summary :
When a local variable has the same name as a global variable , Local variables take precedence .
(3) The scope and life cycle of variables
Scope
Scope (scope) It's a programming concept , Generally speaking , The names used in a program are not always valid / You can use
Of
The scope of the code that defines the usability of the name is the scope of the name .
- The scope of a local variable is the local scope of the variable .
- The scope of global variables is the whole project .
Life cycle
The life cycle of a variable is the period between the creation of a variable and its destruction
1. The life cycle of a local variable is : Enter the scope lifecycle begins , Out of scope life cycle ends .
2. The life cycle of global variables is : The whole life cycle of the program .
2. Constant
C Constants in a language can be divided into the following categories :
Literal constants
const Modified constant variable
#define Defined identifier constant
Enumeration constants
#include <stdio.h>
enum Sex
{
MALE,
FEMALE,
SECRET
};
// In brackets MALE,FEMALE,SECRET It's an enumeration constant
int main()
{
// Literal constants demonstrate
3.14;// Literal constants
1000;// Literal constants
//const Modified constant variable
const float pai = 3.14f; // there pai yes const Modified constant variable
pai = 3.14;// It can't be modified directly !
//#define The identifier constant for demonstration
#define MAX 100
printf("max = %d\n", MAX);
// Enumeration constants demonstrate
printf("%d\n", MALE);
printf("%d\n", FEMALE);
printf("%d\n", SECRET);
// notes : The default of enumeration constants is from 0 Start , Increase in descending order 1 Of
return 0;
}
3、 ... and 、 character string Escape character
character string
“hello world\n”
This is made up of double quotation marks (Double Quote) A string of characters is called a string literal (String Literal), Or abbreviated characters strand .
notes : The end of a string is a \0 The escape character of . When calculating the length of a string \0 It's the end sign , Does not count as a string Content .
#include <stdio.h>
( prominent '\0' Importance )
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;
}

There are two common ways to define strings :
char arr[]=“”;
char arr[]={};
In the use of {} Definition time , We can think of it this way If we don't add the end sign artificially \0 Words ,printf Function will continuously print down in memory , Look for the end sign \0, So the second sentence will appear garbled . Out think join \0 outside , We artificially give to the front [] This purpose can also be achieved when the size is specified in
The size is : Number of characters defined + One is reserved for \0 The location of
Escape character
Escape characters, as the name suggests, change meaning .

We found that it didn't print as expected , At this time, you need to use escape characters .
Escape character paraphrase
\? Use... When writing multiple consecutive question marks , Prevent them from being parsed into three letter words
\ ’ Used to represent character constants ’
\“ Double quotation marks used to represent the inside of a string
\ \ Used to indicate a backslash , Prevent it from being interpreted as an escape sequence character .
\a Warning characters , Beep
\b Back space
\f Paper in
\n Line break
\r enter
\t Horizontal tabs
\v Vertical tabs
\ddd ddd Express 1~3 Eight octal numbers .
\xdd dd Express 2 Hexadecimal numbers .
summary
for example : That's what we're going to talk about today , This article simply introduces the data structure , Variable constant , character string , The basic content of escape characters .
边栏推荐
- [FPGA tutorial case 28] one of DDS direct digital frequency synthesizers based on FPGA -- principle introduction
- Text to image论文精读RAT-GAN:文本到图像合成中的递归仿射变换 Recurrent Affine Transformation for Text-to-image Synthesis
- Tinyint type map is received and returned as Boolean
- HCIA动态路由RIP基础实验
- [reprint] NVIDIA hardware and the accuracy mode supported by each hardware
- 关于编程的自我介绍和规划
- ensp中的简单静态路由
- JS——初识JS、变量的命名规则,数据类型
- Vitgan: training Gans with vision transformers
- [reprint] GPU compute capability table
猜你喜欢

The gradient descent method and Newton method are used to calculate the open radical
![[详解C语言]一文带你玩转循环结构(for_while_do-while)](/img/d9/75053297873a5b5458514e7f557cdc.png)
[详解C语言]一文带你玩转循环结构(for_while_do-while)

HCIA Basics (1)

Pseudo class of a element

HCIA基础知识(1)

OGeek Meetup第一期,携手CubeFS火热来袭
![[translation] explicit and implicit batch in tensorrt](/img/17/3f00697d53ff43cd881960849da5f7.png)
[translation] explicit and implicit batch in tensorrt

2022zui新抖音24小时循环值守直播监控(一)直播间开播监控

OSPF的重发布及路由策略

STM32入门教程第一讲
随机推荐
Hash索引和B+树相关知识
第四讲—讲解GPIO_Write函数以及相关例程
7.8 锐捷网络笔试
利用九天深度学习平台复现SSA-GAN
初识网页设计
Experiment of total connection and star topology of mGRE
Tinyint type map is received and returned as Boolean
2022年T2I文本生成图像 中文期刊论文速览-1(ECAGAN:基于通道注意力机制的文本生成图像方法+CAE-GAN:基于Transformer交叉注意力的文本生成图像技术)
详解文本生成图像的仿射变换模块(Affine Transformation)和条件批量标准化(CBN)
Unity Huatuo revolutionary hot update series [1]
JS -- first understand the naming rules and data types of JS and variables
mgre的全连和星型拓扑实验
二层封装技术(HDLC、PPP--PAP\CHAP、GRE)实验练习
Specify that SQL only supports select syntax
mysql一个select语句的执行过程
ensp中的简单静态路由
初识C语言(2)
6.28同花顺笔试
HCIA Basics (1)
Solution: various error reports and pit stepping and pit avoidance records encountered in the alchemist cultivation plan pytoch+deeplearning (I)

