SlideShare a Scribd company logo
2
DYNAMIC OBJECTS
C++ supports dynamic memory allocation and deallocation . C++
allocates memory and initializes the member variables.
An object can be created at run-time ; such an object is called a
dynamic object.
The new and delete operators are used to allocate and
deallocate memory to such objects.
Most read
3
NEW Operator
The new operator is used to allocate memory at runtime.
The memory is allocated in bytes.
Syntax:
DATA TYPE *ptr = new DATA TYPE;
// Pointer initialized with NULL
// Then request memory for the variable
int *p = NULL;
p = new int;
OR
// Combine declaration of pointer
// and their assignment
int *p = new int;
Most read
7
ADVANTAGES:
The main advantage of using dynamic memory allocation
is preventing the wastage of memory.
We can allocate (create) additional storage whenever we
need them.
We can de-allocate (free/delete) dynamic space whenever
we are done with them
Most read
‘ Dynamic objects, pointer to function, array
and pointers, character string processing ’
Presented By:
Muskaan (MCA/25020/18)
Prashi Jain (MCA/25022/18)
DYNAMIC OBJECTS
C++ supports dynamic memory allocation and deallocation . C++
allocates memory and initializes the member variables.
An object can be created at run-time ; such an object is called a
dynamic object.
The new and delete operators are used to allocate and
deallocate memory to such objects.
NEW Operator
The new operator is used to allocate memory at runtime.
The memory is allocated in bytes.
Syntax:
DATA TYPE *ptr = new DATA TYPE;
// Pointer initialized with NULL
// Then request memory for the variable
int *p = NULL;
p = new int;
OR
// Combine declaration of pointer
// and their assignment
int *p = new int;
We can initialize a variable while dynamical allocation in the
following way:
int *ptr = new int (4);
Example:
#include<iostream.h>
#include<conio.h>
int main()
{
int *ptr = new int;
*ptr = 4;
cout << *ptr << endl ;
return 0;
}
OUTPUT: 4
DELETE Operator
A dynamic object can be distroyed by using the DELETE
operator
Syntax :
delete ptr;
Here ptr is the pointer to the dynamically allocated
variable
The delete operator simply returns the memory allocated
back to the operating system so that it can be used again.
Let’s look at an example:
int main()
{
int *ptr = new int;
*ptr = 4;
cout << *ptr << endl;
delete ptr;
return 0;
}
OUTPUT: 4
ADVANTAGES:
The main advantage of using dynamic memory allocation
is preventing the wastage of memory.
We can allocate (create) additional storage whenever we
need them.
We can de-allocate (free/delete) dynamic space whenever
we are done with them
POINTER TO FUNCTION
C++ allows you to pass a pointer to a function.
Simply declare the function parameter as a pointer type.
 Syntax:
data type fun_name(data type *arg)
Let’s look at an example:
#include <iostream.h>
void swap( int *a, int *b )
{
int t;
t = *a;
*a = *b;
*b = t;
}
int main()
{
int num1, num2;
cout << "Enter first number" << endl;
cin >> num1;
cout << "Enter second number" << endl;
cin >> num2;
swap( &num1, &num2);
cout << "First number = " << num1 << endl;
cout << "Second number = " << num2 << endl;
return 0;
}
OUTPUT:
Enter first number
2
Enter second number
4
First number = 4
Second number = 2
Arrays and pointers
Array
An array is collection of items stored at
continues memory locations.
Syntax : Int arr[10]; //Array declaration by
specifying size
Pointers
A pointer is a variable whose value is the
address of another variable. Like any variable or
constant.
Syntax : type * var_name; //declaration of an
pointer
Example: int *p,a;
p=&a;
Arrays and pointers
Arrays and pointers are very closely related in c++.
For Example: An array declared as
Int a[10]
Can also be accessed using its pointers representation . The
name of the array is a constant pointer to the first element of the
array. So a can be considered as const int*.
Here arr points to the
first element of the array
For example:
In array and pointers ptr[i] and*(ptr+i) are considered as same.
Int a[4]={10,20,30,40};
Int *ptr = a;
for(int i =0 ; i<4; i++)
{
cout<< *(ptr+i) <<endl;
}
Output: 10
20
30
40
For the same array
For(int i=0 ; i<4;i++)
{
Cout<< ptr[i] <<endl;
}
Output:
10
20
30
40
Character string processing
String:
In C++, the one-dimensional array of characters
are called strings, which is terminated by a null
character 0.
Syntax: char greeting[6];
What is character string processing?
Character string processing basically means
accessing (insertion and extraction operators)
the characters from a string.
C++ provides following two types of string
representations −
• The C-style character string.
• The string class type introduced with Standard
C++.
Insertion operator : The result of inserting a char pointer to
an output stream is same as displaying a char array whose
first element is located at the address to which the char*
object points.
Example: Char text[9]= “world”;
For(char *ptr = text; *ptr!= ‘0’ ; ++ptr)
{ Cout<< ptr << endl;
}
Output : world
orld
rld
ld
d
Extraction operator
When the right operand of an extraction operator is a char*
object, the behaves same as extraction from char array- by
default leading white space is skipped and the next
nonwhitespace string of characters is extracted.
For example: char str[40];
Cout<<“enter a string:” ;
Cin>> str;
Cout<<“you entered :” <<str <<endl;
}
Output : enter a string : programming is fun
you entered: programming
String functions
1- strlen(): returns the length of the sytring.
Syntax: int strlen(s1);
2- strcpy(): copies one string to another string.
Syntax: char *strcpy(s1 , s2);
3- strcat(): this function concates two strings.
syntax: char *strcat(s1 , s2 );
4- strcmp(): compares two strings.
syntax: strcmp(s1 ,s2);
THANK YOU

More Related Content

What's hot (20)

Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
Shyam Gupta
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
Vineeta Garg
 
Chapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptChapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.ppt
AmanuelZewdie4
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
Neeru Mittal
 
Chapter 1 2 - some size factors
Chapter 1   2 - some size factorsChapter 1   2 - some size factors
Chapter 1 2 - some size factors
NancyBeaulah_R
 
C Structures and Unions
C Structures and UnionsC Structures and Unions
C Structures and Unions
Dhrumil Patel
 
Features of c language 1
Features of c language 1Features of c language 1
Features of c language 1
srmohan06
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
Githushan Gengaparam
 
C Programming Assignment
C Programming AssignmentC Programming Assignment
C Programming Assignment
Vijayananda Mohire
 
parameter passing in c#
parameter passing in c#parameter passing in c#
parameter passing in c#
khush_boo31
 
This pointer
This pointerThis pointer
This pointer
Kamal Acharya
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
Mauryasuraj98
 
Java- Nested Classes
Java- Nested ClassesJava- Nested Classes
Java- Nested Classes
Prabhdeep Singh
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
programming9
 
C++ string
C++ stringC++ string
C++ string
Dheenadayalan18
 
Structures
StructuresStructures
Structures
DrJasmineBeulahG
 
Parameter passing to_functions_in_c
Parameter passing to_functions_in_cParameter passing to_functions_in_c
Parameter passing to_functions_in_c
ForwardBlog Enewzletter
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
Harsh Patel
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming Language
Steve Johnson
 
Chapter 07 inheritance
Chapter 07 inheritanceChapter 07 inheritance
Chapter 07 inheritance
Praveen M Jigajinni
 

Similar to Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing (20)

Pointers in C++ object oriented programming
Pointers in C++ object oriented programmingPointers in C++ object oriented programming
Pointers in C++ object oriented programming
Ahmad177077
 
Introduction to pointers in c plus plus .
Introduction to pointers in c plus plus .Introduction to pointers in c plus plus .
Introduction to pointers in c plus plus .
karimibaryal1996
 
C++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptxC++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptx
ShashiShash2
 
Unit 6 pointers
Unit 6   pointersUnit 6   pointers
Unit 6 pointers
George Erfesoglou
 
C++ Functions.ppt
C++ Functions.pptC++ Functions.ppt
C++ Functions.ppt
WaheedAnwar20
 
CPP Language Basics - Reference
CPP Language Basics - ReferenceCPP Language Basics - Reference
CPP Language Basics - Reference
Mohammed Sikander
 
C Programming - Refresher - Part III
C Programming - Refresher - Part IIIC Programming - Refresher - Part III
C Programming - Refresher - Part III
Emertxe Information Technologies Pvt Ltd
 
Arrry structure Stacks in data structure
Arrry structure Stacks  in data structureArrry structure Stacks  in data structure
Arrry structure Stacks in data structure
lodhran-hayat
 
Computer Programming for Engineers Spring 2023Lab 8 - Pointers.pptx
Computer Programming for Engineers Spring 2023Lab 8 - Pointers.pptxComputer Programming for Engineers Spring 2023Lab 8 - Pointers.pptx
Computer Programming for Engineers Spring 2023Lab 8 - Pointers.pptx
ab11167
 
Lecture2.ppt
Lecture2.pptLecture2.ppt
Lecture2.ppt
Sabaunnisa3
 
C++ Secure Programming
C++ Secure ProgrammingC++ Secure Programming
C++ Secure Programming
Marian Marinov
 
8 Pointers
8 Pointers8 Pointers
8 Pointers
Praveen M Jigajinni
 
Data Structures asdasdasdasdasdasdasdasdasdasd
Data Structures asdasdasdasdasdasdasdasdasdasdData Structures asdasdasdasdasdasdasdasdasdasd
Data Structures asdasdasdasdasdasdasdasdasdasd
abdulrahman39ab
 
Pointer
PointerPointer
Pointer
saeeb12
 
C++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfC++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdf
yamew16788
 
COM1407: Working with Pointers
COM1407: Working with PointersCOM1407: Working with Pointers
COM1407: Working with Pointers
Hemantha Kulathilake
 
c programming
c programmingc programming
c programming
Arun Umrao
 
chapter-11-pointers.pdf
chapter-11-pointers.pdfchapter-11-pointers.pdf
chapter-11-pointers.pdf
study material
 
Lecture 9_Classes.pptx
Lecture 9_Classes.pptxLecture 9_Classes.pptx
Lecture 9_Classes.pptx
NelyJay
 
Assignment c programming
Assignment c programmingAssignment c programming
Assignment c programming
Icaii Infotech
 
Pointers in C++ object oriented programming
Pointers in C++ object oriented programmingPointers in C++ object oriented programming
Pointers in C++ object oriented programming
Ahmad177077
 
Introduction to pointers in c plus plus .
Introduction to pointers in c plus plus .Introduction to pointers in c plus plus .
Introduction to pointers in c plus plus .
karimibaryal1996
 
C++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptxC++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptx
ShashiShash2
 
CPP Language Basics - Reference
CPP Language Basics - ReferenceCPP Language Basics - Reference
CPP Language Basics - Reference
Mohammed Sikander
 
Arrry structure Stacks in data structure
Arrry structure Stacks  in data structureArrry structure Stacks  in data structure
Arrry structure Stacks in data structure
lodhran-hayat
 
Computer Programming for Engineers Spring 2023Lab 8 - Pointers.pptx
Computer Programming for Engineers Spring 2023Lab 8 - Pointers.pptxComputer Programming for Engineers Spring 2023Lab 8 - Pointers.pptx
Computer Programming for Engineers Spring 2023Lab 8 - Pointers.pptx
ab11167
 
C++ Secure Programming
C++ Secure ProgrammingC++ Secure Programming
C++ Secure Programming
Marian Marinov
 
Data Structures asdasdasdasdasdasdasdasdasdasd
Data Structures asdasdasdasdasdasdasdasdasdasdData Structures asdasdasdasdasdasdasdasdasdasd
Data Structures asdasdasdasdasdasdasdasdasdasd
abdulrahman39ab
 
C++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfC++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdf
yamew16788
 
chapter-11-pointers.pdf
chapter-11-pointers.pdfchapter-11-pointers.pdf
chapter-11-pointers.pdf
study material
 
Lecture 9_Classes.pptx
Lecture 9_Classes.pptxLecture 9_Classes.pptx
Lecture 9_Classes.pptx
NelyJay
 
Assignment c programming
Assignment c programmingAssignment c programming
Assignment c programming
Icaii Infotech
 
Ad

More from Meghaj Mallick (20)

24 partial-orderings
24 partial-orderings24 partial-orderings
24 partial-orderings
Meghaj Mallick
 
PORTFOLIO BY USING HTML & CSS
PORTFOLIO BY USING HTML & CSSPORTFOLIO BY USING HTML & CSS
PORTFOLIO BY USING HTML & CSS
Meghaj Mallick
 
Introduction to Software Testing
Introduction to Software TestingIntroduction to Software Testing
Introduction to Software Testing
Meghaj Mallick
 
Introduction to System Programming
Introduction to System ProgrammingIntroduction to System Programming
Introduction to System Programming
Meghaj Mallick
 
MACRO ASSEBLER
MACRO ASSEBLERMACRO ASSEBLER
MACRO ASSEBLER
Meghaj Mallick
 
Icons, Image & Multimedia
Icons, Image & MultimediaIcons, Image & Multimedia
Icons, Image & Multimedia
Meghaj Mallick
 
Project Tracking & SPC
Project Tracking & SPCProject Tracking & SPC
Project Tracking & SPC
Meghaj Mallick
 
Peephole Optimization
Peephole OptimizationPeephole Optimization
Peephole Optimization
Meghaj Mallick
 
Routing in MANET
Routing in MANETRouting in MANET
Routing in MANET
Meghaj Mallick
 
Macro assembler
 Macro assembler Macro assembler
Macro assembler
Meghaj Mallick
 
Architecture and security in Vanet PPT
Architecture and security in Vanet PPTArchitecture and security in Vanet PPT
Architecture and security in Vanet PPT
Meghaj Mallick
 
Design Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software EngineeringDesign Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software Engineering
Meghaj Mallick
 
Text Mining of Twitter in Data Mining
Text Mining of Twitter in Data MiningText Mining of Twitter in Data Mining
Text Mining of Twitter in Data Mining
Meghaj Mallick
 
DFS & BFS in Computer Algorithm
DFS & BFS in Computer AlgorithmDFS & BFS in Computer Algorithm
DFS & BFS in Computer Algorithm
Meghaj Mallick
 
Software Development Method
Software Development MethodSoftware Development Method
Software Development Method
Meghaj Mallick
 
Secant method in Numerical & Statistical Method
Secant method in Numerical & Statistical MethodSecant method in Numerical & Statistical Method
Secant method in Numerical & Statistical Method
Meghaj Mallick
 
Motivation in Organization
Motivation in OrganizationMotivation in Organization
Motivation in Organization
Meghaj Mallick
 
Communication Skill
Communication SkillCommunication Skill
Communication Skill
Meghaj Mallick
 
Partial-Orderings in Discrete Mathematics
 Partial-Orderings in Discrete Mathematics Partial-Orderings in Discrete Mathematics
Partial-Orderings in Discrete Mathematics
Meghaj Mallick
 
Hashing In Data Structure
Hashing In Data Structure Hashing In Data Structure
Hashing In Data Structure
Meghaj Mallick
 
PORTFOLIO BY USING HTML & CSS
PORTFOLIO BY USING HTML & CSSPORTFOLIO BY USING HTML & CSS
PORTFOLIO BY USING HTML & CSS
Meghaj Mallick
 
Introduction to Software Testing
Introduction to Software TestingIntroduction to Software Testing
Introduction to Software Testing
Meghaj Mallick
 
Introduction to System Programming
Introduction to System ProgrammingIntroduction to System Programming
Introduction to System Programming
Meghaj Mallick
 
Icons, Image & Multimedia
Icons, Image & MultimediaIcons, Image & Multimedia
Icons, Image & Multimedia
Meghaj Mallick
 
Project Tracking & SPC
Project Tracking & SPCProject Tracking & SPC
Project Tracking & SPC
Meghaj Mallick
 
Architecture and security in Vanet PPT
Architecture and security in Vanet PPTArchitecture and security in Vanet PPT
Architecture and security in Vanet PPT
Meghaj Mallick
 
Design Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software EngineeringDesign Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software Engineering
Meghaj Mallick
 
Text Mining of Twitter in Data Mining
Text Mining of Twitter in Data MiningText Mining of Twitter in Data Mining
Text Mining of Twitter in Data Mining
Meghaj Mallick
 
DFS & BFS in Computer Algorithm
DFS & BFS in Computer AlgorithmDFS & BFS in Computer Algorithm
DFS & BFS in Computer Algorithm
Meghaj Mallick
 
Software Development Method
Software Development MethodSoftware Development Method
Software Development Method
Meghaj Mallick
 
Secant method in Numerical & Statistical Method
Secant method in Numerical & Statistical MethodSecant method in Numerical & Statistical Method
Secant method in Numerical & Statistical Method
Meghaj Mallick
 
Motivation in Organization
Motivation in OrganizationMotivation in Organization
Motivation in Organization
Meghaj Mallick
 
Partial-Orderings in Discrete Mathematics
 Partial-Orderings in Discrete Mathematics Partial-Orderings in Discrete Mathematics
Partial-Orderings in Discrete Mathematics
Meghaj Mallick
 
Hashing In Data Structure
Hashing In Data Structure Hashing In Data Structure
Hashing In Data Structure
Meghaj Mallick
 
Ad

Recently uploaded (20)

Driving License making Guide Sri Lanka.pptx
Driving License making Guide Sri Lanka.pptxDriving License making Guide Sri Lanka.pptx
Driving License making Guide Sri Lanka.pptx
jmtj526b
 
Presentation SoftwareNOTES AND USES..pdf
Presentation SoftwareNOTES AND USES..pdfPresentation SoftwareNOTES AND USES..pdf
Presentation SoftwareNOTES AND USES..pdf
bathyates
 
3b. Jur Erbrink - session 3 pitch.pdf Presentatie CIRED Voorbereidingsdag
3b. Jur Erbrink - session 3 pitch.pdf Presentatie CIRED Voorbereidingsdag3b. Jur Erbrink - session 3 pitch.pdf Presentatie CIRED Voorbereidingsdag
3b. Jur Erbrink - session 3 pitch.pdf Presentatie CIRED Voorbereidingsdag
Dutch Power
 
Apresentação sobre a Marinha do Brasil .
Apresentação sobre a Marinha do Brasil  .Apresentação sobre a Marinha do Brasil  .
Apresentação sobre a Marinha do Brasil .
romulobfernandes
 
DLD Bounas Assignment IOT.pdf by nouman saleem
DLD Bounas Assignment IOT.pdf by nouman saleemDLD Bounas Assignment IOT.pdf by nouman saleem
DLD Bounas Assignment IOT.pdf by nouman saleem
noumansaleempc
 
Generalizability SPOCs - Conference presentation - LASI Spain 2025
Generalizability SPOCs - Conference presentation - LASI Spain 2025Generalizability SPOCs - Conference presentation - LASI Spain 2025
Generalizability SPOCs - Conference presentation - LASI Spain 2025
pmmorenom01
 
Streamline English Destinations.pdf for ev
Streamline English Destinations.pdf for evStreamline English Destinations.pdf for ev
Streamline English Destinations.pdf for ev
PhuongNguyen180931
 
1. Martin Binnendijk - Rory Leich - Daniel Woldendorp - Session 1.pdf
1. Martin Binnendijk - Rory Leich - Daniel Woldendorp - Session 1.pdf1. Martin Binnendijk - Rory Leich - Daniel Woldendorp - Session 1.pdf
1. Martin Binnendijk - Rory Leich - Daniel Woldendorp - Session 1.pdf
Dutch Power
 
3-LIPIDS.pdfhhydfnpoufddgkhkuhhyjfyfgvfrgn
3-LIPIDS.pdfhhydfnpoufddgkhkuhhyjfyfgvfrgn3-LIPIDS.pdfhhydfnpoufddgkhkuhhyjfyfgvfrgn
3-LIPIDS.pdfhhydfnpoufddgkhkuhhyjfyfgvfrgn
s241141868
 
3d. Alejandra Jimenz Rosales - Session 3 pitch.pdf
3d. Alejandra Jimenz Rosales - Session 3 pitch.pdf3d. Alejandra Jimenz Rosales - Session 3 pitch.pdf
3d. Alejandra Jimenz Rosales - Session 3 pitch.pdf
Dutch Power
 
3A. Alain Stuivenvolt - session 3 pitch.pdf
3A. Alain Stuivenvolt - session 3 pitch.pdf3A. Alain Stuivenvolt - session 3 pitch.pdf
3A. Alain Stuivenvolt - session 3 pitch.pdf
Dutch Power
 
2025-06-08 Abraham 02 (shared slides).pptx
2025-06-08 Abraham 02 (shared slides).pptx2025-06-08 Abraham 02 (shared slides).pptx
2025-06-08 Abraham 02 (shared slides).pptx
Dale Wells
 
ART INTAGRATED PROJECT in chemistry about resources
ART INTAGRATED PROJECT in chemistry about resourcesART INTAGRATED PROJECT in chemistry about resources
ART INTAGRATED PROJECT in chemistry about resources
mcarchana74
 
Presenation - compensation plan - Mining Race - NEW - June 2025
Presenation - compensation plan - Mining Race - NEW - June 2025Presenation - compensation plan - Mining Race - NEW - June 2025
Presenation - compensation plan - Mining Race - NEW - June 2025
Mining RACE
 
Diddy Baby oil making tutorial (natural ingresients.pptx
Diddy Baby oil making tutorial (natural ingresients.pptxDiddy Baby oil making tutorial (natural ingresients.pptx
Diddy Baby oil making tutorial (natural ingresients.pptx
RanitMal
 
Road safety presentation for high school
Road safety presentation for high schoolRoad safety presentation for high school
Road safety presentation for high school
nikhithavarghese77
 
Seminar Presented by Natnael Dechasa Title: Brain Cheat Codes: The Science-Ba...
Seminar Presented by Natnael Dechasa Title: Brain Cheat Codes: The Science-Ba...Seminar Presented by Natnael Dechasa Title: Brain Cheat Codes: The Science-Ba...
Seminar Presented by Natnael Dechasa Title: Brain Cheat Codes: The Science-Ba...
Nati1986
 
From Idea to Impact: Maximizing Your Hackathon Performance
From Idea to Impact: Maximizing Your Hackathon PerformanceFrom Idea to Impact: Maximizing Your Hackathon Performance
From Idea to Impact: Maximizing Your Hackathon Performance
outsystemspuneusergr
 
FUTURE OF FITNESS 2025 KEYNOTE BRYAN OROURKE BEYOND ACTIV SINGAPORE 2025
FUTURE OF FITNESS 2025 KEYNOTE BRYAN OROURKE BEYOND ACTIV SINGAPORE 2025FUTURE OF FITNESS 2025 KEYNOTE BRYAN OROURKE BEYOND ACTIV SINGAPORE 2025
FUTURE OF FITNESS 2025 KEYNOTE BRYAN OROURKE BEYOND ACTIV SINGAPORE 2025
Bryan K. O'Rourke
 
Group 2- Formulating the Research Problem-NICOLAS, MA. GENOVEVA D..pptx
Group 2- Formulating the Research Problem-NICOLAS, MA. GENOVEVA D..pptxGroup 2- Formulating the Research Problem-NICOLAS, MA. GENOVEVA D..pptx
Group 2- Formulating the Research Problem-NICOLAS, MA. GENOVEVA D..pptx
mhiranicolas1
 
Driving License making Guide Sri Lanka.pptx
Driving License making Guide Sri Lanka.pptxDriving License making Guide Sri Lanka.pptx
Driving License making Guide Sri Lanka.pptx
jmtj526b
 
Presentation SoftwareNOTES AND USES..pdf
Presentation SoftwareNOTES AND USES..pdfPresentation SoftwareNOTES AND USES..pdf
Presentation SoftwareNOTES AND USES..pdf
bathyates
 
3b. Jur Erbrink - session 3 pitch.pdf Presentatie CIRED Voorbereidingsdag
3b. Jur Erbrink - session 3 pitch.pdf Presentatie CIRED Voorbereidingsdag3b. Jur Erbrink - session 3 pitch.pdf Presentatie CIRED Voorbereidingsdag
3b. Jur Erbrink - session 3 pitch.pdf Presentatie CIRED Voorbereidingsdag
Dutch Power
 
Apresentação sobre a Marinha do Brasil .
Apresentação sobre a Marinha do Brasil  .Apresentação sobre a Marinha do Brasil  .
Apresentação sobre a Marinha do Brasil .
romulobfernandes
 
DLD Bounas Assignment IOT.pdf by nouman saleem
DLD Bounas Assignment IOT.pdf by nouman saleemDLD Bounas Assignment IOT.pdf by nouman saleem
DLD Bounas Assignment IOT.pdf by nouman saleem
noumansaleempc
 
Generalizability SPOCs - Conference presentation - LASI Spain 2025
Generalizability SPOCs - Conference presentation - LASI Spain 2025Generalizability SPOCs - Conference presentation - LASI Spain 2025
Generalizability SPOCs - Conference presentation - LASI Spain 2025
pmmorenom01
 
Streamline English Destinations.pdf for ev
Streamline English Destinations.pdf for evStreamline English Destinations.pdf for ev
Streamline English Destinations.pdf for ev
PhuongNguyen180931
 
1. Martin Binnendijk - Rory Leich - Daniel Woldendorp - Session 1.pdf
1. Martin Binnendijk - Rory Leich - Daniel Woldendorp - Session 1.pdf1. Martin Binnendijk - Rory Leich - Daniel Woldendorp - Session 1.pdf
1. Martin Binnendijk - Rory Leich - Daniel Woldendorp - Session 1.pdf
Dutch Power
 
3-LIPIDS.pdfhhydfnpoufddgkhkuhhyjfyfgvfrgn
3-LIPIDS.pdfhhydfnpoufddgkhkuhhyjfyfgvfrgn3-LIPIDS.pdfhhydfnpoufddgkhkuhhyjfyfgvfrgn
3-LIPIDS.pdfhhydfnpoufddgkhkuhhyjfyfgvfrgn
s241141868
 
3d. Alejandra Jimenz Rosales - Session 3 pitch.pdf
3d. Alejandra Jimenz Rosales - Session 3 pitch.pdf3d. Alejandra Jimenz Rosales - Session 3 pitch.pdf
3d. Alejandra Jimenz Rosales - Session 3 pitch.pdf
Dutch Power
 
3A. Alain Stuivenvolt - session 3 pitch.pdf
3A. Alain Stuivenvolt - session 3 pitch.pdf3A. Alain Stuivenvolt - session 3 pitch.pdf
3A. Alain Stuivenvolt - session 3 pitch.pdf
Dutch Power
 
2025-06-08 Abraham 02 (shared slides).pptx
2025-06-08 Abraham 02 (shared slides).pptx2025-06-08 Abraham 02 (shared slides).pptx
2025-06-08 Abraham 02 (shared slides).pptx
Dale Wells
 
ART INTAGRATED PROJECT in chemistry about resources
ART INTAGRATED PROJECT in chemistry about resourcesART INTAGRATED PROJECT in chemistry about resources
ART INTAGRATED PROJECT in chemistry about resources
mcarchana74
 
Presenation - compensation plan - Mining Race - NEW - June 2025
Presenation - compensation plan - Mining Race - NEW - June 2025Presenation - compensation plan - Mining Race - NEW - June 2025
Presenation - compensation plan - Mining Race - NEW - June 2025
Mining RACE
 
Diddy Baby oil making tutorial (natural ingresients.pptx
Diddy Baby oil making tutorial (natural ingresients.pptxDiddy Baby oil making tutorial (natural ingresients.pptx
Diddy Baby oil making tutorial (natural ingresients.pptx
RanitMal
 
Road safety presentation for high school
Road safety presentation for high schoolRoad safety presentation for high school
Road safety presentation for high school
nikhithavarghese77
 
Seminar Presented by Natnael Dechasa Title: Brain Cheat Codes: The Science-Ba...
Seminar Presented by Natnael Dechasa Title: Brain Cheat Codes: The Science-Ba...Seminar Presented by Natnael Dechasa Title: Brain Cheat Codes: The Science-Ba...
Seminar Presented by Natnael Dechasa Title: Brain Cheat Codes: The Science-Ba...
Nati1986
 
From Idea to Impact: Maximizing Your Hackathon Performance
From Idea to Impact: Maximizing Your Hackathon PerformanceFrom Idea to Impact: Maximizing Your Hackathon Performance
From Idea to Impact: Maximizing Your Hackathon Performance
outsystemspuneusergr
 
FUTURE OF FITNESS 2025 KEYNOTE BRYAN OROURKE BEYOND ACTIV SINGAPORE 2025
FUTURE OF FITNESS 2025 KEYNOTE BRYAN OROURKE BEYOND ACTIV SINGAPORE 2025FUTURE OF FITNESS 2025 KEYNOTE BRYAN OROURKE BEYOND ACTIV SINGAPORE 2025
FUTURE OF FITNESS 2025 KEYNOTE BRYAN OROURKE BEYOND ACTIV SINGAPORE 2025
Bryan K. O'Rourke
 
Group 2- Formulating the Research Problem-NICOLAS, MA. GENOVEVA D..pptx
Group 2- Formulating the Research Problem-NICOLAS, MA. GENOVEVA D..pptxGroup 2- Formulating the Research Problem-NICOLAS, MA. GENOVEVA D..pptx
Group 2- Formulating the Research Problem-NICOLAS, MA. GENOVEVA D..pptx
mhiranicolas1
 

Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing

  • 1. ‘ Dynamic objects, pointer to function, array and pointers, character string processing ’ Presented By: Muskaan (MCA/25020/18) Prashi Jain (MCA/25022/18)
  • 2. DYNAMIC OBJECTS C++ supports dynamic memory allocation and deallocation . C++ allocates memory and initializes the member variables. An object can be created at run-time ; such an object is called a dynamic object. The new and delete operators are used to allocate and deallocate memory to such objects.
  • 3. NEW Operator The new operator is used to allocate memory at runtime. The memory is allocated in bytes. Syntax: DATA TYPE *ptr = new DATA TYPE; // Pointer initialized with NULL // Then request memory for the variable int *p = NULL; p = new int; OR // Combine declaration of pointer // and their assignment int *p = new int;
  • 4. We can initialize a variable while dynamical allocation in the following way: int *ptr = new int (4); Example: #include<iostream.h> #include<conio.h> int main() { int *ptr = new int; *ptr = 4; cout << *ptr << endl ; return 0; } OUTPUT: 4
  • 5. DELETE Operator A dynamic object can be distroyed by using the DELETE operator Syntax : delete ptr; Here ptr is the pointer to the dynamically allocated variable The delete operator simply returns the memory allocated back to the operating system so that it can be used again.
  • 6. Let’s look at an example: int main() { int *ptr = new int; *ptr = 4; cout << *ptr << endl; delete ptr; return 0; } OUTPUT: 4
  • 7. ADVANTAGES: The main advantage of using dynamic memory allocation is preventing the wastage of memory. We can allocate (create) additional storage whenever we need them. We can de-allocate (free/delete) dynamic space whenever we are done with them
  • 8. POINTER TO FUNCTION C++ allows you to pass a pointer to a function. Simply declare the function parameter as a pointer type.  Syntax: data type fun_name(data type *arg)
  • 9. Let’s look at an example: #include <iostream.h> void swap( int *a, int *b ) { int t; t = *a; *a = *b; *b = t; } int main() { int num1, num2; cout << "Enter first number" << endl; cin >> num1; cout << "Enter second number" << endl; cin >> num2; swap( &num1, &num2); cout << "First number = " << num1 << endl; cout << "Second number = " << num2 << endl; return 0; }
  • 10. OUTPUT: Enter first number 2 Enter second number 4 First number = 4 Second number = 2
  • 12. Array An array is collection of items stored at continues memory locations. Syntax : Int arr[10]; //Array declaration by specifying size
  • 13. Pointers A pointer is a variable whose value is the address of another variable. Like any variable or constant. Syntax : type * var_name; //declaration of an pointer Example: int *p,a; p=&a;
  • 14. Arrays and pointers Arrays and pointers are very closely related in c++. For Example: An array declared as Int a[10] Can also be accessed using its pointers representation . The name of the array is a constant pointer to the first element of the array. So a can be considered as const int*. Here arr points to the first element of the array
  • 15. For example: In array and pointers ptr[i] and*(ptr+i) are considered as same. Int a[4]={10,20,30,40}; Int *ptr = a; for(int i =0 ; i<4; i++) { cout<< *(ptr+i) <<endl; } Output: 10 20 30 40
  • 16. For the same array For(int i=0 ; i<4;i++) { Cout<< ptr[i] <<endl; } Output: 10 20 30 40
  • 17. Character string processing String: In C++, the one-dimensional array of characters are called strings, which is terminated by a null character 0. Syntax: char greeting[6];
  • 18. What is character string processing? Character string processing basically means accessing (insertion and extraction operators) the characters from a string. C++ provides following two types of string representations − • The C-style character string. • The string class type introduced with Standard C++.
  • 19. Insertion operator : The result of inserting a char pointer to an output stream is same as displaying a char array whose first element is located at the address to which the char* object points. Example: Char text[9]= “world”; For(char *ptr = text; *ptr!= ‘0’ ; ++ptr) { Cout<< ptr << endl; } Output : world orld rld ld d
  • 20. Extraction operator When the right operand of an extraction operator is a char* object, the behaves same as extraction from char array- by default leading white space is skipped and the next nonwhitespace string of characters is extracted. For example: char str[40]; Cout<<“enter a string:” ; Cin>> str; Cout<<“you entered :” <<str <<endl; } Output : enter a string : programming is fun you entered: programming
  • 21. String functions 1- strlen(): returns the length of the sytring. Syntax: int strlen(s1); 2- strcpy(): copies one string to another string. Syntax: char *strcpy(s1 , s2); 3- strcat(): this function concates two strings. syntax: char *strcat(s1 , s2 ); 4- strcmp(): compares two strings. syntax: strcmp(s1 ,s2);