SlideShare a Scribd company logo
‘ 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
Ad

More Related Content

What's hot (20)

C++ programming function
C++ programming functionC++ programming function
C++ programming function
Vishalini Mugunen
 
user defined function
user defined functionuser defined function
user defined function
King Kavin Patel
 
Inline function
Inline functionInline function
Inline function
Tech_MX
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
Mauryasuraj98
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
kamal kotecha
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
Pranali Chaudhari
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vishal Patil
 
File handling in c++
File handling in c++File handling in c++
File handling in c++
baabtra.com - No. 1 supplier of quality freshers
 
Array within a class
Array within a classArray within a class
Array within a class
AAKASH KUMAR
 
Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in java
Elizabeth alexander
 
CS3391 -OOP -UNIT – II NOTES FINAL.pdf
CS3391 -OOP -UNIT – II  NOTES FINAL.pdfCS3391 -OOP -UNIT – II  NOTES FINAL.pdf
CS3391 -OOP -UNIT – II NOTES FINAL.pdf
AALIM MUHAMMED SALEGH COLLEGE OF ENGINEERING
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
Ritika Sharma
 
Function Pointer
Function PointerFunction Pointer
Function Pointer
Dr-Dipali Meher
 
Java exception handling ppt
Java exception handling pptJava exception handling ppt
Java exception handling ppt
JavabynataraJ
 
Pointer to function 1
Pointer to function 1Pointer to function 1
Pointer to function 1
Abu Bakr Ramadan
 
CS3391 -OOP -UNIT – III NOTES FINAL.pdf
CS3391 -OOP -UNIT – III  NOTES FINAL.pdfCS3391 -OOP -UNIT – III  NOTES FINAL.pdf
CS3391 -OOP -UNIT – III NOTES FINAL.pdf
AALIM MUHAMMED SALEGH COLLEGE OF ENGINEERING
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Tech_MX
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
MOHIT AGARWAL
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
Vraj Patel
 
C++ classes
C++ classesC++ classes
C++ classes
imhammadali
 

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)

Besu Shibpur Enquesta 2012 Intra College General Quiz Finals.pptx
Besu Shibpur Enquesta 2012 Intra College General Quiz Finals.pptxBesu Shibpur Enquesta 2012 Intra College General Quiz Finals.pptx
Besu Shibpur Enquesta 2012 Intra College General Quiz Finals.pptx
Rajdeep Chakraborty
 
Bloom Where You Are Planted 05.04.2025.pptx
Bloom Where You Are Planted 05.04.2025.pptxBloom Where You Are Planted 05.04.2025.pptx
Bloom Where You Are Planted 05.04.2025.pptx
FamilyWorshipCenterD
 
ICSE 2025 Keynote: Software Sustainability and its Engineering: How far have ...
ICSE 2025 Keynote: Software Sustainability and its Engineering: How far have ...ICSE 2025 Keynote: Software Sustainability and its Engineering: How far have ...
ICSE 2025 Keynote: Software Sustainability and its Engineering: How far have ...
patricialago3459
 
Platform Engineering >> Platform Product Management.pptx
Platform Engineering  >>  Platform Product Management.pptxPlatform Engineering  >>  Platform Product Management.pptx
Platform Engineering >> Platform Product Management.pptx
noelorona
 
Reflections on an ngo peace conference in zimbabwe
Reflections on an ngo peace conference in zimbabweReflections on an ngo peace conference in zimbabwe
Reflections on an ngo peace conference in zimbabwe
jujuaw05
 
THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...
THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...
THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...
ASHISHKUMAR504404
 
THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...
THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...
THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...
ASHISHKUMAR504404
 
Bidding World Conference 2027 - NSGF Mexico.pdf
Bidding World Conference 2027 - NSGF Mexico.pdfBidding World Conference 2027 - NSGF Mexico.pdf
Bidding World Conference 2027 - NSGF Mexico.pdf
ISGF - International Scout and Guide Fellowship
 
THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...
THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...
THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...
ASHISHKUMAR504404
 
Key Elements of a Procurement Plan.docx.
Key Elements of a Procurement Plan.docx.Key Elements of a Procurement Plan.docx.
Key Elements of a Procurement Plan.docx.
NeoRakodu
 
ICONX - Mining RACE - Compensation Plan - english
ICONX - Mining RACE - Compensation Plan - englishICONX - Mining RACE - Compensation Plan - english
ICONX - Mining RACE - Compensation Plan - english
Bitcoin Mining RACE
 
cardiovascular outcome in trial of new antidiabetic drugs
cardiovascular outcome in trial of new antidiabetic drugscardiovascular outcome in trial of new antidiabetic drugs
cardiovascular outcome in trial of new antidiabetic drugs
Mohammed Ahmed Bamashmos
 
stackconf 2025 | IP Authentication: A Tale of Performance Pitfalls and Challe...
stackconf 2025 | IP Authentication: A Tale of Performance Pitfalls and Challe...stackconf 2025 | IP Authentication: A Tale of Performance Pitfalls and Challe...
stackconf 2025 | IP Authentication: A Tale of Performance Pitfalls and Challe...
NETWAYS
 
A Bot Identification Model and Tool Based on GitHub Activity Sequences
A Bot Identification Model and Tool Based on GitHub Activity SequencesA Bot Identification Model and Tool Based on GitHub Activity Sequences
A Bot Identification Model and Tool Based on GitHub Activity Sequences
natarajan8993
 
Bidding World Conference 2027-NSGF Senegal.pdf
Bidding World Conference 2027-NSGF Senegal.pdfBidding World Conference 2027-NSGF Senegal.pdf
Bidding World Conference 2027-NSGF Senegal.pdf
ISGF - International Scout and Guide Fellowship
 
Microsoft Azure Data Fundamentals (DP-900) Exam Dumps & Questions 2025.pdf
Microsoft Azure Data Fundamentals (DP-900) Exam Dumps & Questions 2025.pdfMicrosoft Azure Data Fundamentals (DP-900) Exam Dumps & Questions 2025.pdf
Microsoft Azure Data Fundamentals (DP-900) Exam Dumps & Questions 2025.pdf
MinniePfeiffer
 
2. Asexual propagation of fruit crops and .pptx
2. Asexual propagation of fruit crops and .pptx2. Asexual propagation of fruit crops and .pptx
2. Asexual propagation of fruit crops and .pptx
aschenakidawit1
 
NASIG ISSN 2025 updated for the_4-30meeting.pptx
NASIG ISSN 2025 updated for the_4-30meeting.pptxNASIG ISSN 2025 updated for the_4-30meeting.pptx
NASIG ISSN 2025 updated for the_4-30meeting.pptx
reine1
 
Thyrocardiac syndrome, diagnosis and treatment
Thyrocardiac syndrome,  diagnosis and treatmentThyrocardiac syndrome,  diagnosis and treatment
Thyrocardiac syndrome, diagnosis and treatment
Mohammed Ahmed Bamashmos
 
stackconf 2025 | Stratoshark: Bringing the Wireshark experience to cloud and ...
stackconf 2025 | Stratoshark: Bringing the Wireshark experience to cloud and ...stackconf 2025 | Stratoshark: Bringing the Wireshark experience to cloud and ...
stackconf 2025 | Stratoshark: Bringing the Wireshark experience to cloud and ...
NETWAYS
 
Besu Shibpur Enquesta 2012 Intra College General Quiz Finals.pptx
Besu Shibpur Enquesta 2012 Intra College General Quiz Finals.pptxBesu Shibpur Enquesta 2012 Intra College General Quiz Finals.pptx
Besu Shibpur Enquesta 2012 Intra College General Quiz Finals.pptx
Rajdeep Chakraborty
 
Bloom Where You Are Planted 05.04.2025.pptx
Bloom Where You Are Planted 05.04.2025.pptxBloom Where You Are Planted 05.04.2025.pptx
Bloom Where You Are Planted 05.04.2025.pptx
FamilyWorshipCenterD
 
ICSE 2025 Keynote: Software Sustainability and its Engineering: How far have ...
ICSE 2025 Keynote: Software Sustainability and its Engineering: How far have ...ICSE 2025 Keynote: Software Sustainability and its Engineering: How far have ...
ICSE 2025 Keynote: Software Sustainability and its Engineering: How far have ...
patricialago3459
 
Platform Engineering >> Platform Product Management.pptx
Platform Engineering  >>  Platform Product Management.pptxPlatform Engineering  >>  Platform Product Management.pptx
Platform Engineering >> Platform Product Management.pptx
noelorona
 
Reflections on an ngo peace conference in zimbabwe
Reflections on an ngo peace conference in zimbabweReflections on an ngo peace conference in zimbabwe
Reflections on an ngo peace conference in zimbabwe
jujuaw05
 
THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...
THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...
THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...
ASHISHKUMAR504404
 
THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...
THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...
THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...
ASHISHKUMAR504404
 
THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...
THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...
THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...
ASHISHKUMAR504404
 
Key Elements of a Procurement Plan.docx.
Key Elements of a Procurement Plan.docx.Key Elements of a Procurement Plan.docx.
Key Elements of a Procurement Plan.docx.
NeoRakodu
 
ICONX - Mining RACE - Compensation Plan - english
ICONX - Mining RACE - Compensation Plan - englishICONX - Mining RACE - Compensation Plan - english
ICONX - Mining RACE - Compensation Plan - english
Bitcoin Mining RACE
 
cardiovascular outcome in trial of new antidiabetic drugs
cardiovascular outcome in trial of new antidiabetic drugscardiovascular outcome in trial of new antidiabetic drugs
cardiovascular outcome in trial of new antidiabetic drugs
Mohammed Ahmed Bamashmos
 
stackconf 2025 | IP Authentication: A Tale of Performance Pitfalls and Challe...
stackconf 2025 | IP Authentication: A Tale of Performance Pitfalls and Challe...stackconf 2025 | IP Authentication: A Tale of Performance Pitfalls and Challe...
stackconf 2025 | IP Authentication: A Tale of Performance Pitfalls and Challe...
NETWAYS
 
A Bot Identification Model and Tool Based on GitHub Activity Sequences
A Bot Identification Model and Tool Based on GitHub Activity SequencesA Bot Identification Model and Tool Based on GitHub Activity Sequences
A Bot Identification Model and Tool Based on GitHub Activity Sequences
natarajan8993
 
Microsoft Azure Data Fundamentals (DP-900) Exam Dumps & Questions 2025.pdf
Microsoft Azure Data Fundamentals (DP-900) Exam Dumps & Questions 2025.pdfMicrosoft Azure Data Fundamentals (DP-900) Exam Dumps & Questions 2025.pdf
Microsoft Azure Data Fundamentals (DP-900) Exam Dumps & Questions 2025.pdf
MinniePfeiffer
 
2. Asexual propagation of fruit crops and .pptx
2. Asexual propagation of fruit crops and .pptx2. Asexual propagation of fruit crops and .pptx
2. Asexual propagation of fruit crops and .pptx
aschenakidawit1
 
NASIG ISSN 2025 updated for the_4-30meeting.pptx
NASIG ISSN 2025 updated for the_4-30meeting.pptxNASIG ISSN 2025 updated for the_4-30meeting.pptx
NASIG ISSN 2025 updated for the_4-30meeting.pptx
reine1
 
Thyrocardiac syndrome, diagnosis and treatment
Thyrocardiac syndrome,  diagnosis and treatmentThyrocardiac syndrome,  diagnosis and treatment
Thyrocardiac syndrome, diagnosis and treatment
Mohammed Ahmed Bamashmos
 
stackconf 2025 | Stratoshark: Bringing the Wireshark experience to cloud and ...
stackconf 2025 | Stratoshark: Bringing the Wireshark experience to cloud and ...stackconf 2025 | Stratoshark: Bringing the Wireshark experience to cloud and ...
stackconf 2025 | Stratoshark: Bringing the Wireshark experience to cloud and ...
NETWAYS
 

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);