DEV Community

Matthew Cullen
Matthew Cullen

Posted on

C++ datatypes

Today I set up my development environment with Unreal engine 4.
I also learned about the data types present in c++ and the space in memory they occupy.

Github

Data types

In c++ a variable is declared with the data type that will be assigned to it.
-Integer(keyword: int, example: 1,2,3);
-Float(keyword: float, example: 3.14, 4.5);
-Double(keyword: double, example: 3.3333);
-Characters(keyword: char, example: a-z,A-Z,0-9,symbols);
-Boolean(keyword: bool, example: 0/1, true/false);

The difference between a float and a double is precision, the amount of decimal values.

example of declaring a variable in c++

int a = 4;
or if the variable will not be reassigned
const int b = 6;
Enter fullscreen mode Exit fullscreen mode

Modifiers

modifiers operate on the range of memory the data type will occupy. The modifiers are as follows.
-short
-long
-unsigned (only positive values accepted)
-signed (both positive and negative values accepted)

sizeof()

Passing a value into the sizeof operator will return it's size in bytes.

cout << "Size of char : " << sizeof(char) << " byte" << endl;
output: Size of char : 1 byte
Enter fullscreen mode Exit fullscreen mode

In the github I linked I used the sizeof operator on all the datatypes and produced the following output

Size of char : 1 byte
Size of int : 4 bytes
Size of signed int : 4 bytes
Size of unsigned int : 4 bytes
Size of short int : 2 bytes
Size of signed short int : 2 bytes
Size of unsigned short int : 2 bytes
Size of signed long int : 4 bytes
Size of unsigned long int : 4 bytes
Size of float : 4 bytes
Size of double : 8 bytes
Size of long double : 8 bytes
Size of boolean : 1bytes
Size of wchar_t or wide char : 2 bytes
Enter fullscreen mode Exit fullscreen mode

Top comments (0)