当前位置:网站首页>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 .
边栏推荐
- [daily question] 565. Array nesting
- HCIA静态路由基础模拟实验
- 2022最新抖音直播监控(二)直播间流媒体下载
- [explain C language in detail] this article takes you to know C language and makes you impressed
- mysql一个select语句的执行过程
- [explain C language in detail] takes you to play with loop structure (for_while_do while)
- 测开基础 日常刷题 (持续更新ing...)
- HCIA(网络初级综合实验练习)
- 静态路由综合实验
- Fastjson handles string escape characters
猜你喜欢

RIP V2 的简单应用(v2的配置、宣告、手工汇总、RIPV2的认证、沉默接口、加快收敛)

STM32 HAL库串口(UART/USART)调试经验(一)——串口通信基础知识+HAL库代码理解

解决方案:炼丹师养成计划 Pytorch+DeepLearning遇见的各种报错与踩坑避坑记录(三)

JS 99 multiplication table

Unity Huatuo hot update environment installation and sample project

HCIA动态路由RIP基础实验

Experiment of total connection and star topology of mGRE

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

Is index reproduction text generation image is score quantitative experiment whole process reproduction inception score quantitative evaluation experiment step on the pit and avoid the pit process
![[Database Course Design] SQLSERVER database course design (student dormitory management), course design report + source code + database diagram](/img/24/fe01d656a54086adf8a3702b82cc26.png)
[Database Course Design] SQLSERVER database course design (student dormitory management), course design report + source code + database diagram
随机推荐
Solution: various error reports and pit stepping and pit avoidance records encountered in the alchemist cultivation plan pytoch+deeplearning (I)
预分频值和自动重装值对中断频率的影响
【volatile原理】volatile原理
Introduction to network - Introduction to home networking & basic network knowledge
mgre的全连和星型拓扑实验
Text to image intensive reading of paper gr-gan: gradually refine text to image generation
初识C语言(1)
2022最新直播监控24小时监控(三)直播间弹幕解析
TCP的三次握手与四次挥手(简述)
OGeek Meetup第一期,携手CubeFS火热来袭
[FPGA tutorial case 29] the second DDS direct digital frequency synthesizer based on FPGA - Verilog development
广域网技术实验
静态路由基础配置(IP地址的规划、静态路由的配置),实现全网可达。
Specify that SQL only supports select syntax
OSPF在MGRE环境下的实验
C语言实现小游戏【三子棋】注释详细 逻辑清晰 快来看看吧!!
静态综合实验(静态路由、环回接口、缺省路由、空接口、浮动静态的综合练习)
解决方案:炼丹师养成计划 Pytorch+DeepLearning遇见的各种报错与踩坑避坑记录(三)
动态路由ofps协议配置
STM32入门教程第一讲

