Signed Integer:
Unsigned Integer:
Note:
- Unsigned data means quantity, only positive value
- unsigned unsigned identification does not change the byte size of the data type
- To print unsigned data, replace all the previous %d with %u. If you do not pay attention to the conversion in vs and output the unsigned type with %d, then the compiler will optimize it and press the unsigned type as a signed type. For output, the premise of optimization is not to write:
unsigned int a = -10u;
After the data is added u, if a negative sign is written in front, an error will be reported, because it is clear that this is an unsigned integer.
If you use %u to output a negative integer, garbled characters will appear
- Signed type is generally not written before signed
- When defining variables, the following d and u are generally omitted:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void test()
{
unsigned int a = 10u; //简写成unsigned int a=10;
//注意:这里不能用hu
unsigned short a1 = 10u; //简写成unsigned short a1=10;
unsigned long a2 = 10lu; //简写成unsigned long a2=10;
unsigned long long a3 = 10llu; //简写成unsigned long long a3=10;
printf("int a=%u\n", a);
//这里打印short短整型要用hu
printf("short a1=%hu\n", a1);
printf("long a2=%lu\n", a2);
printf("long long a3=%llu\n", a3);
}
int main()
{
test();
return 0;
}
`
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void test()
{
int a = 10; //简写成int a=10;
//注意:这里不能用hu
short a1 = 10; //简写成 short a1=10;
long a2 = 10l; //简写成 long a2=10;
long long a3 = 10ll; //简写成 long long a3=10;
printf("int a=%d\n", a);
//这里打印short短整型要用hd
printf("short a1=%hd\n", a1);
printf("long a2=%ld\n", a2);
printf("long long a3=%lld\n", a3);
}
int main()
{
test();
return 0;
}
Note: The return value of sizeof() is:
size_t is equivalent to unsigned int to
receive the return value of sizeof to use %u