当前位置:网站首页>First knowledge of C language (2)
First knowledge of C language (2)
2022-07-27 02:18:00 【First seen in winter】

Hello everyone , I first met Yu Dong !
List of articles
Preface
Then the content of the last time , I will continue to share with you the initial stage C language knowledge !
5、 ... and 、 character string + Escape character + notes
character string
"hello bit.\n"
This is made up of double quotation marks (Double Quote) The resulting string of characters is called string literal (String Literal), Or string for short .
notes : The end flag of the string is '\0' The escape character of . When calculating the length of a string '\0' It's the end sign , It doesn't count as string content .
#include<stdio.h>
#include<string.h>
int main()
{
char arr1[]="bit";
char arr2[]={'b','i','t'};
char arr3[]={'b','i','t','\0'};
printf("%s\n",arr1); // The result is 'bit'.
printf("%s\n",arr2); // The print result is a pile of garbled .
printf("%s\n",arr3); // The result is 'bit'.
printf("%d\n",strlen(arr1)); // The result is 3.
return 0;
}strlen(string lenth)——> Add #include<string.h>
strlen It's a library function , Is a function that specifically calculates the length of a string ( Count '\0' The number of characters before )
Escape character
example :
#include<stdio.h>
int main()
{
printf("c:\code\test.c\n");
return 0;
}
This shows the '\t' and '\n' Not printed out ! I have to mention the escape character here . Escape characters, as the name suggests, change meaning .
| Escape character | paraphrase |
|---|---|
| \? | Use... When writing multiple 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 a human 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 . Such as \130 (X) |
| \xdd | dd Express 2 Hexadecimal numbers . Such as \x30 0 |
#include<stdio.h>
int main()
{
printf("%c\n",''\'); // Printed as '
printf("%s\n","\""); // Printed as "
return 0;
}#include<stdio.h>
int main()
{
printf("%d\n",strlen("abcdef")); // The result is 6
printf("%d\n",strlen("c:\test\628\test.c"); // \62 Parsed into an escape character
retrurn 0;
}#include<stdio.h>
int main()
{
printf("%c\n",'\130'); // Printed as X
return 0;
}Why does this output X Well ? Because the octal 130 Convert to decimal to 88,88 Corresponding ASCII In the table X.

6、 ... and 、 notes
Why do you need comments in your code ?
- There are unnecessary codes in the code that can be deleted directly , You can also comment out .
- Some of the code is hard to understand , You can add a comment file .
There are two styles of annotation :
- C Notes on language style ( You can't nest comments )
- C++ Notes on language style ( You can comment on a line , You can also comment on multiple lines )
Code demonstration :
#include<stdio.h>
int Add(int x, int y)
{
return x + y;
}
/*C Language style notes
int Sub(int x, int y)
{
return x + y;
}
*/
int main()
{
//C++ The annotation style of
//int a=0;
// call Add function , Complete the addition
printf("%d\n", Add(1, 2));
return 0;
}7、 ... and 、 Select statement
adopt if else Statement to realize the selection of conditions
Code demonstration :
#include<stdio.h>
int main()
{
int input = 0;
printf(" Should you study hard ?(1/0)");
scanf("%d", &input);
if (input = 1)
{
printf(" good offer\n");
}
else
{
printf(" Go home and plant \n");
}
return 0;
}8、 ... and 、 Loop statement
C How to implement loops in languages ?
- while sentence
- for Loop statement ( Explain in detail later )
- do ......while sentence ( Explain in detail later )
Code demonstration while sentence :
#include<stdio.h>
int main()
{
printf(" Crazy code writing \n");
int line = 0;
while (line <= 20000)
{
line++;
printf(" I'm going to keep typing \n");
}
if (line > 20000)
printf(" The keyboard is broken , Twenty thousand a month \n");
return 0;
}Brothers, the keyboard is broken , Twenty thousand a month ! No fear of hardship , Work hard !
Nine 、 function
Function is characterized by simplifying code , Code reuse
Code demonstration :
#include<stdio.h>
int main()
{
int num1 = 0;
int num2 = 0;
int num3 = 0;
printf(" Enter two operands :");
scanf_s("%d %d", &num1, &num2);
num3 = num1 + num2;
printf("%d", &num3);
return 0;
}This code is a little verbose , We can simplify the code through functions !
Simplified code demonstration :
#include<stdio.h>
int Add(int x, int y)
{
return x + y;
}
int main()
{
int a = 0;
int b = 0;
printf(" Enter two operands :");
scanf_s("%d %d", &a, &b);
printf("%d",Add(a,b));
return 0;
}
summary
The above is the initial stage I summarized for you C Language dry goods , If there are mistakes, welcome baozi to criticize and correct in the comment area ! I also hope the knowledge I summarized can bring you harvest !
边栏推荐
- Ospf基础配置应用( 综合实验: 干涉选举 缺省路由 区域汇总 认证--接口认证)
- HCIA静态路由基础模拟实验
- 2022zui new Tiktok 24-hour round robin live broadcast monitoring (I) live broadcast room start-up monitoring
- OSPF protocol knowledge summary
- Static routing default routing VLAN experiment
- Mechanical hard disk Selection Guide -- from the selection experience
- [explain C language in detail] takes you to play with the choice (Branch) structure
- 预分频值和自动重装值对中断频率的影响
- 静态综合实验(静态路由、环回接口、缺省路由、空接口、浮动静态的综合练习)
- 6.28大华笔试
猜你喜欢

HCIA (network elementary comprehensive experimental exercise)

Text to image paper intensive reading ssa-gan: text to image generation with semantic spatial aware Gan

mgre的全连和星型拓扑实验

HCIA基础知识(1)

CAN总线通信应用

动态路由rip协议实验

Mechanical hard disk Selection Guide -- from the selection experience

Explain exi interrupt through the counting experiment of infrared sensor

Solution: various error reporting and pit stepping and pit avoiding records encountered in the alchemist cultivation plan pytoch+deeplearning (III)

Codeforces Round #809 (Div. 2), problem: (C) Qpwoeirut And The City
随机推荐
6.30滴滴面经(一面+二面)
C语言——字符和字符串、算术运算符、类型转换
【volatile原理】volatile原理
[详解C语言]一文带你玩转选择(分支)结构
OSPF静态大实验
Codeforces Round #810 (Div. 2), problem: (B) Party
Vitgan: training Gans with vision transformers
[volatile principle] volatile principle
[explain C language in detail] this article takes you to know C language and makes you impressed
Dynamic routing ofps protocol configuration
2022最新抖音直播监控(二)直播间流媒体下载
JS logical operator
[Database Course Design] SQLSERVER database course design (student dormitory management), course design report + source code + database diagram
7.13 Weilai approved the written examination in advance
6.29 Zhong'an Summer Internship
MySQL课程1.简单命令行--简单记录 欢迎补充纠错
机械硬盘选购指南——从选购经历谈起
通过对射式红外传感器计次实验讲解EXTI中断
OSPF basic configuration application (comprehensive experiment: interference election default routing area summary authentication -- interface authentication)
6.30 written examination of MediaTek