C Language Learning fourth day data type 1

Source: Internet
Author: User

int represents an integer, it occupies 4 bytes in memory, the binary representation is 32 bits, the binary contains only 0 and 1, and its maximum value is all 1, but int is

signed type, so the highest bit (the first bit on the left) to take out to do the sign bit, so that only 31 bits to save the number, converted to decimal its maximum value is

2147483647, this value can be in the calculation The highest bit is 0 for positive, 1 for negative, and the minimum is to add a minus sign before the maximum number, but

The reason for 0 is positive 0 and negative 0, so negative 0 is the minimum value, that is, the minimum value minus 1 is the minimum value of int:-2147483648

Note: If the type of the variable is shaped and assigned to a variable with a decimal number, the fractional part is omitted when the variable is output

Long is similar to int, but long is 4 bytes on a 32-bit system, 8 bytes on a 64-bit system, and a long long is used on a 32-bit system to take up the 8-byte example:

#include <stdio.h>
int main ()
{
Long x=21474836472;
printf ("%ld", X);
return 0;
}

%ld l for long, d for int together is long int (length shaping)

#include <stdio.h>
int main ()
{
unsigned int x=4294967294;
printf ("%u", X);
return 0;
}

Unsigned represents unsigned, unsigned shaping takes up 4 bytes, and because the sign bit can also be used to represent numeric values, it is one times larger than the sign bit, but because there is no sign bit

Can only represent positive numbers, u represents unsigned

#include <stdio.h>
int main ()
{
unsigned long x=2147483647;
printf ("%lu", X);
return 0;
}

Short Shaping:

#include <stdio.h>

int main ()
{
Short x=32767;
printf ("%hd", X);
return 0;
}

Short is similar to int, accounting for two bytes, H stands for short

#include <stdio.h>
int main ()
{
unsigned short x=65535;
printf ("%hu", X);
return 0;
}

Convert the value of an integer to 8 binary

#include <stdio.h>
int main ()
{
int x=16;
printf ("% #o \ n", x);
return 0;
}

o represents the output of shaping data in octal format, #代表输出八进制的前缀

The following is the conversion of the value of shaping to 16 binary

#include <stdio.h>
int main ()
{
unsigned int x=16;
printf ("% #x \ n", x);
return 0;
}

X for 16 binary, which can be used to differentiate between octal or hexadecimal numbers by prefix

Defining aliases using typedef

#include <stdio.h>
int main ()
{
typedef unsigned short int us;
US a=1,b=2,c=3;
printf ("%hu+%hu-%hu\n", a,b,c);
return 0;
}

alias definition: unsigned short int-->us

Floating-point variables:

#include <stdio.h>
int main ()
{
float A;
Double b;
a long double C;
return 0;
}

Float,double, long double stands for single precision, double precision

The float type variable takes 4 bytes, the value range is -3.4*10 38 times to 3.4*10 38 times

#include <stdio.h>
int main ()
{
float x=3.40e38f;
printf ("%f", X);
return 0;
}

E for 10,e38 represents 10 of 38 times, if 38 represents 10 of the negative 38 times

F indicates that this is a value of type float, and if you do not add the f description, the compiler will consider this to be a numeric value of type Double.

The value range of the double type variable, which accounts for 8 bytes in memory

#include <stdio.h>
int main ()
{
Double x=1.79e308;
printf ("%f", X);
return 0;
}

C Language Learning fourth day data type 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.