position: fixed; top: auto !important; margin-left: 112px;

Data Types in C++

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. NoDatatypesDatatype 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. NoDatatypeSize
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 :-

#include <iostream>
using namespace std;
typedef float codzify;

int main()
// Here we used float type with different name.
  codzify a = 1.0;
  cout<<a;    // Calling member function using class object



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 initialized with 1. Then it's next with 2.. then 3 etc.

You can also initialize 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.

Solve the Quiz of Article

1) If variable is declared as float, what do you think compiler will allocate memory of 8 bytes?

2) Does void return some value?

Previous Next Article


Largest collection of up-to-date tutorials to learn programming languages. We are focused on easy learning. Massive collection of interview questions one may need for preparation.

Social Profile


Copyright 2019. All rights reserved.