当前位置:网站首页>First acquaintance with C language (Part 1)
First acquaintance with C language (Part 1)
2022-07-06 13:07:00 【犇犇犇犇犇犇犇】
Here I will give you a brief introduction C Language what we need to learn , Let's have a preliminary understanding .
C Language is a structured programming language , What is structured , That is to say : Sequential structure , Selection structure , Loop structure , Everything in life is the combination, nesting and repetition of these structures . therefore C Language can solve problems in life through programming .
The development of programming language : Machine language is binary – Assembly language people program better through some mnemonics –B Language –C Language , At this time C Language is already a high-level language .
C In language, we need to understand
- Variable
- Constant
- data type
- The scope and life cycle of variables
- Comment and escape characters
- keyword
- Array
- function
- The pointer
- Selection structure
- Loop structure
- Structure
Variables and constants
Look at the following code
//1. Literal constants
//2.const Modified constant variable
//3. adopt define Defined constant
//4. Enumeration defined constants
enum Color
{
Red=0,
Green=0,
Blue=0,
};
#define Max 100
int main()
{
//30;
//3.14;
//'W';// character
//"abc";
stay C In language ,const Embellished a, It's essentially a variable , But it can't be modified directly , There are properties of constants
//const int a = 10;
//a = 20;
//printf("%d ", a);
//const int n = 10;
//int arr[n] = { 0 };// At this time, the error is that the expression must contain a constant value
//return 0;
//Max = 10;// When you want to modify define When defining variable values , You're going to report a mistake .
//printf("%d\n", Max);
//Red = 10; // You can see that there will be define The same mistake
printf("%d\n", Red);
return 0;
}
int main()
{
int a = 10;
a = 20;
printf("%d\n", a);
// This is the variable that can be changed
return 0;
}
data type
// What are the data types
// character
// integer Short integer Long integer Longer integer
// floating-point Single precision floating point Double precision floating point
int main(){
printf("%d\n", sizeof(char));// byte --1
printf("%d\n", sizeof(short));// --2
printf("%d\n", sizeof(int));// --4
printf("%d\n", sizeof(long));// --4
printf("%d\n", sizeof(long long));// --8
printf("%d\n", sizeof(float));// --4
printf("%d\n", sizeof(double));// --8
return 0;
}
The life cycle and scope of variables
// Scope of variable
//1. local variable
// From the function that created it to the end of this function
//2. Global variables
// The scope of global variables is the whole project
// Life cycle of variable
// local variable : Enter the scope and start , Out of scope end
// Global variables : The whole life cycle of the program
int main(){
int a = 10;
{
//int a = 10;
printf("%d\n", a);
}
printf("%d", a);
return 0;
}
Comment and escape characters
/* /* int main() { This is a C The annotation style of language */
return 0;
}*/
//int main()
//{
// This is a C++ The annotation style of
// return 0;
//}
// current C Language has also introduced // This style
/**/C This annotation style of language
shortcoming : You can't nest
C++ The annotation style of
advantage : Convenient single line notes , You can also comment multiple lines
Escape characters, you can search the Internet to understand it by yourself. There is no more introduction here , But leave a question for everyone , See if you can do it right
int main()
{
// What will the compiler output
printf("%s\n","C:\\test\test.c");
printf("%d\n", sizeof("C:\\test\test.c\x069"));
return 0;
}
Array
int main()
{
int arr[10] = {
0 };
// int Represents the array type arr Represents the array name
//10-- Array size {0}--- All ten elements in the array are assigned zero
return 0;
}
function
// Write a sum of two numbers
int ADD(int x, int y)
{
//int The return type of the function
//ADD Function name
//int x,int y The parameters of the function
//{
// return x + y; These three lines are the function body
//}
return x + y;
}
int main(){
// establish
int num1 = 0;// Variable initialization
int num2 = 0;
// Input
scanf("%d %d", &num1, &num2);
// Sum up
//int sum = num1 + num2;
int sum = ADD(num1, num2);
// Output
printf("%d", sum);
return 0;
}
To be continued …
边栏推荐
- [algorithme] swordfinger offer2 golang question d'entrevue 2: addition binaire
- 继承和多态(下)
- 基本Dos命令
- 第一人称视角的角色移动
- 初识C语言(上)
- FGUI工程打包发布&导入Unity&将UI显示出来的方式
- 基于rtklib源码进行片上移植的思路分享
- How do architects draw system architecture blueprints?
- [algorithm] sword finger offer2 golang interview question 2: binary addition
- 【GNSS】抗差估计(稳健估计)原理及程序实现
猜你喜欢

String类

121道分布式面试题和答案

Ten minutes to thoroughly master cache breakdown, cache penetration, cache avalanche
![[算法] 剑指offer2 golang 面试题12:左右两边子数组的和相等](/img/11/ee0628a68542236fc641966579a31a.png)
[算法] 剑指offer2 golang 面试题12:左右两边子数组的和相等

十分鐘徹底掌握緩存擊穿、緩存穿透、緩存雪崩

染色法判定二分图

MySQL 30000 word essence summary + 100 interview questions, hanging the interviewer is more than enough (Collection Series
![[algorithm] sword finger offer2 golang interview question 10: subarray with sum K](/img/63/7422489d09a64ec9f0e79378761bf1.png)
[algorithm] sword finger offer2 golang interview question 10: subarray with sum K

音乐播放(Toggle && PlayerPrefs)

平衡二叉树详解 通俗易懂
随机推荐
[Chongqing Guangdong education] reference materials for regional analysis and planning of Pingdingshan University
Wechat applet development experience
Excel导入,导出功能实现
2-year experience summary, tell you how to do a good job in project management
【RTKLIB 2.4.3 b34 】版本更新简介一
[untitled]
MYSQL索引钟B-TREE ,B+TREE ,HASH索引之间的区别和应用场景
[algorithm] sword finger offer2 golang interview question 12: the sum of the left and right sub arrays is equal
Shortest Hamilton path (pressure DP)
What are the functions and features of helm or terrain
Problems and solutions of robust estimation in rtklib single point location spp
121 distributed interview questions and answers
Sharing ideas of on-chip transplantation based on rtklib source code
Realization of the code for calculating the mean square error of GPS Height Fitting
[GNSS] robust estimation (robust estimation) principle and program implementation
雇佣收银员【差分约束】
All in one 1405: sum and product of prime numbers
Containers and Devops: container based Devops delivery pipeline
基本Dos命令
Error: sorting and subscript out of bounds