SlideShare uma empresa Scribd logo
1 de 36
DATA TYPES
      By:-Nokesh prabhakar.
Data Types
Data types are means to identify the type
of data and associated operation of
handling it .

C++ has three types of data types :-
      • Built in data type.

      • Derived data type.

      • User defined data type.
C++ Data
                             Types


User-defined                                         Derived type
    type
   structure                 Built-in                     array
                                                        function
     union
     class
                              type                       pointer
                                                       reference
 enumeration




          Integral                              Floating
                              Void
            type                                  type



   int               char               float           double
Type          Bytes   Range
char          1       -128 to 127
                      signed: -128 to 127
                      unsigned: 0 to 255
short int     2       -31768 to 32767
                      signed: -32768 to 32767
                      unsigned: 0 to 65535
int           2       -32768 to 32767
                      signed: -31768 to 32767
                      unsigned: 0 to 65535
long int      4       -2147483648 to 2147483647
                      signed: -2147483648 to
                      2147483647
                      unsigned: 0 to 4294967295
float         4       3.4E-38 to 3.4E+38
double        8       1.7E-308 to 1.7E+308
long double   10      3.4E-4932 to 1.1E+4932
Built in data type
Built in data types are those who are
not composed of other data types.

There are mainly 5 kinds of build in
data type :-
1.int type.
2.char type.
3.float type.
4.double type.
5.void type.
Void data type
 The void data type specifies an
empty set of values .

  It is used as the return type for
functions that do not return a
value.
Int data type

 Integers are whole number such as 5,39,-
1917,0 etc.

they have no fractional part.

 Integers can have positive as well as
negative value .

 An identifiers declared as int cannot have
fractional part.
Char data type

 characters can store any member of
the c++ implementation’s basic
character set .

 An identifiers declared as char
becomes character variable .

  char set is often said to be a integer
type .
Float data type

  A number having a fractional part is
a floating-point number .

   the decimal point shows that it is a
floating-point number not an integer.

  for ex-31.0 is a floating-point
number not a integer but simply 31 is
a integer.
Double data type

  It is used for handling floating-point
numbers.

  It occupies twice as memory as float.

  It is used when float is too small or
insufficienly precise.
Data type modifiers

The basic data type has modifiers
preceding them .we use modifier to alter
the meaning of the base type to fit various
situation more precisely.

There are 3 types of modifiers:-
 1.Integer type modifiers.

 2.Character type modifiers .
 3.Float type modifiers .
Integer type modifiers

By using different number of bytes to
store values , c++ offers 3 types of
integers :short , int and long that can
represent upto three different integer
sizes.

 A short integer is at least 2 bytes .

 A int integer is at least as big as short .

 A long integer is at least 4 bytes .
APPROXIMATE
 TYPE            SIZE(IN BYTES)
                                    MINIMAL RANGE
short                   2          -32768 to 32767
Unsigned short          2           0 to 65,535
Signed short            2           same as short
Int                     2           -32768 to 32767
Unsigned int            2           0 to 65,535
Signed int              2           same as int
Long                    4             -2,147,483,648 to
                                  2,147,483,647
Unsigned long          4             0 to 4,294,967,295
character type modifiers

The char type can also be signed or
unsigned .

The unsigned char represent the range 0
to 255.

The signed char represent the range -128
to 127.
Type        Approximate      Minimal
                size(in bytes)    range
Char                 1           -128 to 127

Unsigned char        1           0 to 255

Signed char          1            same as char
Floating-point type modifiers

C++ has three floating-point types : float
, double and long double.

float type occupies 4 byte.

Double occupies 8 byte .

Long double occupies 10 byte.
TYPE         approximate Digit of
              size(in bytes) precision
Float             4             7


Double            8             15

Long double       10            19
Derived Data Types
From the built in data types other types
can be derived called derived data types.

There are 5 types of derived data
types :-
1.Arrays.
2.Functions.
3.Pointers.
4.References.
5.Constant.
ARRAYS
Values of similar type stored in continuous
memory locations.

int a[10]; char string[3]=“xyz”;

Array can be one dimensional , two
dimensional , multi dimensional.

For ex-float a[3]; //declares array of three
floats :a[0],a[1],a[2].

Int b[2][4]; //declares a 2 dimension array
of integer:b[0][0], b[0][1], b[0][2], b[0][3],
           b[1][0], b[1][1], b[1][2], b[1][3].
   Two ways to make multidimensional arrays
    ◦ Both examples from Ada
    ◦ Construct specifically as multidimensional.

      matrix: array (1..10, 1..10) of real;
      -- Reference example: matrix(7, 2)

       Looks nice, but has limited functionality.

    ◦ Construct as being an array of arrays.

      matrix: array (1..10) of array (1..10) of real;
      -- Reference example: matrix(7)(2)

Multidimensional Arrays
                                                        20
Functions
Set of statements to perform specific
tasks.

A piece of code that perform specific
task.
Introduces modularity in the code.
Reduces the size of program.
C++ has added many new features
to the functions to make them more
reliable and flexible.
It can be overloaded.
   Function declaration
    ◦ return-type function-name (argument-list);
    ◦ void show();
    ◦ float volume(int x,float y,float z);
   Function definition
    return-type function-name(argument-list)
    {
      statement1;
      statement2;
    }
   Function call
    ◦ function-name(argument-list);
    ◦ volume(a,b,c);




Functions
Pointers
Pointers can be declared and initialized as in
C.


int * ip;   // int pointer
ip = &x; // address of x assigned to ip
*ip = 10; // 10 assigned to x through
indirection
References
A reference is an alternative name of
an object.


        Constant

A constant is a data item whose data value
can never change during the program run.
Classes and Objects
   Class is a way to bind the data and
    procedures that operates on data.
   Class declaration:
    class class_name
    {
       private:
              variable declarations;//class
              function declarations;//members
       public:
              variable declarations;//class
              function declarations;//members
    };//Terminates with a semicolon
Classes and Objects

 Class members that have been declared as
  private can be accessed only from within
  the class.
 Public class members can be accessed
  from outside the class also.
 Supports      data-hiding     and   data
  encapsulation features of OOP.
Classes and Objects

 Objects are run time instance of a class.
 Class is a representation of the object, and
  Object is the actual run time entity which
  holds data and function that has been
  defined in the class.
 Object declaration:
  class_name obj1;
  class_name obj2,obj3;
  class class_name
  {……}obj1,obj2,obj3;
Classes and Objects

   Accessing class members
    ◦ Object-name.function-name(actual-arguments);
    ◦ obj1.setdata(100,34.4);
   Defining Member Functions
    ◦ Outside the class definition.
    return-type class-name::function-name
      (argument declaration)
    {
      Function body;
    }
    ◦ Inside the class definition.
    Same as normal function declaration.
An example: Classes and
Objects
Structures
   Structures Revisited
    ◦ Makes convenient to handle a group of logically
      related data items.
    struct student //declaration
    {
        char name[20];
        int roll_number;
        float total_marks;
    };
    struct student A;// C declaration
    student A;            //C++ declaration
    A.roll_number=999;
    A.total_marks=595.5;
    Final_Total=A.total_marks + 5;
Structures
   Limitations
    ◦ C doesn’t allow it to be treated like built-in data
      types.
    struct complex{float x; float y;};
    struct complex c1,c2,c3;
    c3=c1+c2;//Illegal in C
    ◦ They do not permit data hiding.
Structures in C++
 Can hold variables and functions as
  members.
 Can also declare some of its members as
  ‘private’.
 C++ introduces another user-defined type
  known as ‘class’ to incorporate all these
  extensions.
Unions
   A union is like a record
    ◦ But the different fields take up the same space
      within memory

    union foo {
        int i;
        float f;
        char c[4];
    }

   Union size is 4 bytes!
Union example (from an
assembler)
union DisasmInst {
#ifdef BIG_ENDIAN
  struct { unsigned char a, b, c, d; } chars;
#else
  struct { unsigned char d, c, b, a; } chars;
#endif
  int intv;
  unsigned unsv;
  struct { unsigned offset:16, rt:5, rs:5, op:6; } itype;
  struct { unsigned offset:26, op:6; } jtype;
  struct { unsigned function:6, sa:5, rd:5, rt:5, rs:5,
             op:6; } rtype;
};
void CheckEndian() {

                              Another union
  union {
    char charword[4];
    unsigned int intword;

                              example
  } check;

 check.charword[0]   =   1;
 check.charword[1]   =   2;
 check.charword[2]   =   3;
 check.charword[3]   =   4;

#ifdef BIG_ENDIAN
  if (check.intword != 0x01020304) {                /* big */
    cout << "ERROR: Host machine is not Big Endian.nExiting.n";
    exit (1);
  }
#else
#ifdef LITTLE_ENDIAN
  if (check.intword != 0x04030201) {                /* little */
    cout << "ERROR: Host machine is not Little Endian.nExiting.n";
    exit (1);
  }
#else
  cout << "ERROR: Host machine not defined as Big or Little Endian.n";
  cout << "Exiting.n";
  exit (1);
#endif // LITTLE_ENDIAN
#endif // BIG_ENDIAN
}
Data types

Mais conteúdo relacionado

Mais procurados

constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in CSahithi Naraparaju
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programmingprogramming9
 
structure and union
structure and unionstructure and union
structure and unionstudent
 
Data Types and Variables In C Programming
Data Types and Variables In C ProgrammingData Types and Variables In C Programming
Data Types and Variables In C ProgrammingKamal Acharya
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programmingsavitamhaske
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of ConstructorsDhrumil Panchal
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C ProgrammingShuvongkor Barman
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in clavanya marichamy
 
Recursion in C++
Recursion in C++Recursion in C++
Recursion in C++Maliha Mehr
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++Muhammad Waqas
 
arrays and pointers
arrays and pointersarrays and pointers
arrays and pointersSamiksha Pun
 

Mais procurados (20)

Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
C tokens
C tokensC tokens
C tokens
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in C
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
 
structure and union
structure and unionstructure and union
structure and union
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Introduction to c++ ppt
Introduction to c++ pptIntroduction to c++ ppt
Introduction to c++ ppt
 
Data Types and Variables In C Programming
Data Types and Variables In C ProgrammingData Types and Variables In C Programming
Data Types and Variables In C Programming
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programming
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
C functions
C functionsC functions
C functions
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
 
Recursion in C++
Recursion in C++Recursion in C++
Recursion in C++
 
Structure in C
Structure in CStructure in C
Structure in C
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
 
arrays and pointers
arrays and pointersarrays and pointers
arrays and pointers
 

Semelhante a Data types

Semelhante a Data types (20)

Chapter 2.datatypes and operators
Chapter 2.datatypes and operatorsChapter 2.datatypes and operators
Chapter 2.datatypes and operators
 
Datatypes
DatatypesDatatypes
Datatypes
 
Data Handling
Data HandlingData Handling
Data Handling
 
cassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfcassignmentii-170424105623.pdf
cassignmentii-170424105623.pdf
 
C++ data types
C++ data typesC++ data types
C++ data types
 
java Basic Programming Needs
java Basic Programming Needsjava Basic Programming Needs
java Basic Programming Needs
 
Concept Of C++ Data Types
Concept Of C++ Data TypesConcept Of C++ Data Types
Concept Of C++ Data Types
 
FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2
 
Structured Languages
Structured LanguagesStructured Languages
Structured Languages
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C Programming
 
datatypes-200723165518 (1).pptx
datatypes-200723165518 (1).pptxdatatypes-200723165518 (1).pptx
datatypes-200723165518 (1).pptx
 
Cpprm
CpprmCpprm
Cpprm
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++
 
variablesfinal-170820055428 data type results
variablesfinal-170820055428 data type resultsvariablesfinal-170820055428 data type results
variablesfinal-170820055428 data type results
 
C96e1 session3 c++
C96e1 session3 c++C96e1 session3 c++
C96e1 session3 c++
 
Datatypes in c
Datatypes in cDatatypes in c
Datatypes in c
 
Data types
Data typesData types
Data types
 
What is Data Types and Functions?
What is Data Types and Functions?What is Data Types and Functions?
What is Data Types and Functions?
 
C Sharp Nagina (1)
C Sharp Nagina (1)C Sharp Nagina (1)
C Sharp Nagina (1)
 
C Sharp Jn (1)
C Sharp Jn (1)C Sharp Jn (1)
C Sharp Jn (1)
 

Último

9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 

Último (20)

9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 

Data types

  • 1. DATA TYPES By:-Nokesh prabhakar.
  • 2. Data Types Data types are means to identify the type of data and associated operation of handling it . C++ has three types of data types :- • Built in data type. • Derived data type. • User defined data type.
  • 3. C++ Data Types User-defined Derived type type structure Built-in array function union class type pointer reference enumeration Integral Floating Void type type int char float double
  • 4. Type Bytes Range char 1 -128 to 127 signed: -128 to 127 unsigned: 0 to 255 short int 2 -31768 to 32767 signed: -32768 to 32767 unsigned: 0 to 65535 int 2 -32768 to 32767 signed: -31768 to 32767 unsigned: 0 to 65535 long int 4 -2147483648 to 2147483647 signed: -2147483648 to 2147483647 unsigned: 0 to 4294967295 float 4 3.4E-38 to 3.4E+38 double 8 1.7E-308 to 1.7E+308 long double 10 3.4E-4932 to 1.1E+4932
  • 5. Built in data type Built in data types are those who are not composed of other data types. There are mainly 5 kinds of build in data type :- 1.int type. 2.char type. 3.float type. 4.double type. 5.void type.
  • 6. Void data type The void data type specifies an empty set of values . It is used as the return type for functions that do not return a value.
  • 7. Int data type Integers are whole number such as 5,39,- 1917,0 etc. they have no fractional part. Integers can have positive as well as negative value . An identifiers declared as int cannot have fractional part.
  • 8. Char data type characters can store any member of the c++ implementation’s basic character set . An identifiers declared as char becomes character variable . char set is often said to be a integer type .
  • 9. Float data type A number having a fractional part is a floating-point number . the decimal point shows that it is a floating-point number not an integer. for ex-31.0 is a floating-point number not a integer but simply 31 is a integer.
  • 10. Double data type It is used for handling floating-point numbers. It occupies twice as memory as float. It is used when float is too small or insufficienly precise.
  • 11. Data type modifiers The basic data type has modifiers preceding them .we use modifier to alter the meaning of the base type to fit various situation more precisely. There are 3 types of modifiers:- 1.Integer type modifiers. 2.Character type modifiers . 3.Float type modifiers .
  • 12. Integer type modifiers By using different number of bytes to store values , c++ offers 3 types of integers :short , int and long that can represent upto three different integer sizes. A short integer is at least 2 bytes . A int integer is at least as big as short . A long integer is at least 4 bytes .
  • 13. APPROXIMATE TYPE SIZE(IN BYTES) MINIMAL RANGE short 2 -32768 to 32767 Unsigned short 2 0 to 65,535 Signed short 2 same as short Int 2 -32768 to 32767 Unsigned int 2 0 to 65,535 Signed int 2 same as int Long 4 -2,147,483,648 to 2,147,483,647 Unsigned long 4 0 to 4,294,967,295
  • 14. character type modifiers The char type can also be signed or unsigned . The unsigned char represent the range 0 to 255. The signed char represent the range -128 to 127.
  • 15. Type Approximate Minimal size(in bytes) range Char 1 -128 to 127 Unsigned char 1 0 to 255 Signed char 1 same as char
  • 16. Floating-point type modifiers C++ has three floating-point types : float , double and long double. float type occupies 4 byte. Double occupies 8 byte . Long double occupies 10 byte.
  • 17. TYPE approximate Digit of size(in bytes) precision Float 4 7 Double 8 15 Long double 10 19
  • 18. Derived Data Types From the built in data types other types can be derived called derived data types. There are 5 types of derived data types :- 1.Arrays. 2.Functions. 3.Pointers. 4.References. 5.Constant.
  • 19. ARRAYS Values of similar type stored in continuous memory locations. int a[10]; char string[3]=“xyz”; Array can be one dimensional , two dimensional , multi dimensional. For ex-float a[3]; //declares array of three floats :a[0],a[1],a[2]. Int b[2][4]; //declares a 2 dimension array of integer:b[0][0], b[0][1], b[0][2], b[0][3], b[1][0], b[1][1], b[1][2], b[1][3].
  • 20. Two ways to make multidimensional arrays ◦ Both examples from Ada ◦ Construct specifically as multidimensional. matrix: array (1..10, 1..10) of real; -- Reference example: matrix(7, 2)  Looks nice, but has limited functionality. ◦ Construct as being an array of arrays. matrix: array (1..10) of array (1..10) of real; -- Reference example: matrix(7)(2) Multidimensional Arrays 20
  • 21. Functions Set of statements to perform specific tasks. A piece of code that perform specific task. Introduces modularity in the code. Reduces the size of program. C++ has added many new features to the functions to make them more reliable and flexible. It can be overloaded.
  • 22. Function declaration ◦ return-type function-name (argument-list); ◦ void show(); ◦ float volume(int x,float y,float z);  Function definition return-type function-name(argument-list) { statement1; statement2; }  Function call ◦ function-name(argument-list); ◦ volume(a,b,c); Functions
  • 23. Pointers Pointers can be declared and initialized as in C. int * ip; // int pointer ip = &x; // address of x assigned to ip *ip = 10; // 10 assigned to x through indirection
  • 24. References A reference is an alternative name of an object. Constant A constant is a data item whose data value can never change during the program run.
  • 25. Classes and Objects  Class is a way to bind the data and procedures that operates on data.  Class declaration: class class_name { private: variable declarations;//class function declarations;//members public: variable declarations;//class function declarations;//members };//Terminates with a semicolon
  • 26. Classes and Objects  Class members that have been declared as private can be accessed only from within the class.  Public class members can be accessed from outside the class also.  Supports data-hiding and data encapsulation features of OOP.
  • 27. Classes and Objects  Objects are run time instance of a class.  Class is a representation of the object, and Object is the actual run time entity which holds data and function that has been defined in the class.  Object declaration: class_name obj1; class_name obj2,obj3; class class_name {……}obj1,obj2,obj3;
  • 28. Classes and Objects  Accessing class members ◦ Object-name.function-name(actual-arguments); ◦ obj1.setdata(100,34.4);  Defining Member Functions ◦ Outside the class definition. return-type class-name::function-name (argument declaration) { Function body; } ◦ Inside the class definition. Same as normal function declaration.
  • 29. An example: Classes and Objects
  • 30. Structures  Structures Revisited ◦ Makes convenient to handle a group of logically related data items. struct student //declaration { char name[20]; int roll_number; float total_marks; }; struct student A;// C declaration student A; //C++ declaration A.roll_number=999; A.total_marks=595.5; Final_Total=A.total_marks + 5;
  • 31. Structures  Limitations ◦ C doesn’t allow it to be treated like built-in data types. struct complex{float x; float y;}; struct complex c1,c2,c3; c3=c1+c2;//Illegal in C ◦ They do not permit data hiding.
  • 32. Structures in C++  Can hold variables and functions as members.  Can also declare some of its members as ‘private’.  C++ introduces another user-defined type known as ‘class’ to incorporate all these extensions.
  • 33. Unions  A union is like a record ◦ But the different fields take up the same space within memory union foo { int i; float f; char c[4]; }  Union size is 4 bytes!
  • 34. Union example (from an assembler) union DisasmInst { #ifdef BIG_ENDIAN struct { unsigned char a, b, c, d; } chars; #else struct { unsigned char d, c, b, a; } chars; #endif int intv; unsigned unsv; struct { unsigned offset:16, rt:5, rs:5, op:6; } itype; struct { unsigned offset:26, op:6; } jtype; struct { unsigned function:6, sa:5, rd:5, rt:5, rs:5, op:6; } rtype; };
  • 35. void CheckEndian() { Another union union { char charword[4]; unsigned int intword; example } check; check.charword[0] = 1; check.charword[1] = 2; check.charword[2] = 3; check.charword[3] = 4; #ifdef BIG_ENDIAN if (check.intword != 0x01020304) { /* big */ cout << "ERROR: Host machine is not Big Endian.nExiting.n"; exit (1); } #else #ifdef LITTLE_ENDIAN if (check.intword != 0x04030201) { /* little */ cout << "ERROR: Host machine is not Little Endian.nExiting.n"; exit (1); } #else cout << "ERROR: Host machine not defined as Big or Little Endian.n"; cout << "Exiting.n"; exit (1); #endif // LITTLE_ENDIAN #endif // BIG_ENDIAN }