Data Types in C++

3 min 30 sec read Basic

When we write any program we create variables and the job of data type is to tell the compiler how much memory a specific variable is going to take to store the values. Datatypes specify the type of data where variables can be stored.

Data types in C++ includes Primitive Data Types like int, char, float, double and User-defined Data Types like Structure, Union, enum. User-defined data types mean which are defined by the user.

  1. Basic Datatypes
  2. Derived Datatypes
  3. Enumeration Datatype
  4. void Datatype
Sr. No Datatypes Datatype Description
1) Basic Data Type int, char, float, double
2) Derived Data Type Array, Pointer, Structure, Union
3) Enumeration Data Type enum
4) void void return nothing.
5) bool Boolean ( True or False )
6) wchar_t Wide character.

Basic Data Types

In Interview aptitude questions you might experience the questions like what is the size of particular data type? Basic Data types in C++ you should know about,

Sr. No Datatype Size
1) char Character Type - 1 byte
2) int Integer Type - 2 or 4 bytes depends on the compiler.
3) float Floating type - 4 bytes
4) double Double type - 8 bytes

typedef Declarations:

typedef is used to give a new name to existing datatypes. In this example we will give the exisiting float datatype some name which we use in our entire Cpp program. For example:

typedef float codzify;

Now you have given the name to float type as codzify. Now you can use it whenever you want to declare the float variable.

//Declare a float variable.
codzify abc = 1.0;

Sample program using typedef :-

using namespace std;
typedef float codzify;

int main()
// Here we used float type with different name.
  codzify a = 1.0;



Enumerated Types

An enumeration is a user-defined type that consists of a set of named integral constants that are known as enumerators.

In simple words, enumerated contains a list of identifiers whose first value is initialized with 0 by default. Its next value is being initialised with 1. Then it's next with 2.. then 3 etc.

You can also initialise the enum values as per your need.

Example :-

enum day(mon, tues, wed, thurs, fri) d;

mon = 0 will be by default. tue = 1 will be 1 If you assign tues = 7 then wed = 8 , thurs = 9 , fri = 10.

Derived Data Types

Derived Data types like Arrays, Pointers, Structure, Union are explained in detail in our upcoming articles. We will explore one by one. Just get the basics and have some rough information that these are the datatypes.


How was the tutorial? Nice. Right?

Deep Concept videos to crack the highly-piad interviews.

Chekout out our Youtube Channel to get detailed video content on important topics in interviews.

What is your Interview Score?

Test your skillset with the curated questions created by experts around the globe.

Book a free test slot. Now !.

It usually takes 30 mins for an online test and this test will be MCQ based. Get detailed analytics based on your test and recommedations with personalised roadmaps.

Book a test slot. Now!

Have questions about the trial coding class?

Chat with our experts to discuss

Connect on WhatsApp

Recommended tutorials

#online compiler for c     #python for programming    

#dfs and bfs algorithm     #programming with c language

#storageclass in C    #listcomprehension in python