当前位置:网站首页>C language -- legal identifier and integer
C language -- legal identifier and integer
2022-06-26 16:41:00 【D_ eretay】
Let's first introduce , Start learning c What is the first header file that the language encounters
The header file
Also known as toolbox
Provide a series of methods ( Tools )
#include <stdio.h>
#include "stdio.h"<>: Search directly in the system directory If it is not found, an error will be reported directly
" ": First, search under the current directory Can't find it. Look it up in the system directory If it is not found, an error will be reported directly
summary : Generally, in order to improve efficiency, I will use " " instead of <>
In general , System file usage <> Custom files are usually placed in the current directory So use " "
Constant
Constants usually have the following
integer constants such as :1、100、999、6366
Real constant such as :1.0、3.14
character constants such as :'A'、'a'、'1'
String constant such as :"aA1"
Symbolic constant utilize #define To define constants
address constant
Variable
Variable : It represents a with a name , A storage unit with specific properties . Can be used to store data ( The value of the variable )
Variables must be defined before using . The naming of variables must conform to the specification
Naming specification
By digital , Letter , Underline composition
Cannot start with a number ( In general, you will not start with an underscore )
It can't be a keyword
Be careful :
Case sensitive
Nomenclature Naming habits
Write the name according to its meaning
give an example :
// We want to describe the health of a character in the game ( data ==> Stored in memory )
// This memory Let's give him a name ==> Variable name
Example :
hp xueliang a b abc hp HP
a1 b2_
Error model :
123 1aLegal floating point numbers
Decimals and exponents
decimal
Index ( Scientific enumeration : n*10^m eE) Such as :3.14e3
char And octal
The following is an example through code
Numbers and numeric characters
'\0' Terminator ( character string ) // A: -128 -- 127 B: 0 -- 255 // 0 -- 255 ==> 0 -- 0377 char ch; ch = '\0'; printf("ch = 0%o\n", ch); ch = '\377'; printf("ch = 0%o\n", ch); // 1 Why are there eight more 7 // 2 If more than 377 What will happen? // Improve the overall shape // char Type in operation Will be promoted to int type // After the operation Will revert to the original typetoggle case
// 'A': 65 // 'a': 97 // '0': 48 // 1 '0'==>0 char ch = '0'; ch = ch - ('0' - 0);// Subtract the difference printf(" Numbers : %d\n",ch); // 0 // 2 0==>'0' // 'A' ==> 'a' char ch1 = 'A'; ch1 = ch1 + ('a'-'A'); printf("%c\n", ch1); // a
sizeof()
// Application :sizeof() Operator
/*
character : ''
character string : "" "" "a" "123"
*/
printf("%d\n", sizeof("")); // "\0"
printf("%d\n", sizeof("a")); // "a\0"
printf("%d\n", sizeof("123")); // "123\0"
printf("%d\n", sizeof("ab12\\1234\0ab")); //
printf("%d\n", sizeof("\1a")); //
printf("%d\n", sizeof("\128")); // 3effect : Count bytes , seek () The objects inside occupy a few bytes in memory
In general :
position = byte
A byte is eight bits
short sh = 0;
printf("%d\n", sizeof(sh));
printf("%d\n", sizeof(short));Value range
Make small value ---- Maximum
Unsigned : 0-65535 (65536)
The signed : -32768--0--32767 (65536)
Data overflow
The size of the data exceeds the range that the current type can represent
Use time :
It will overflow when the data is stored
Processing mode :( Automatic adjustment )
The data is too big : Subtract... From the data n Range sizes
The data is too small : Add... To the data n Range sizes
Range size : The number of data that the current type can represent
integer
data type
short: Short int: integer long: Long integer long long: long long
Is a type of data type , Include :
short int long long long
// Defined a int Variable of type
// Name the variable hp
// Initialize the variable to 100
int hp = 100;
// Defined a int Variable of type
// Name the variable num
int num;
// to num The assignment is 0
num = 0;
Be careful :
1 Integer defaults to int type
2 Between integers , The result is still an integer
// Output statement
// 1 Simple
printf("hello world!\n");
// 2 A little difficult
printf("num The value of is :%d\n", num);
// 3 It's a little difficult
printf("hp = %d, num = %d\n", hp, num);
// Output statement
// 1 Simple
printf("hello world!\n");
// 2 A little difficult
printf("num The value of is :%d\n", num);
// 3 It's a little difficult
printf("hp = %d, num = %d\n", hp, num);
#include <stdio.h>
int main()
{
short sh = 1;
int num = 10;
long n = 100;
long long m = 1000;
/*
short: Short
int: integer
long: Long integer
long long: long long
short int sh = 1;
int num = 10;
long int n = 100;
long long int m = 1000;
*/
/*
They are all integers Can be used to define integer variables
that How should we choose the type ?
*/
// The phenomenon :
short s = 0;
printf("s = %d\n", s);
s = 100;
printf("s = %d\n", s);
s = 32768;
printf("s = %d\n", s);
s = 32769;
printf("s = %d\n", s);
// analysis :
// The data has changed ==> Maybe the data is too big
// knowledge :
// Data overflow (1 Range 2 overflow )
return 0;
}Process oriented
First c Languages usually write programs that are process oriented , The following describes its process
technological process
The process of program execution : From the top down , Sentence by sentence execution ; Encountered a specific syntax structure , Execute according to the grammar rules
entrance 、 exit
// Every project There is only one entrance
// The main function Entry function main function
int main()
{
// Code valid area
return 0;
// Code invalid area
}
perhaps
void main()
{
} notes
// Single-line comments
/*
Multiline comment
1
2
3
....
*/Hexadecimal conversion
Measurement method ( How many into one It's a decimal )
Decimal system : full 10 Jin Yi
Hexadecimal : full 16 Jin Yi
Binary and octal representations
Binary system :0b 0B
octal :0
A number on a digit
Express ( features )
give an example
Binary system 0 1 Only 0 and 1 10100101
octal 0 1 2 3 4 5 6 7 0 start 01457
Decimal system 0 1 2 3 4 5 6 7 8 9 No special requirements 666
Hexadecimal
0x start 0 1 2 3 4 5 6 7 8 9 a b c d e f 0x12af
0X start 0 1 2 3 4 5 6 7 8 9 A B C D E F 0X34CD
Welfare part :
About vs2013 Press F5 Unable to jump out of the console
The first way
#include <Windows.h> // Be sure to add this header file
void main()
{
system("pause"); // Add this code at the end to solve
}
The second way
getchar(); // Add this code at the end of the function 边栏推荐
- Stm32h7b0 replaces the h750 program, causing the MCU to hang up and unable to burn the program
- Develop operator based on kubebuilder (for getting started)
- JS教程之使用 ElectronJS 桌面应用程序打印贴纸/标签
- [Blue Bridge Cup training 100 questions] scratch distinguishing prime numbers and composite numbers Blue Bridge Cup scratch competition special prediction programming question intensive training simul
- 国内首款开源 MySQL HTAP 数据库即将发布,三大看点提前告知
- In a bad mood, I just write code like this
- What does the inner structure of the neural network "alchemy furnace" look like? An interpretation of the thesis by the doctor of Oxford University
- Cloud platform monitoring system based on stm32+ Huawei cloud IOT design
- Redis migration (recommended operation process) 1
- [time complexity and space complexity]
猜你喜欢

5g is not flat and 6G is restarted. China leads wireless communication. What is the biggest advantage of 6G?

Big talk Domain Driven Design -- presentation layer and others

How to implement interface current limiting?

若依如何实现接口限流?
Redis Guide (8): principle and implementation of Qianfan Jingfa distributed lock

The details of the first pig heart transplantation were fully disclosed: human herpes virus was found in the patient, the weight of the heart doubled after death, and myocardial cell fibrosis

Lifeifei's team applied vit to the robot, increased the maximum speed of planning reasoning by 512 times, and also cued hekaiming's Mae

Structure the graduation project of actual combat camp

Arduino uno + DS1302 simple time acquisition and serial port printing

I regard it as a dry product with a monthly income of more than 30000 yuan for sidelines and more than 10000 yuan for novices!
随机推荐
最小二乘系统辨识课 中篇:递归最小二乘
[机缘参悟-31]:鬼谷子-抵巇[xī]篇-危机是危险与机会并存
[graduation season] a word for graduates: the sky is high enough for birds to fly, and the sea is wide enough for fish to leap
Oilfield exploration problems
I regard it as a dry product with a monthly income of more than 30000 yuan for sidelines and more than 10000 yuan for novices!
Redis migration (recommended operation process)
100+ data science interview questions and answers Summary - basic knowledge and data analysis
[从零开始学习FPGA编程-46]:视野篇 - 集成电路的发展与技术进步
proxy
Stm32f103c8t6 realize breathing lamp code
《软件工程》期末重点复习笔记
基于STM32+华为云IOT设计的云平台监控系统
Redis 迁移(操作流程建议)
C语言 头哥习题答案截图
Redis 迁移(操作流程建议)1
Redis顺序排序命令
Overall context of concurrent programming
Acid of redis
LeetCode Algorithm 24. Exchange the nodes in the linked list in pairs
[Li Kou brush questions] 11 Container holding the most water //42 Rain water connection