Skip to content

Latest commit

 

History

History
53 lines (41 loc) · 2.62 KB

CppDataType.md

File metadata and controls

53 lines (41 loc) · 2.62 KB

A data type is the form that data (for example: numbers, words, images) has. Every variable has a data type. C++ is type safe, which means that during compiling it checks that all conversions are legal.

The example below the definition of a variable of data type double with the name of 'd' being assigned the value 3.1415. The next line tries to assign the text 'hello world' to d, which is illegal, because 'hello world' if not of data type double (but of std::string).

int main()
{
  double d = 3.1415; //Legal
  d = "hello world"; //ILLEGAL!
}

List of data types that are also keywords

Some data types are only accepted by some standards.

The range of each of these data types can be found with std::numeric_limits.

  • Ideally, a program should be statically type safe [1]
  • Use a consistent method (such as uppercase first letter) to distinguish type names [2].