DEV Community

Matthew Cullen
Matthew Cullen

Posted on

3 3

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

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay