Data Types in C++ – Pythongdb

In this I will learn about data types, Before that I will understand what Is variables and keywords.
Variable – It a place where we store some memory at a place where we allocated it.

  • A variable can have alphabets, digits, underscore.
  • Variable can’t start with digits.
  • No whitespace is allowed within the variable name.
  • A variable can’t be reserved work or keyword like int etc.

Types of Variables

  • Local Variables
  • Instance Variables
  • Static Variables

Data types are mainly divided into three types:

  1. Primitive Data Types: These are built – in or predefined data types and can be used directly by the user to declare variables.
  • Integer(int)
  • Floating point(float)
  • Character(char)
  • Boolean(bool)
  • Double Floating Point
  • Void (value less)
  • Wide Character

2. Derived Data Types: These are the data types that are derived from the primitive or build in datatypes.

  • Function
  • Array
  • Pointer
  • Reference

3. User Defined : These are data types which we can defined by ourself. Like Defining a class inC++ or a structure.

  • Class
  • Structure
  • Union
  • Enumeration
  • Typedef Define DataType
// c++ program to size of data types
#include <iostream>
using namespace std;

int main()
{
    cout << "Size of char : " << sizeof(char) << " byte" << endl; 
    cout << "Size of int : " << sizeof(int) << " bytes" << endl;
    cout << "Size of short int : " << sizeof(short int) << " bytes" <<    endl; 
    cout << "Size of long int : " << sizeof(long int) << " bytes" << endl; 
    cout << "Size of signed long int : " << sizeof(signed long int) << " bytes" << endl; 
    cout << "Size of unsigned long int : " << sizeof(unsigned long  int) << " bytes" << endl;
    cout << "Size of float : " << sizeof(float) << " bytes" <<endl; 
    cout << "Size of double : " << sizeof(double) << " bytes" << endl;       cout << "Size of wchar_t : " << sizeof(wchar_t) << " bytes" <<endl;

    return 0;
}

Output

Size of char : 1 byte
Size of int : 4 bytes
Size of short int : 2 bytes
Size of long int : 8 bytes
Size of signed long int : 8 bytes
Size of unsigned long int : 8 bytes
Size of float : 4 bytes
Size of double : 8 bytes
Size of wchar_t : 4 bytes

Leave a Comment