C language data type (beginner)

c language data type
#include <stdio.h> //Include a file called stdio.h (std-standard standard)//library function-function provided by the c language itself
int main()//main function- The entry main function of the program has one and only one
{
//input code (task)
printf("hello world\n"); //output hello world on the screen (function-print print function)
return 0;
}
int main()
{
char ch='A';//Apply an area named ch to the memory for the character A
printf ("%c\n", ch); //%c--print character format data
return 0 ;
}
Char--character type int--integer short--short integer long--long integer %p--print as an address %x--print hexadecimal number
int main()
{
int age = 20;
printf("%d\n", age); //%d--print integer decimal data
return 0;
}
int main()
{
float f = 5.0;
printf("%f\n", f) ;//%F--print floating-point number-decimal
return 0;
}
int main()
{
double d = 3.14;
printf("%lf\n", d);//%f can be used, but it is not suitable, so %lf
return 0;
}
int main()
{
short age = 20;// Apply 2 bytes to the memory = 16bit bits to store 20
float weigth=95.6f; // Apply 4 bytes to the memory to store decimals (because the computer defaults decimals are double floating point types, then we need to use float Add f after the decimal)
return 0;
}

Variables, constants
The method of defining variables
int age = 150;
float weight = 45.5f;
char ch ='w';

// It is recommended that the names of global variables and local variables should not be the same, which is prone to bugs.
//When the names of local variables and global variables are the same, local variables take precedence
#include <stdio.h>
int num2 = 20;//Global variables-definition Variables outside the code block ({})
int main()
{
int num1 = 10;//Local variables-defined in the code block ({})
return 0;
}
#include <stdio.h>
int main()
{
//Calculate the sum of 2 numbers
int num1 = 0;
int num2 = 0;
//Input data-use the input function scanf
scanf("%d%d", &num1, &num2); // Take the address symbol
int sum = 0 ;//C language grammar stipulates that variables should be defined at the top of the current code block, that is, defined in int num2=0; the next line
sum = num1+num2;
printf("sum = %d\n", sum);
return 0
}
The scope and life cycle of
variables 1. The scope of local variables is the local scope of the variable. The life cycle of a local variable starts when it enters the scope and ends when it leaves the scope.
2. The scope of global variables is the entire project. The life cycle of global variables is the cycle of the entire project.

Computer unit
bit--bit
byte--byte (8 bits)
kb (1024 bytes)
mb (1024 kb)
gb (1024 mb)
tb (1024 gb)
pb (1024 tb)
printf( "%D\n", sizeof(char)); see how much memory the character type represented by char occupies (bytes) (binary)
char 1 byte can represent 2^8-1 numbers
short 2 byte can represent 2^16-1 number
int 4 byte can represent 2^32-1 number
long 4/8 byte (C language standard stipulates: sizeof(long)>=sizeof(int) will do)
long long 8 byte
float 4 byte
double 8 byte

Guess you like

Origin blog.51cto.com/15083809/2591954