1. Sanjivani Rural Education Society’s
Sanjivani College of Engineering, Kopargaon-423 603
(An Autonomous Institute, Affiliated to Savitribai Phule Pune University, Pune)
NAAC ‘A’Grade Accredited, ISO 9001:2015 Certified
Department of Computer Engineering
(NBA Accredited)
Subject- Object Oriented Programming (CO212)
Unit 1 – Fundamentals of OOP
Topic – 1.5 Data Types in C++
Prof. V.N.Nirgude
Assistant Professor
E-mail :
nirgudevikascomp@sanjivani.org.in
Contact No: 9975240215
2. Data type
DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 2
➢ A data type specifies the type of value a variable can hold.
➢ General syntax of declaration of data type is:
data_type variable_name;
➢ Example:
int a;
3. C++ DATATYPES
USER-DEFINED TYPE BUILT-IN TYPE DERIVED TYPE
INTEGRAL TYPE VOID FLOATING TYPE
STRUCTURE
UNION
CLASS
ENUMERATION
ARRAY
FUNCTION
POINTER
int char float double
DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 3
4. INTEGRAL DATATYPE
INTEGER DATATYPE:
➢ Keyword: int
➢ Storage space: two bytes
➢ Range of int: -32768 to 32767
CHARACTER DATATYPE:
➢ Keyword: char
➢ Storage space: 1 byte
➢ Range of char: -128 to 127
INTEGRAL TYPE
int char
DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 4
5. FLOAT DATATYPE
➢ Keyword: float
➢ Storage space: 4 bytes
➢ Range of float: 3.4e-38 to 3.4e+38.
FLOATING TYPE
float double
DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 5
6. • Type void was introduced in ANSI C.
Two normal use of void:
➢ To specify the return type of a function when it
is not returning any value.
➢ To indicate an empty argument list to a
function.
Eg:- void function-name ( void )
VOID DATATYPE
BUILT-IN TYPE
VOID
DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 6
7. User Defined Type
C++ DATATYPES
USER-DEFINED TYPE
STRUCTURE
UNION
CLASS
ENUMERATION
DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 7
8. User Defined Type
DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 8
• STRUCTURES:
➢ Structures are used for grouping together elements with dissimilar
types.
➢ The general syntax of a structure:-
struct struct_name
{
Data_type member1;
. . . . .
};
9. User Defined Type
DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 9
• Unions:
➢ Unions are conceptually similar to structures as they allow us
to group together dissimilar type elements inside a single unit.
10. User Defined Type
DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 10
• CLASSES:
➢The entire set of data and functions can be
defined data type with the help of a class.
➢ Once a class has been defined, we can create
objects belonging to that class.
➢ Example: fruit mango;
made a user-
any number of
➢ Created an object mango belonging to the class fruit.
12. Derived Type
DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 12
• ARRAYS:
➢An array is a fixed sequence collection of elements of same
data type that share a common name.
➢ General syntax is:
data_type array_name[size];
➢ Example:
int a[10];
13. Derived Type
DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 13
• FUNCTIONS:
➢ A function is a group of statements that together perform a task.
➢Every c++ program has at least one function, which is
main().
void main()
{
Statements;
}
14. Derived Type
DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 14
• POINTERS:
➢ A pointer is a variable that holds a memory address.
➢ General syntax to declare pointer is:-
Data_type *pointer_name;
➢ Example:
int *p;