当前位置:网站首页>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 1a

Legal 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 type 
  • toggle 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")); // 3

effect : 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 

原网站

版权声明
本文为[D_ eretay]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202170507083750.html