Data Types C Plus Plus Programming Language

Data Types C Plus Plus Programming Language
Data Types C Plus Plus Programming Language

Data Types C Plus Plus Programming Language

    Data Types C Plus Plus: A Data type is a type of data. Data types can be used C++ Program. The C++ language provides different data types. which can be used in the C++ language program. Data types provide in the C++ library.

    Data types specify how we enter data into our programs and what type of data we enter. The C++ language has a predefined set of data types to handle various kinds of data that we use in our program.


    Data types are two types in C++ Language

    1. Pre-defined Data Types

    2. User-defined Data Types or Derived Data Types.

    Pre-defined Data Types: A pre-defined data type is already provided in the c Library. pre-defined data types like integer, floating and Character are pre-defined data types in C++ Language.

    1.integer Type (int)

    2.floating Type(float)

    3.Character Type(char)


    User-defined Data Types or Derived Data Types

    1. Pointer Types

    2. Array

    3. Structure

    4. Union

    These data types have different storage capacities. C++ language supports 2 different types of data types: primary and Derived data types.

    Primary data types: These are fundamental data types in C++ namely integer (int), floating(float), character (char), and void.

    Derived data types: Derived data types are arrays, functions, structures, and pointers. These are discussed in detail later.


    integer Data types in C++

    Data Types

    Size

    Bytes Range

    Short

    2-32768 To +32767

    Int

    2-32768 To +32767

    Unsigned int

    20 To +65536

    Long

    4-214748 To +214748
    Unsigned long4

    0 To 4,294,967


    float Data types in C++

    Data Types

    Size Byte

    Range

    Float

    4

    3.4E-38 To +3.4E+38

    Double

    8

    1.7+308 To +1.7E+308

    Long Double

    10

    3.4-4932 To +1.1+4932


    Char Data types in C++

    Data Types

    Size Byte

    Range

    Char

    1

    -127 to +128

    signed char

    1

    -128 to +128

    unsigned char

    1

    -0 to +255


    How To Use Data Types Size in C++?

    #include <iostream>

    #include <stdlib.h>

    #include <limits.h>

    #include <float.h>

    using namespace std;

    int main()

    {

    int args;

    char** args;

    cout<<"CHAR_BIT:"<<CHAR_BIT<<"\n";

    cout<<"CHAR_MAX:" <<CHAR_MAX<<"\n";

    cout<<"CHAR_MIN:"<<CHAR_MIN<<"\n";

    cout<<"INT_MAX:"<<INT_MAX<<"\n";

    cout<<"INT_MIN:"<<INT_MIN<<"\n";

    cout<<"LONG_MAX:"<<LONG_MAX<<"\n";

    cout<<"LONG_MI:"<<LONG_MIN<<"\n";

    cout<<"SCHAR_MAX:"<<SCHAR_MAX<<"\n";

    cout<<"SCHAR_MIN:"<<SCHAR_MIN<<"\n";

    cout<<"SHRT_MAX:"<<SHRT_MAX<<"\n";

    cout<<"SHRT_MIN:"<<SHRT_MIN<<"\n";

    cout<<"UCHAR_MAX:"<<UCHAR_MAX<<"\n";

    cout<<"UINT_MAX:"<<UINT_MAX<<"\n";

    cout<<"ULONG_MAX:"<<ULONG_MAX<<"\n";

    cout<<"USHRT_MAX:"<<USHRT_MAX;

    return 0;

    }


    *****OUTPUT*****

    CHAR_BIT:   8

    CHAR_MAX:   127

    CHAR_MIN:   -128

    INT_MAX     :   2147483647

    INT_MIN:   -2147483648

    LONG_MAX:   2147483647

    LONG_MIN:   -2147483648

    SCHAR_MAX:   127

    SCHAR_MIN:   -128

    SHRT_MAX    :   32767

    SHRT_MIN:   -32768

    UCHAR_MAX:   255

    UINT_MAX    :   4294967295

    ULONG_MAX:   4294967295

    USHRT_MAX   :   65535


    How To Use float Data Types in C++?

    #include <iostream>

    #include <stdlib.h>

    #include <limits.h>

    #include <float.h>

    using namespace std;

    int main()

    {

    int args;

    char** args;

    cout<<"Storage size for float :"<<sizeof(float)<<"\n";

    cout<<"FLT_MAX: "<<(float) FLT_MAX<<"\n";

    cout<<"FLT_MIN: "<<(float) FLT_MIN<<"\n";

    cout<<"-FLT_MAX: "<<(float) -FLT_MAX<<"\n";

    cout<<"-FLT_MIN: "<<(float) -FLT_MIN<<"\n";

    cout<<"DBL_MAX: "<<(double) DBL_MAX<<"\n";

    cout<<"DBL_MIN: "<<(double) DBL_MIN<<"\n";

    cout<<"Precision: "<<FLT_DIG<<"\n";

    return 0;

    }


    *****OUTPUT*****

    Storage size for float:4

    FLT_MAX: 3.40282e+038

    FLT_MIN: 1.17549e-038

    -FLT_MAX: -3.40282e+038

    -FLT_MIN: -1.17549e-038

    DBL_MAX: 1.79769e+308

    DBL_MIN: 2.22507e-308

    Precision: 6


    Void Data-Type: Void type means no value. This is usually used to specify the type of functions. For Example void main().


    Data Types And Their Control Strings

    3x3 Table

    Data Types

    Size(bytes)

    Format String

    Char

    1

    %c

    Unsigned Char 1 %c
    Short or int 2 %i or %d
    Unsigned int 2 %u
    Long 4 %ld
    Unsigned Long 4 %lu

    Float

    4

    %f or %g

    Double

    8

    %lf

    Long Double

    10

    %lf

    Enum

    2

    %d



    Type Modifiers in C++ Programming Language

    Type Modifiers: The keywords signed, unsigned, short and long are type modifiers. A type modifier changes the meaning of a basic data type and produces a new data type. Each of these type modifiers applies to the basic data type int. 

    The modifiers signed and unsigned are also applicable to the type char. The long-type modifier can be useful to double types.

    Example: Long, int, Unsigned Long int.


    Example: Write a Program to Declare Different Variables With Type Modifiers And Display

    #include<iostream>

    using namespace std;

    void main()

    {

    short t =1;

    long k = 52111;

    unsigned u = 20;

    signed j = -1;

    clrscr();

    court<<“\n t =%d “<<t;

    cout<<“\n k = %ld”<<k;

    cout<<“\n u = %u”<<u;

    cout<<“\n j =%d”<<j;

    }


    *****OUTPUT*****

    k = 54111

    n = 10

    j = -10


    Read Also Post Other Programming Languages



    👉C Data Types


    👉Java Data Types


    Post a Comment

    0 Comments
    * Please Don't Spam Here. All the Comments are Reviewed by Admin.