Data Types in C++ - Algomentor

Data Types in C++ 

data type in c++

Hi, welcome to the data structure and algorithm made easy in this section of the tutorial we will learn about Data types in C++. We will learn about many data types like int, double, string, long, and many more. First, we will talk about variables and memory so that it's easy to understand the concept of data types.

What is Memory?

Memory is the piece of computer which allows us to store the data and also allows us to retrieve the data example of memory is pen drive, SSD, Hard Drive, etc. When we run a c++ program it takes some memory of RAM to execute the instruction of the program like if a program has an Array then there must be a piece of memory to hold the array or a program may have variables then variable also take some space on the memory to depend upon the Data Type of the variable.

What are Variables?

Variables are something that stores information about the particular type, for example, you declare a variable has name Age and its data type is an int that means age occupies a block of memory to store age of the person in the program and after the program terminate age will release the memory that is held initially to store Age you can assign as many time as you want in the program and the latest updated value is overwritten in the previously written value.

What are the Different Types of Data Types?

Data types in c++ are mainly divided into 3 parts.

1. Primitive Data Types:- These types of data type is prebuilt of already define in c++ we just need to declare them and we are good to go. Example of these data types

  • int
  • float
  • long
  • double
  • boolean
  • character 
  • void
  • string

2. Derived Data Types:- These data types are derived from the Primitive Data like you want to store around 100 integers so you don't need to define all 100 integers we only need to define an array of integers which can hold 100 integers simultaneously. Types there are 4 types of Derived Data Types
  • Array
  • Pointer
  • Function
  • Reference

3. User Define or Abstract Data Types:- These data type is defined by the user so that they can take input accordingly like you want a data type that can store a Name, Age, Roll no of the student so you can make a structure by using struct keywords. Example of these Data type are as follows

  • struct
  • class
  • union
  • typedef
  • enum or enumeration

What is the memory Allocation to Primitive Data Types?
  • short - 2 Byte
  • void - 0 Byte
  • int -  2 Byte or 4 Byte
  • float -  4 Byte
  • double -  4 Byte
  • long -  8 Byte
  • double long - 12 Byte
  • character -  1 Byte
  • string - 1Byte * (size of string)
So That all, for now, I hope you like this lesson and want to learn more so don't forget to follow us on our Social handle as we post our update on them 😀.

Thank you for reading this post and yes don't forget to share this post with you.

Hi if you want to write a post on our website then please check this article on How to do a guest post.

Post a Comment

0 Comments