SlideShare a Scribd company logo
3
Most read
5
Most read
7
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

PPTX
class and objects
PPTX
Object Oriented Programming Using C++
PPT
friend function(c++)
PDF
Function overloading ppt
PDF
Object Oriented Programming using JAVA Notes
PPTX
Python OOPs
PPTX
class and objects
Object Oriented Programming Using C++
friend function(c++)
Function overloading ppt
Object Oriented Programming using JAVA Notes
Python OOPs

What's hot (20)

PPTX
Pointers in c++
PPT
Class and object in C++
PPTX
Functions in c++
PPT
Operator Overloading
PPTX
classes and objects in C++
PPTX
Data types
PPTX
Advantages of DBMS
PDF
Class and Objects in Java
PDF
C++ Files and Streams
PPT
Object-oriented concepts
PPT
Basic concept of OOP's
PPTX
Super keyword in java
PPTX
Call by value or call by reference in C++
PPTX
Characteristics of OOPS
PPTX
INLINE FUNCTION IN C++
PPT
Use Case Diagram
PPTX
07. Virtual Functions
PPTX
Applets in java
PPTX
Inline function
PPT
Object and class relationships
Pointers in c++
Class and object in C++
Functions in c++
Operator Overloading
classes and objects in C++
Data types
Advantages of DBMS
Class and Objects in Java
C++ Files and Streams
Object-oriented concepts
Basic concept of OOP's
Super keyword in java
Call by value or call by reference in C++
Characteristics of OOPS
INLINE FUNCTION IN C++
Use Case Diagram
07. Virtual Functions
Applets in java
Inline function
Object and class relationships
Ad

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

PPTX
arraytypes of array and pointer string in c++.pptx
PPTX
DSA-Lecture03-Pointers, Strings(outputs).pptx
PPT
Lecture2.ppt
PDF
C++ computer language chapter 4 pointers.pdf
PPTX
Data Structures asdasdasdasdasdasdasdasdasdasd
PPT
DOCX
Arrry structure Stacks in data structure
PPTX
week14Pointers_II. pointers pemrograman dasar C++.pptx
PPTX
The string class
PPT
Pointer
PPTX
20.C++Pointer.pptx
PPTX
Arrays & Strings.pptx
PPTX
Introduction to Arrays and Strings.pptx
PPTX
Chapter 1 Introduction to Arrays and Strings
PPTX
C++ - UNIT_-_IV.pptx which contains details about Pointers
PDF
Chapter 3 - Characters and Strings - Student.pdf
PDF
Strinng Classes in c++
PPTX
Pointers in C++ object oriented programming
PPTX
Introduction to pointers in c plus plus .
arraytypes of array and pointer string in c++.pptx
DSA-Lecture03-Pointers, Strings(outputs).pptx
Lecture2.ppt
C++ computer language chapter 4 pointers.pdf
Data Structures asdasdasdasdasdasdasdasdasdasd
Arrry structure Stacks in data structure
week14Pointers_II. pointers pemrograman dasar C++.pptx
The string class
Pointer
20.C++Pointer.pptx
Arrays & Strings.pptx
Introduction to Arrays and Strings.pptx
Chapter 1 Introduction to Arrays and Strings
C++ - UNIT_-_IV.pptx which contains details about Pointers
Chapter 3 - Characters and Strings - Student.pdf
Strinng Classes in c++
Pointers in C++ object oriented programming
Introduction to pointers in c plus plus .
Ad

More from Meghaj Mallick (20)

PPT
24 partial-orderings
PPTX
PORTFOLIO BY USING HTML & CSS
PPTX
Introduction to Software Testing
PPTX
Introduction to System Programming
PPTX
MACRO ASSEBLER
PPTX
Icons, Image & Multimedia
PPTX
Project Tracking & SPC
PPTX
Peephole Optimization
PPTX
Routing in MANET
PPTX
Macro assembler
PPTX
Architecture and security in Vanet PPT
PPTX
Design Model & User Interface Design in Software Engineering
PPTX
Text Mining of Twitter in Data Mining
PPTX
DFS & BFS in Computer Algorithm
PPTX
Software Development Method
PPTX
Secant method in Numerical & Statistical Method
PPTX
Motivation in Organization
PPTX
Communication Skill
PPT
Partial-Orderings in Discrete Mathematics
PPTX
Hashing In Data Structure
24 partial-orderings
PORTFOLIO BY USING HTML & CSS
Introduction to Software Testing
Introduction to System Programming
MACRO ASSEBLER
Icons, Image & Multimedia
Project Tracking & SPC
Peephole Optimization
Routing in MANET
Macro assembler
Architecture and security in Vanet PPT
Design Model & User Interface Design in Software Engineering
Text Mining of Twitter in Data Mining
DFS & BFS in Computer Algorithm
Software Development Method
Secant method in Numerical & Statistical Method
Motivation in Organization
Communication Skill
Partial-Orderings in Discrete Mathematics
Hashing In Data Structure

Recently uploaded (20)

PPTX
Hydrogel Based delivery Cancer Treatment
PDF
oil_refinery_presentation_v1 sllfmfls.pdf
PPTX
Tablets And Capsule Preformulation Of Paracetamol
PPTX
BIOLOGY TISSUE PPT CLASS 9 PROJECT PUBLIC
PPTX
nose tajweed for the arabic alphabets for the responsive
PDF
Instagram's Product Secrets Unveiled with this PPT
PPTX
Effective_Handling_Information_Presentation.pptx
PPTX
Presentation for DGJV QMS (PQP)_12.03.2025.pptx
PPTX
Relationship Management Presentation In Banking.pptx
PDF
Parts of Speech Prepositions Presentation in Colorful Cute Style_20250724_230...
DOC
学位双硕士UTAS毕业证,墨尔本理工学院毕业证留学硕士毕业证
PPTX
AcademyNaturalLanguageProcessing-EN-ILT-M02-Introduction.pptx
DOCX
ENGLISH PROJECT FOR BINOD BIHARI MAHTO KOYLANCHAL UNIVERSITY
PPTX
Impressionism_PostImpressionism_Presentation.pptx
PDF
Swiggy’s Playbook: UX, Logistics & Monetization
PPTX
An Unlikely Response 08 10 2025.pptx
PPTX
Human Mind & its character Characteristics
PPTX
_ISO_Presentation_ISO 9001 and 45001.pptx
PPTX
fundraisepro pitch deck elegant and modern
PPTX
2025-08-10 Joseph 02 (shared slides).pptx
Hydrogel Based delivery Cancer Treatment
oil_refinery_presentation_v1 sllfmfls.pdf
Tablets And Capsule Preformulation Of Paracetamol
BIOLOGY TISSUE PPT CLASS 9 PROJECT PUBLIC
nose tajweed for the arabic alphabets for the responsive
Instagram's Product Secrets Unveiled with this PPT
Effective_Handling_Information_Presentation.pptx
Presentation for DGJV QMS (PQP)_12.03.2025.pptx
Relationship Management Presentation In Banking.pptx
Parts of Speech Prepositions Presentation in Colorful Cute Style_20250724_230...
学位双硕士UTAS毕业证,墨尔本理工学院毕业证留学硕士毕业证
AcademyNaturalLanguageProcessing-EN-ILT-M02-Introduction.pptx
ENGLISH PROJECT FOR BINOD BIHARI MAHTO KOYLANCHAL UNIVERSITY
Impressionism_PostImpressionism_Presentation.pptx
Swiggy’s Playbook: UX, Logistics & Monetization
An Unlikely Response 08 10 2025.pptx
Human Mind & its character Characteristics
_ISO_Presentation_ISO 9001 and 45001.pptx
fundraisepro pitch deck elegant and modern
2025-08-10 Joseph 02 (shared slides).pptx

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