C + + Common data types

Source: Internet
Author: User

Basic built-in types

C + + provides programmers with a rich range of built-in data types and user-defined data types. The following table lists seven basic C + + data types:

type Key Words
Boolean type bool
Character type Char
Integral type Int
Floating point Type Float
Double floating point type Double
No type void
Wide character type wchar_t

Some basic types can be decorated with one or more type modifiers:

    • Signed
    • Unsigned
    • Short
    • Long

The following table shows the memory that is required for various variable types to store values in memory, and the maximum and minimum values that can be stored by variables of that type.

Note: different systems will vary.

1#include <iostream>2 3 using namespacestd;4 5 intMain ()6 {7     //Print the maximum value of type int8cout <<"int type maximum:"<< Int_max <<Endl;9     //Print the minimum value of type intTencout <<"type of int minimum value:"<< Int_min <<Endl; One     //Print the number of bytes that int occupies Acout <<"int type byte number:"<<sizeof(int); -     return 0; -}

type Number of bits (bytes) Range
Char 8-bit, 1-byte 128 to 127 or 0 to 255
unsigned char 8-bit, 1-byte 0 to 255
Signed Char 8-bit, 1-byte 128 to 127
Int 32-bit, 4-byte 2147483648 to 2147483647
unsigned int 32-bit, 4-byte 0 to 4294967295
Signed int 32-bit, 4-byte 2147483648 to 2147483647
Short int 16-bit, 2-byte 32768 to 32767
unsigned short int 16-bit, 2-byte 0 to 65,535
Signed Short int 16-bit, 2-byte 32768 to 32767
Long int 64-bit, 8-byte 9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
Signed Long int 64-bit, 8-byte 9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
unsigned long int 64-bit, 8-byte 0 to 18,446,744,073,709,551,615
Float 32-bit, 4-byte +/-3.4e +/-38 (up to a number)
Double 32-bit, 8-byte +/-1.7e +/-308 (~15 digits)
Long double 128-bit, 16-byte +/-1.7e +/-308 (~15 digits)
wchar_t 2 or 4 bytes 1 wide characters

As you can tell from the table above, the size of the variable varies depending on the compiler and the computer you are using.

C + + Common data types

Related Article

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.