SlideShare uma empresa Scribd logo
1 de 32
DATA TYPES
 Data types are means to identify the type of data and
associated operations of handling it. C++ provides a
predefined set of data types for handling the data it
uses. When variables are declared of a particular data
type then the variable becomes the place where the
data is stored and data types is the type of value(data)
stored by that variable. Data can be of may types such
as character, integer, real etc. since the data to be
dealt with are of may types, a programming language
must provide different data types.
DATA TYPES
FUNDAMENTAL DATA
TYPES
USER DEFINED DATA
TYPES
DATA TYPE MODIFIERS
DERIVED DATA TYPES
FUNDAMENTAL DATA
TYPES
INTEGER
CHARACTER
DOUBLE
VOID
FLOAT
FUNDAMENTAL DATA TYPES ARE
THOSE THAT ARE NOT COMPOSED
OF OTHER DATA TYPES
 Integers are whole numbers with a machine
dependent range of values. A good programming
language as to support the programmer by
giving a control on a range of numbers and
storage space. C has 3 classes of integer
storage namely short int, int and long int. All of
these data types have signed and unsigned
forms. A short int requires half the space than
normal integer values. Unsigned numbers are
always positive and consume all the bits for the
magnitude of the number. The long and
unsigned integers are used to declare a longer
range of values.
CHARACTER DATA TYPECHARACTER DATA TYPE
It can store any member of the C++
implementation's basic character set. If
a character from this set is stored in a
character variable, its value is
equivalent to the integer code of that
character. Character data type is often
called as integer data type because
the memory implementation of char
data type is in terms of the number
code.
FLOAT DATA TYPE
 A number having fractional part is a floating-
point number. An identifier declared as float
becomes a floating-point variable and can hold
floating-point numbers. floating point variables
represent real numbers. They have two
advantages over integer data types:-
1: they can represent values between integers.
2: they can represent a much greater range of
values.
they have one disadvantage also, that is their
operations are usually slower.
 The data type double is also used for handling
floating-point numbers. But it is treated as a
distinct data type because, it occupies twice as
much memory as type float, and stores floating-
point numbers with much larger range and
precision. It is slower that type float.
 It specifies an empty set of values. It is used
as the return type for functions that do not
return a value. No object of type void may be
declared. It is used when program or
calculation does not require any value but
the syntax needs it.
 int age = 0; will declare an integer variable called
age initialized to the value 0.
 char letter = 'A'; will declare a char variable that
will be initialized to an uppercase A.
 string name = ""; will declare a variable called
name of type string and initialize it to nothing
(a.k.a. the empty string).
 float f; will simply just declare a float variable
called f.
 double trouble; will simply just declare a double
variable called trouble.
 #include <iostream.h>
 #include <string.h>
 using namespace std;
 int main()
 {
▪ string name = "";
▪ int age = 0;
▪ cout << "Enter your first name: ";
▪ cin >> name; cout << "Now enter your age (be honest): ";
▪ cin >> age; cout << "Hello " << name << ".You are " << age << " years
old." << endl;
▪ return 0;
 }
DATA TYPE MODIFIERS
INTEGER TYPE
MODIFIERS
CHARACTER TYPE
MODIFIERS
FLOATING-POINT
MODIFIERS
THEY CHANGE SOME
PROPERTIES OF THE DATA
TYPE
INTEGER TYPE MODIFIERS
• C++ offers three types of integer data type:-
1:- short integer- at least two bytes.
2:- int integer – at least as big as short.
3:- long integer-at least four bytes.
the prefix signed makes the integer type hold
negative values also. Unsigned makes the integer
not to hold negative values.
TYPE APPROXIMATE
SIZE
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
SIGNED LONG 4 Same as long
CHARACTER TYPE
MODIFIER
The char can also be signed or unsigned. unlike
int,char is not signed or unsigned by default. It is later
modified to best fit the type to the hardware
properties.
TYPE APPROXIMAT
E SIZE
MINIMAL
RANGE
CHAR 1 -128 to 127
UNSIGNED
CHAR
1 0 to 255
SIGNED CHAR 1 Same as char
FLOATING POINT TYPE
MODIFIERS
 There are three floating-point types: float, double, and long
double. These types represent minimum allowable range of
types.
Note:- don’t use commas in numeric values assigned to
variables.
TYPE APPROXIMA
TE SIZE
DIGITS
OF
PRECISIO
N
FLOAT 4 7
LONG
DOUBLE
8 15
LONG 10 19
Name Description Size* Range*
char Character or small integer. 1byte
signed: -128 to 127
unsigned: 0 to 255
short int (short) Short Integer. 2bytes
signed: -32768 to 32767
unsigned: 0 to 65535
int Integer. 4bytes
signed: -2147483648 to
2147483647
unsigned: 0 to 4294967295
long int (long) Long integer. 4bytes
signed: -2147483648 to
2147483647
unsigned: 0 to 4294967295
float Floating point number. 4bytes +/- 3.4e +/- 38 (~7 digits)
double
Double precision floating
point number.
8bytes +/- 1.7e +/- 308 (~15 digits)
long double
Long double precision
floating point number.
8bytes +/- 1.7e +/- 308 (~15 digits)
DERIVED DATA TYPES
ARRAYS
POINTERS
REFERENCES
CONSTANTS
FUNCTIONS
ARRAYS
 An array is a series of elements of the same type placed in
contiguous memory locations that can be individually
referenced by adding an index to a unique identifier.
That means that, for example, we can store 5 values of type int
in an array without having to declare 5 different variables, each
one with a different identifier. Instead of that, using an array we
can store 5 different values of the same type, int for example,
with a unique identifier.
 Like a regular variable, an array must be declared before it is
used. A typical declaration for an array in C++ is:
type name [elements];
NOTE:The elements field within brackets [ ] which represents the
number of elements the array is going to hold, must be a constant
value, since arrays are blocks of non-dynamic memory whose size
must be determined before execution.
VALID OPERATIONS WITH ARRAYS:-
 billy[0] = a;
 billy[a] = 75;
 b = billy [a+2];
 billy[billy[a]] = billy[2] + 5;
PROGRAM:-
// arrays example
#include <iostream>
using namespace std;
int billy [] = {16, 2, 77, 40, 12071};
int n, result=0;
int main () OUTPUT:- 12206
{
for ( n=0 ; n<5 ; n++ )
{
result += billy[n];
}
cout << result;
return 0;
}
FUNCTIONS:-
Function groups a number of program statements into a unit and gives it
a name. This unit can be invoked from other parts of a program. A
computer program cannot handle all the tasks by it self. Instead its
requests other program like entities – called functions in C – to get its
tasks done. A function is a self contained block of statements that
perform a coherent task of same kind.
The name of the function is unique in a C Program and is Global. It means
that a function can be accessed from any location with in a C Program.
We pass information to the function called arguments specified when
the function is called. And the function either returns some value to the
point it was called from or returns nothing.
We can divide a long C program into small blocks which can perform a
certain task. A function is a self contained block of statements that
perform a coherent task of same kind.
We first declare the function and then at the end of the program we
define the function.
POINTERS:-
The memory of your computer can be imagined as a
succession of memory cells, each one of the minimal size
that computers manage (one byte). These single-byte
memory cells are numbered in a consecutive way, so as,
within any block of memory, every cell has the same
number as the previous one plus one.
This way, each cell can be easily located in the memory
because it has a unique address and all the memory cells
follow a successive pattern. For example, if we are looking
for cell 1776 we know that it is going to be right between
cells 1775 and 1777, exactly one thousand cells after 776
and exactly one thousand cells before cell 2776.
The general form of declaring the pointer is
type*ptr;
 It is an alternative name for an object. A
reference variable provides an alias for a
previously defined variable. It’s declaration
consists of a base type, an &(ampersand), a
reference variable name equated to a variable
name.
 the general form of declaring is:-
type&ref-var = var-name;
CONSTANTS:-
 C++ constants are not very different from any C++ variable. They
are defined in a similar way and have the same data types and the
same memory limitations. However, there is one major difference -
once a constant has been created and value assigned to it then that
value may not be changed.
 Defining Constants with C++
There are actually three ways of defining a constant in a C++ program:
A. by using the preprocessor
B. by using the const key word
C. by using enumerators - these will have a range of integer values
It's also worth noting that there are two types of constant: literal and
symbolic.
the general form of declaring a variable is:-
const int upperage = 50;
USER DEFINED DERIVED
DATA TYPES
CLASS
STRUCTURE
UNION
ENUMERATION
 Class: A class is a collection of variables and
function under one reference name. it is the
way of separating and storing similar data
together. Member functions are often the
means of accessing, modifying and operating
the data members (i.e. variables). It is one
of the most important features of C++ since
OOP is usually implemented through the use
of classes.
Classes are generally declared using
the keyword class, with the following
format:
class class_name { access_specifier_1:
member1;
access_specifier_2:
member2; ...
} object_names;
STRUCTURES:-
 A data structure is a group of data elements grouped together under one name.
These data elements, known as members, can have different types and different
lengths.
 Data structures are declared in C++ using the following syntax:
struct structure_name {
member_type1 member_name1;
member_type2 member_name2;
member_type3 member_name3;
.
.
} object_names;
 where structure_name is a name for the structure type, object_name can be a set
of valid identifiers for objects that have the type of this structure. Within braces {
} there is a list with the data members, each one is specified with a type and a
valid identifier as its name.
 Structure is different from an array in the sense that an array represents an
aggregate of elements of same type whereas a structure represents an aggregate
of elements of arbitrary types..
 Unions allow one same portion of memory to be accessed as different data
types, since all of them are in fact the same location in memory. Its declaration
and use is similar to the one of structures but its functionality is totally
different:
union union_name {
member_type1 member_name1;
member_type2 member_name2;
member_type3 member_name3;
.
.
} object_names;
 All the elements of the union declaration occupy the same physical space in
memory. Its size is the one of the greatest element of the declaration.
 all of them are referring to the same location in memory, the modification of
one of the elements will affect the value of all of them. We cannot store
different values in them independent of each other.
One of the uses a union may have is to unite an elementary type with an array
or structures of smaller elements.
 The exact alignment and order of the members of a union in memory is
platform dependant. Therefore be aware of possible portability issues with this
type of use.
ENUMERATION:-
 It can be used to assign names to integer constants.
//Program to illustrate Enumerator
#include<iostream.h>
void main(void)
{
enum type{POOR,GOOD,EXCELLENT};//this is the syntax of enumerator
int var;
var=POOR;//this makes programs more understandable
cout<<var<<endl;
var=GOOD;
cout<<var<<endl;
var=EXCELLENT;
cout<<var;
}
//poor=0
good=1
excellent=2
 We have so many data types to allow the
programmer to take advantage of hardware
characteristics. Machines are significantly
different in their memory requirements,
memory access times, and computation speeds.
C++ data types

Mais conteúdo relacionado

Mais procurados

Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++Tech_MX
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS ConceptBoopathi K
 
Inline function
Inline functionInline function
Inline functionTech_MX
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++Muhammad Waqas
 
3 data-types-in-c
3 data-types-in-c3 data-types-in-c
3 data-types-in-cteach4uin
 
Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)MD Sulaiman
 
Pointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpprajshreemuthiah
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++Vishal Patil
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of ConstructorsDhrumil Panchal
 
Functions in c language
Functions in c language Functions in c language
Functions in c language tanmaymodi4
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).pptAlok Kumar
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)Ritika Sharma
 
C data types, arrays and structs
C data types, arrays and structsC data types, arrays and structs
C data types, arrays and structsSaad Sheikh
 
Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2MOHIT TOMAR
 

Mais procurados (20)

Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++
 
concept of oops
concept of oopsconcept of oops
concept of oops
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS Concept
 
Inline function
Inline functionInline function
Inline function
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
 
3 data-types-in-c
3 data-types-in-c3 data-types-in-c
3 data-types-in-c
 
Intro to c++
Intro to c++Intro to c++
Intro to c++
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
 
Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)
 
Function overloading ppt
Function overloading pptFunction overloading ppt
Function overloading ppt
 
Pointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpp
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
 
C data types, arrays and structs
C data types, arrays and structsC data types, arrays and structs
C data types, arrays and structs
 
Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2
 

Destaque

Concept Of C++ Data Types
Concept Of C++ Data TypesConcept Of C++ Data Types
Concept Of C++ Data Typesk v
 
General Tips to Overcome an Interview
General Tips to Overcome an InterviewGeneral Tips to Overcome an Interview
General Tips to Overcome an InterviewPratik Patel
 
Calculus II - 15
Calculus II - 15Calculus II - 15
Calculus II - 15David Mao
 
Variables in C and C++ Language
Variables in C and C++ LanguageVariables in C and C++ Language
Variables in C and C++ LanguageWay2itech
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c languageRai University
 
Basics of Networks ,Advantages and Disadvantages
Basics of  Networks ,Advantages and DisadvantagesBasics of  Networks ,Advantages and Disadvantages
Basics of Networks ,Advantages and Disadvantagessabari Giri
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructorsVineeta Garg
 
Structured query language functions
Structured query language functionsStructured query language functions
Structured query language functionsVineeta Garg
 
Advanced data structures using c++ 3
Advanced data structures using c++ 3Advanced data structures using c++ 3
Advanced data structures using c++ 3Shaili Choudhary
 
Classes and objects1
Classes and objects1Classes and objects1
Classes and objects1Vineeta Garg
 
Structured query language constraints
Structured query language constraintsStructured query language constraints
Structured query language constraintsVineeta Garg
 
c++ programming Unit 1 introduction to c++
c++ programming Unit 1  introduction to c++c++ programming Unit 1  introduction to c++
c++ programming Unit 1 introduction to c++AAKASH KUMAR
 
13. Indexing MTrees - Data Structures using C++ by Varsha Patil
13. Indexing MTrees - Data Structures using C++ by Varsha Patil13. Indexing MTrees - Data Structures using C++ by Varsha Patil
13. Indexing MTrees - Data Structures using C++ by Varsha Patilwidespreadpromotion
 
Discrete Mathematics S. Lipschutz, M. Lipson And V. H. Patil
Discrete Mathematics S. Lipschutz, M. Lipson And V. H. PatilDiscrete Mathematics S. Lipschutz, M. Lipson And V. H. Patil
Discrete Mathematics S. Lipschutz, M. Lipson And V. H. Patilwidespreadpromotion
 
Working with Cookies in NodeJS
Working with Cookies in NodeJSWorking with Cookies in NodeJS
Working with Cookies in NodeJSJay Dihenkar
 

Destaque (20)

Concept Of C++ Data Types
Concept Of C++ Data TypesConcept Of C++ Data Types
Concept Of C++ Data Types
 
Apa style-1 (1)
Apa style-1 (1)Apa style-1 (1)
Apa style-1 (1)
 
General Tips to Overcome an Interview
General Tips to Overcome an InterviewGeneral Tips to Overcome an Interview
General Tips to Overcome an Interview
 
Calculus II - 15
Calculus II - 15Calculus II - 15
Calculus II - 15
 
C data_structures
C  data_structuresC  data_structures
C data_structures
 
Variables in C and C++ Language
Variables in C and C++ LanguageVariables in C and C++ Language
Variables in C and C++ Language
 
C++ basics
C++ basicsC++ basics
C++ basics
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c language
 
Basics of Networks ,Advantages and Disadvantages
Basics of  Networks ,Advantages and DisadvantagesBasics of  Networks ,Advantages and Disadvantages
Basics of Networks ,Advantages and Disadvantages
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
 
Structured query language functions
Structured query language functionsStructured query language functions
Structured query language functions
 
Advanced data structures using c++ 3
Advanced data structures using c++ 3Advanced data structures using c++ 3
Advanced data structures using c++ 3
 
Classes and objects1
Classes and objects1Classes and objects1
Classes and objects1
 
Structured query language constraints
Structured query language constraintsStructured query language constraints
Structured query language constraints
 
c++ programming Unit 1 introduction to c++
c++ programming Unit 1  introduction to c++c++ programming Unit 1  introduction to c++
c++ programming Unit 1 introduction to c++
 
13. Indexing MTrees - Data Structures using C++ by Varsha Patil
13. Indexing MTrees - Data Structures using C++ by Varsha Patil13. Indexing MTrees - Data Structures using C++ by Varsha Patil
13. Indexing MTrees - Data Structures using C++ by Varsha Patil
 
Pp
PpPp
Pp
 
Discrete Mathematics S. Lipschutz, M. Lipson And V. H. Patil
Discrete Mathematics S. Lipschutz, M. Lipson And V. H. PatilDiscrete Mathematics S. Lipschutz, M. Lipson And V. H. Patil
Discrete Mathematics S. Lipschutz, M. Lipson And V. H. Patil
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
 
Working with Cookies in NodeJS
Working with Cookies in NodeJSWorking with Cookies in NodeJS
Working with Cookies in NodeJS
 

Semelhante a C++ data types

Semelhante a C++ data types (20)

Concept of c data types
Concept of c data typesConcept of c data types
Concept of c data types
 
Datatypes
DatatypesDatatypes
Datatypes
 
Data Handling
Data HandlingData Handling
Data Handling
 
Data types
Data typesData types
Data types
 
cassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfcassignmentii-170424105623.pdf
cassignmentii-170424105623.pdf
 
Chapter 2.datatypes and operators
Chapter 2.datatypes and operatorsChapter 2.datatypes and operators
Chapter 2.datatypes and operators
 
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
 
Datatypes in c
Datatypes in cDatatypes in c
Datatypes in c
 
Data type
Data typeData type
Data type
 
Data types in C
Data types in CData types in C
Data types in C
 
Module 1:Introduction
Module 1:IntroductionModule 1:Introduction
Module 1:Introduction
 
Data types
Data typesData types
Data types
 
C PROGRAMMING LANGUAGE
C  PROGRAMMING  LANGUAGEC  PROGRAMMING  LANGUAGE
C PROGRAMMING LANGUAGE
 
Data Types, Variables, and Constants in C# Programming
Data Types, Variables, and Constants in C# ProgrammingData Types, Variables, and Constants in C# Programming
Data Types, Variables, and Constants in C# Programming
 
Structured Languages
Structured LanguagesStructured Languages
Structured Languages
 
UNIT-II VISUAL BASIC.NET | BCA
UNIT-II VISUAL BASIC.NET | BCAUNIT-II VISUAL BASIC.NET | BCA
UNIT-II VISUAL BASIC.NET | BCA
 
Data types in C
Data types in CData types in C
Data types in C
 
FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C Programming
 

Último

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
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
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
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
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
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
 
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
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 

Último (20)

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
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
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
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
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........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
 
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...
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .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
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
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"
 
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"
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 

C++ data types

  • 1.
  • 2. DATA TYPES  Data types are means to identify the type of data and associated operations of handling it. C++ provides a predefined set of data types for handling the data it uses. When variables are declared of a particular data type then the variable becomes the place where the data is stored and data types is the type of value(data) stored by that variable. Data can be of may types such as character, integer, real etc. since the data to be dealt with are of may types, a programming language must provide different data types.
  • 3. DATA TYPES FUNDAMENTAL DATA TYPES USER DEFINED DATA TYPES DATA TYPE MODIFIERS DERIVED DATA TYPES
  • 4. FUNDAMENTAL DATA TYPES INTEGER CHARACTER DOUBLE VOID FLOAT FUNDAMENTAL DATA TYPES ARE THOSE THAT ARE NOT COMPOSED OF OTHER DATA TYPES
  • 5.  Integers are whole numbers with a machine dependent range of values. A good programming language as to support the programmer by giving a control on a range of numbers and storage space. C has 3 classes of integer storage namely short int, int and long int. All of these data types have signed and unsigned forms. A short int requires half the space than normal integer values. Unsigned numbers are always positive and consume all the bits for the magnitude of the number. The long and unsigned integers are used to declare a longer range of values.
  • 6. CHARACTER DATA TYPECHARACTER DATA TYPE It can store any member of the C++ implementation's basic character set. If a character from this set is stored in a character variable, its value is equivalent to the integer code of that character. Character data type is often called as integer data type because the memory implementation of char data type is in terms of the number code.
  • 7. FLOAT DATA TYPE  A number having fractional part is a floating- point number. An identifier declared as float becomes a floating-point variable and can hold floating-point numbers. floating point variables represent real numbers. They have two advantages over integer data types:- 1: they can represent values between integers. 2: they can represent a much greater range of values. they have one disadvantage also, that is their operations are usually slower.
  • 8.  The data type double is also used for handling floating-point numbers. But it is treated as a distinct data type because, it occupies twice as much memory as type float, and stores floating- point numbers with much larger range and precision. It is slower that type float.
  • 9.  It specifies an empty set of values. It is used as the return type for functions that do not return a value. No object of type void may be declared. It is used when program or calculation does not require any value but the syntax needs it.
  • 10.  int age = 0; will declare an integer variable called age initialized to the value 0.  char letter = 'A'; will declare a char variable that will be initialized to an uppercase A.  string name = ""; will declare a variable called name of type string and initialize it to nothing (a.k.a. the empty string).  float f; will simply just declare a float variable called f.  double trouble; will simply just declare a double variable called trouble.
  • 11.  #include <iostream.h>  #include <string.h>  using namespace std;  int main()  { ▪ string name = ""; ▪ int age = 0; ▪ cout << "Enter your first name: "; ▪ cin >> name; cout << "Now enter your age (be honest): "; ▪ cin >> age; cout << "Hello " << name << ".You are " << age << " years old." << endl; ▪ return 0;  }
  • 12. DATA TYPE MODIFIERS INTEGER TYPE MODIFIERS CHARACTER TYPE MODIFIERS FLOATING-POINT MODIFIERS THEY CHANGE SOME PROPERTIES OF THE DATA TYPE
  • 13. INTEGER TYPE MODIFIERS • C++ offers three types of integer data type:- 1:- short integer- at least two bytes. 2:- int integer – at least as big as short. 3:- long integer-at least four bytes. the prefix signed makes the integer type hold negative values also. Unsigned makes the integer not to hold negative values.
  • 14. TYPE APPROXIMATE SIZE 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 SIGNED LONG 4 Same as long
  • 15. CHARACTER TYPE MODIFIER The char can also be signed or unsigned. unlike int,char is not signed or unsigned by default. It is later modified to best fit the type to the hardware properties. TYPE APPROXIMAT E SIZE MINIMAL RANGE CHAR 1 -128 to 127 UNSIGNED CHAR 1 0 to 255 SIGNED CHAR 1 Same as char
  • 16. FLOATING POINT TYPE MODIFIERS  There are three floating-point types: float, double, and long double. These types represent minimum allowable range of types. Note:- don’t use commas in numeric values assigned to variables. TYPE APPROXIMA TE SIZE DIGITS OF PRECISIO N FLOAT 4 7 LONG DOUBLE 8 15 LONG 10 19
  • 17. Name Description Size* Range* char Character or small integer. 1byte signed: -128 to 127 unsigned: 0 to 255 short int (short) Short Integer. 2bytes signed: -32768 to 32767 unsigned: 0 to 65535 int Integer. 4bytes signed: -2147483648 to 2147483647 unsigned: 0 to 4294967295 long int (long) Long integer. 4bytes signed: -2147483648 to 2147483647 unsigned: 0 to 4294967295 float Floating point number. 4bytes +/- 3.4e +/- 38 (~7 digits) double Double precision floating point number. 8bytes +/- 1.7e +/- 308 (~15 digits) long double Long double precision floating point number. 8bytes +/- 1.7e +/- 308 (~15 digits)
  • 19. ARRAYS  An array is a series of elements of the same type placed in contiguous memory locations that can be individually referenced by adding an index to a unique identifier. That means that, for example, we can store 5 values of type int in an array without having to declare 5 different variables, each one with a different identifier. Instead of that, using an array we can store 5 different values of the same type, int for example, with a unique identifier.  Like a regular variable, an array must be declared before it is used. A typical declaration for an array in C++ is: type name [elements]; NOTE:The elements field within brackets [ ] which represents the number of elements the array is going to hold, must be a constant value, since arrays are blocks of non-dynamic memory whose size must be determined before execution.
  • 20. VALID OPERATIONS WITH ARRAYS:-  billy[0] = a;  billy[a] = 75;  b = billy [a+2];  billy[billy[a]] = billy[2] + 5; PROGRAM:- // arrays example #include <iostream> using namespace std; int billy [] = {16, 2, 77, 40, 12071}; int n, result=0; int main () OUTPUT:- 12206 { for ( n=0 ; n<5 ; n++ ) { result += billy[n]; } cout << result; return 0; }
  • 21. FUNCTIONS:- Function groups a number of program statements into a unit and gives it a name. This unit can be invoked from other parts of a program. A computer program cannot handle all the tasks by it self. Instead its requests other program like entities – called functions in C – to get its tasks done. A function is a self contained block of statements that perform a coherent task of same kind. The name of the function is unique in a C Program and is Global. It means that a function can be accessed from any location with in a C Program. We pass information to the function called arguments specified when the function is called. And the function either returns some value to the point it was called from or returns nothing. We can divide a long C program into small blocks which can perform a certain task. A function is a self contained block of statements that perform a coherent task of same kind. We first declare the function and then at the end of the program we define the function.
  • 22. POINTERS:- The memory of your computer can be imagined as a succession of memory cells, each one of the minimal size that computers manage (one byte). These single-byte memory cells are numbered in a consecutive way, so as, within any block of memory, every cell has the same number as the previous one plus one. This way, each cell can be easily located in the memory because it has a unique address and all the memory cells follow a successive pattern. For example, if we are looking for cell 1776 we know that it is going to be right between cells 1775 and 1777, exactly one thousand cells after 776 and exactly one thousand cells before cell 2776. The general form of declaring the pointer is type*ptr;
  • 23.  It is an alternative name for an object. A reference variable provides an alias for a previously defined variable. It’s declaration consists of a base type, an &(ampersand), a reference variable name equated to a variable name.  the general form of declaring is:- type&ref-var = var-name;
  • 24. CONSTANTS:-  C++ constants are not very different from any C++ variable. They are defined in a similar way and have the same data types and the same memory limitations. However, there is one major difference - once a constant has been created and value assigned to it then that value may not be changed.  Defining Constants with C++ There are actually three ways of defining a constant in a C++ program: A. by using the preprocessor B. by using the const key word C. by using enumerators - these will have a range of integer values It's also worth noting that there are two types of constant: literal and symbolic. the general form of declaring a variable is:- const int upperage = 50;
  • 25. USER DEFINED DERIVED DATA TYPES CLASS STRUCTURE UNION ENUMERATION
  • 26.  Class: A class is a collection of variables and function under one reference name. it is the way of separating and storing similar data together. Member functions are often the means of accessing, modifying and operating the data members (i.e. variables). It is one of the most important features of C++ since OOP is usually implemented through the use of classes.
  • 27. Classes are generally declared using the keyword class, with the following format: class class_name { access_specifier_1: member1; access_specifier_2: member2; ... } object_names;
  • 28. STRUCTURES:-  A data structure is a group of data elements grouped together under one name. These data elements, known as members, can have different types and different lengths.  Data structures are declared in C++ using the following syntax: struct structure_name { member_type1 member_name1; member_type2 member_name2; member_type3 member_name3; . . } object_names;  where structure_name is a name for the structure type, object_name can be a set of valid identifiers for objects that have the type of this structure. Within braces { } there is a list with the data members, each one is specified with a type and a valid identifier as its name.  Structure is different from an array in the sense that an array represents an aggregate of elements of same type whereas a structure represents an aggregate of elements of arbitrary types..
  • 29.  Unions allow one same portion of memory to be accessed as different data types, since all of them are in fact the same location in memory. Its declaration and use is similar to the one of structures but its functionality is totally different: union union_name { member_type1 member_name1; member_type2 member_name2; member_type3 member_name3; . . } object_names;  All the elements of the union declaration occupy the same physical space in memory. Its size is the one of the greatest element of the declaration.  all of them are referring to the same location in memory, the modification of one of the elements will affect the value of all of them. We cannot store different values in them independent of each other. One of the uses a union may have is to unite an elementary type with an array or structures of smaller elements.  The exact alignment and order of the members of a union in memory is platform dependant. Therefore be aware of possible portability issues with this type of use.
  • 30. ENUMERATION:-  It can be used to assign names to integer constants. //Program to illustrate Enumerator #include<iostream.h> void main(void) { enum type{POOR,GOOD,EXCELLENT};//this is the syntax of enumerator int var; var=POOR;//this makes programs more understandable cout<<var<<endl; var=GOOD; cout<<var<<endl; var=EXCELLENT; cout<<var; } //poor=0 good=1 excellent=2
  • 31.  We have so many data types to allow the programmer to take advantage of hardware characteristics. Machines are significantly different in their memory requirements, memory access times, and computation speeds.