0% found this document useful (0 votes)
23 views9 pages

Data Types of C++

The document provides an overview of data types in C++, including definitions and examples of primitive and built-in types such as boolean, character, integer, and floating point. It details the memory allocation and range for various data types, along with type modifiers like signed and unsigned. Additionally, it includes code examples to demonstrate how to determine the size and limits of these data types on different machines.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views9 pages

Data Types of C++

The document provides an overview of data types in C++, including definitions and examples of primitive and built-in types such as boolean, character, integer, and floating point. It details the memory allocation and range for various data types, along with type modifiers like signed and unsigned. Additionally, it includes code examples to demonstrate how to determine the size and limits of these data types on different machines.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

DATA TYPES

OF C++
05/22/2023
DEFINITION
• While writing program in any language, you need to use
various variables to store various information. Variables are
nothing but reserved memory locations to store values. This
means that when you create a variable you reserve some
space in memory.
• You may like to store information of various data types like
character, wide character, integer, floating point, double
floating point, boolean etc. Based on the data type of a
variable, the operating system allocates memory and decides
what can be stored in the reserved memory.
PRIMITIVE Type Keyword

BUILT-IN TYPES Boolean bool

Character char
•C++ offers the Integer int
programmer a rich
assortment of built-in as Floating point float

well as user defined data Double floating point double

types. Following table Valueless void


lists down seven basic Wide character wchar_t
C++ data types −
Several of the basic types can be modified using
one or more of these type modifiers:
• signed
• unsigned
• short
• long
The following table shows the variable type, how
much memory it takes to store the value in
memory, and what is maximum and minimum
value which can be stored in such type of variables.
Type Typical Bit Width Typical Range
char 1byte -127 to 127 or 0 to 255
unsigned char 1byte 0 to 255
signed char 1byte -127 to 127
int 4bytes -2147483648 to 2147483647
unsigned int 4bytes 0 to 4294967295
signed int 4bytes -2147483648 to 2147483647
short int 2bytes -32768 to 32767
unsigned short int 2bytes 0 to 65,535
signed short int 2bytes -32768 to 32767
signed long int 8bytes same as long int
unsigned long int 8bytes 0 to
1844674407370955161
5
long long int 8bytes -(2^63) to (2^63)-1
unsigned long long int 8bytes 0 to
18,446,744,073,709,55
1,615
float 4bytes
double 8bytes
long double 12bytes
wchar_t 2 or 4 bytes 1 wide character
• The size of variables might be different from those shown in the
above table, depending on the compiler and the computer you are
using.
Following is the example, which will produce correct size of various
#include <iostream>
data types using
on your computer.
namespace std;
int main() {
cout << "Size of char : " << sizeof(char) << endl;
cout << "Size of int : " << sizeof(int) << endl;
cout << "Size of short int : " << sizeof(short int)
<< endl;
cout << "Size of long int : " << sizeof(long int) <<
endl;
cout << "Size of float : " << sizeof(float) << endl;
cout << "Size of double : " << sizeof(double) <<
endl;
cout << "Size of wchar_t : " << sizeof(wchar_t)
<< endl;
• This example uses endl, which inserts a new-line character after every
line and << operator is being used to pass multiple values out to the
screen. We are also using sizeof() operator to get size of various data
types.
When the above code is compiled and executed, it produces the
following result which can vary from machine to machine −
Size of char : 1
Size of int : 4
Size of short int : 2
Size of long int : 4
Size of float : 4
Size of double : 8
Size of wchar_t : 4
#include <iostream>
#include <limits>
using namespace std;

int main() {

std::cout << "Int Min " << std::numeric_limits<int>::min() << endl;


std::cout << "Int Max " << std::numeric_limits<int>::max() << endl;
std::cout << "Unsigned Int Min " << std::numeric_limits<unsigned int>::min() << endl;
std::cout << "Unsigned Int Max " << std::numeric_limits<unsigned int>::max() << endl;
std::cout << "Long Int Min " << std::numeric_limits<long int>::min() << endl;
std::cout << "Long Int Max " << std::numeric_limits<long int>::max() << endl;

std::cout << "Unsigned Long Int Min " << std::numeric_limits<unsigned long int>::min() <<endl;
std::cout << "Unsigned Long Int Max " << std::numeric_limits<unsigned long int>::max() << endl;

You might also like