当前位置:网站首页>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 …
边栏推荐
- FairyGUI条子家族(滚动条,滑动条,进度条)
- [Yu Yue education] guide business reference materials of Wuxi Vocational and Technical College of Commerce
- [algorithm] sword finger offer2 golang interview question 1: integer division
- [算法] 劍指offer2 golang 面試題2:二進制加法
- 基本Dos命令
- [GNSS] robust estimation (robust estimation) principle and program implementation
- Ten minutes to thoroughly master cache breakdown, cache penetration, cache avalanche
- Shortest Hamilton path (pressure DP)
- 初识指针笔记
- Edit distance (multi-source BFS)
猜你喜欢
随机推荐
Music playback (toggle & playerprefs)
【rtklib】在rtk下使用抗差自适应卡尔曼滤波初步实践
几道高频的JVM面试题
系统设计学习(三)Design Amazon‘s sales rank by category feature
系统设计学习(二)Design a key-value cache to save the results of the most recent web server queries
Application architecture of large live broadcast platform
抽象类和接口
Record: solution of 404 error of servlet accessing database in dynamic web project
音乐播放(Toggle && PlayerPrefs)
MySQL shutdown is slow
On March 15, the official version of go 1.18 was released to learn about the latest features and usage
How to reduce the shutdown time of InnoDB database?
RTKLIB: demo5 b34f. 1 vs b33
继承和多态(上)
图书管理系统小练习
Chromatic judgement bipartite graph
[算法] 劍指offer2 golang 面試題2:二進制加法
Edit distance (multi-source BFS)
[算法] 剑指offer2 golang 面试题12:左右两边子数组的和相等
MYSQL索引钟B-TREE ,B+TREE ,HASH索引之间的区别和应用场景