SlideShare a Scribd company logo
1 of 28
Lecture # 1Lecture # 1
(Data Structure)(Data Structure)
Fazl-e-BasitFazl-e-Basit
ProgramProgram InstitutionInstitution
MS (Software Engineering )MS (Software Engineering )
(2 years)(2 years)
NUST (National UniversityNUST (National University
of Science &of Science &
Technology), RawalpindiTechnology), Rawalpindi
Computer SoftwareComputer Software
EngineeringEngineering
(4 years)(4 years)
Foundation UniversityFoundation University
Islamabad (FUI)Islamabad (FUI)
B. Sc (Computer Science)B. Sc (Computer Science) Peshawar UniversityPeshawar University
Working ExperienceWorking Experience
 CurrentlyCurrently Assistant ProfessorAssistant Professor herehere –– CSCS
DepartmentDepartment
 Worked as “Worked as “Project DirectorProject Director” LEADS Software” LEADS Software
House Peshawar (Registered with PSEB).House Peshawar (Registered with PSEB).
 Worked as “Worked as “Lecturer/CoordinatorLecturer/Coordinator” Greenwich” Greenwich
University Peshawar.University Peshawar.
 Worked as “Worked as “Software DeveloperSoftware Developer” Pi-Sigma (Prosol)” Pi-Sigma (Prosol)
Technologies, Software Technology Park,Technologies, Software Technology Park,
Islamabad.Islamabad.
Objective of the CourseObjective of the Course
 Covering well-known data structures suchCovering well-known data structures such
as dynamic arrays, linked lists, stacks,as dynamic arrays, linked lists, stacks,
queues, trees and graphs etc.queues, trees and graphs etc.
 To Prepare students for (and is aTo Prepare students for (and is a
prerequisite for) the more advancedprerequisite for) the more advanced
material students will encounter in latermaterial students will encounter in later
courses.courses.
 Implementing data structures and classicalImplementing data structures and classical
computer science problems in C++.computer science problems in C++.
Teaching ProcedureTeaching Procedure
 LecturesLectures
 DiscussionsDiscussions
 Assignments (Assignments ( ImportantImportant ))
 Sudden QuizzesSudden Quizzes
 Mid TermMid Term
 Final ExamFinal Exam
Material / ResourcesMaterial / Resources
 Text BookText Book
 Fundamentals of Data Structures in C++ byFundamentals of Data Structures in C++ by
horowitz, sahni and mehta.horowitz, sahni and mehta.
 wwwwww
 Any other good book on Data StructureAny other good book on Data Structure
GradingGrading
 Assignments/Lab Exam …..…………… 15Assignments/Lab Exam …..…………… 15
%%
 Quizzes ………..…………..…..……………Quizzes ………..…………..…..……………
05 %05 %
 Mid Term….…………………………………Mid Term….…………………………………
30 %30 %
 Final Exam..…………………………………Final Exam..…………………………………
50 %50 %
Keys for success in the course…….Keys for success in the course…….
 100 %100 % AttendanceAttendance
 Solving AssignmentsSolving Assignments YourselvesYourselves
 AttentiveAttentive in class sessionsin class sessions
 AskingAsking questionsquestions && questionsquestions unless youunless you
are clear about your problem.are clear about your problem.
Revision of PointersRevision of Pointers
 Every byte in the computer’s memory has anEvery byte in the computer’s memory has an
address.address. Addresses are numbers just as everyAddresses are numbers just as every
house in a locality has got an address.house in a locality has got an address.
 Your program, when it is loaded into memory,Your program, when it is loaded into memory,
occupies certain range of these addresses. Thisoccupies certain range of these addresses. This
means that every variable and every function inmeans that every variable and every function in
your program starts with a particular addressyour program starts with a particular address
 NOTE :NOTE : Pointer can only contain thePointer can only contain the ADDRESSADDRESS
of certain memory location.of certain memory location.
 Normally a variable directly contains a specificNormally a variable directly contains a specific
value. Pointer, on the other hand, contains anvalue. Pointer, on the other hand, contains an
address of the variable that contains the specificaddress of the variable that contains the specific
value.value.
 Pointers, like other variables must be declaredPointers, like other variables must be declared
before they are used. For e.g.before they are used. For e.g.
int *pttrr, temp;int *pttrr, temp;
 Pointers should be initialized either when they arePointers should be initialized either when they are
declared or in an assignment statement. A pointerdeclared or in an assignment statement. A pointer
may be initialized tomay be initialized to 00,, NULLNULL or anor an addressaddress. A. A
pointer with the valuepointer with the value 00 oror NULLNULL points to nothing.points to nothing.
 NULLNULL is a symbolic constant defined in theis a symbolic constant defined in the
header fileheader file <iostream.h>.<iostream.h>. Initializing a pointer toInitializing a pointer to
NULLNULL is equivalent to initializing a pointer tois equivalent to initializing a pointer to 00..
 Initializing a pointer is necessary to prevent itInitializing a pointer is necessary to prevent it
pointing to unknown or un-initialized area ofpointing to unknown or un-initialized area of
memory.memory.
 There are two pointer operators;There are two pointer operators;
 thethe address ofaddress of operatoroperator &&
andand
 indirection operatorindirection operator oror dereferencing operatordereferencing operator
i.e.i.e. **..
 && is a unary operator that returns theis a unary operator that returns the address ofaddress of itsits
operand. For e.g.operand. For e.g.
int x = 5;int x = 5;
int *ptrr = NULL;int *ptrr = NULL;
ptrr = &x;ptrr = &x;
 In aboveIn above ** showsshows ptrrptrr is pointer variable whose typeis pointer variable whose type
isis intint i.e. it can only contain thei.e. it can only contain the address ofaddress of anyany
integer variablesinteger variables in memory.in memory.
SimilarlySimilarly
cout<< *ptrr <<“n”;cout<< *ptrr <<“n”;
cout<< x <<“n”;cout<< x <<“n”;
 Will produce the same resultWill produce the same result 55. Here. Here ** meansmeans
value ofvalue of the variable to whichthe variable to which ptrrptrr points to, whichpoints to, which
isis xx..
 Note that the dereferenced pointer may also beNote that the dereferenced pointer may also be
used on the left side of an assignment statementused on the left side of an assignment statement
as follows.as follows.
*pttr = 9;*pttr = 9; oror
cin>>*ptrr;cin>>*ptrr;
 Following program explains the concept ofFollowing program explains the concept of
pointerspointers
#include<iostream.h>#include<iostream.h>
void main( )void main( )
{{
int x = 5;int x = 5;
int *ptrr = NULL;int *ptrr = NULL;
ptrr = &x;ptrr = &x;
cout<< *ptrr <<“n”;cout<< *ptrr <<“n”;
cout<< x <<“n”;cout<< x <<“n”;
*pttr = 9;*pttr = 9;
cout<< &x <<“n”;cout<< &x <<“n”;
cout<< *&ptrr <<“n”;cout<< *&ptrr <<“n”;
// cancel effect of each other// cancel effect of each other ( &( & andand *)*)
cout<< &*ptrr <<“n”;cout<< &*ptrr <<“n”;
cout<< ptrr <<“n”;cout<< ptrr <<“n”;
cout<< *ptrr <<“n”;cout<< *ptrr <<“n”;
cout<< x <<“n”;cout<< x <<“n”;
}}
Output of ProgramOutput of Program
55
55
0x0064FDF40x0064FDF4
0x0064FDF40x0064FDF4
0x0064FDF40x0064FDF4
0x0064FDF40x0064FDF4
99
99
newnew andand deletedelete operatorsoperators
 Variables created during execution ( run time ) ofVariables created during execution ( run time ) of
a program by means of special operation isa program by means of special operation is
known asknown as Dynamic DataDynamic Data. In C++ operation is. In C++ operation is
new.new.
 The new operation has two formsThe new operation has two forms
newnew DataTypeDataType
newnew DataType [intExpression]DataType [intExpression]
First form is used for creating a single varaible ofFirst form is used for creating a single varaible of
type DataType ( e.g. int,…) attype DataType ( e.g. int,…) at run timerun time.. SecondSecond
form creates an array whose elements are ofform creates an array whose elements are of
type DataType ( e.g. char,…) attype DataType ( e.g. char,…) at run time.run time.
 ExampleExample
intint **intptr;intptr;
charchar **namestr;namestr;
intptr =intptr = newnew int;int;
namestr =namestr = newnew char[8];char[8];
 Variables created byVariables created by newnew are said to be on theare said to be on the
free storefree store oror heapheap, a region of memory set aside, a region of memory set aside
forfor Dynamic VariablesDynamic Variables..
 The new operator obtains a chunk (portion) ofThe new operator obtains a chunk (portion) of
memory from thememory from the free storefree store..
 AA Dynamic VariableDynamic Variable isis unnamedunnamed and cannotand cannot
bebe directly addresseddirectly addressed. It must be. It must be indirectlyindirectly
addressedaddressed through the pointer returned by thethrough the pointer returned by the
newnew operator.operator.
intint **intptr =intptr = newnew int;int;
charchar **namestr =namestr = newnew char[8];char[8];
*intptr = 357;*intptr = 357;
strcpy( namestr, “datastructure” );strcpy( namestr, “datastructure” );
 Dynamic dataDynamic data can becan be destroyeddestroyed at any timeat any time
during theduring the executionexecution of a program when it is noof a program when it is no
longer needed. The built-in operatorlonger needed. The built-in operator deletedelete doesdoes
that and has two forms,that and has two forms, oneone for deleting singlefor deleting single
variable, thevariable, the otherother for deleting an array.for deleting an array.
deletedelete pointer;pointer;
deletedelete [ ] pointer;[ ] pointer;
 Example :Example :
intint **ptr1 =ptr1 = newnew int;int;
intint **ptr2 =ptr2 = newnew int;int;
*ptr2 = 44;*ptr2 = 44;
*ptr1 = *ptr2;*ptr1 = *ptr2;
ptr1 = ptr2;ptr1 = ptr2;
deletedelete ptr2;ptr2;
 Inaccessible object :Inaccessible object :
A dynamic variable on the free store withoutA dynamic variable on the free store without
any pointer pointing to it.any pointer pointing to it.
 Dangling pointer :Dangling pointer :
A pointer that points to a variable that hasA pointer that points to a variable that has
been deallocated.been deallocated.
NOTE :NOTE : Leaving inaccessible objects on the freeLeaving inaccessible objects on the free
store should be considered a logic error.store should be considered a logic error.
Implementation ofImplementation of
newnew andand deletedelete operatorsoperators
Example :Example :
#include<iostream.h>#include<iostream.h>
#include<conio.h>#include<conio.h>
struct nodestruct node
{{
char info[15];char info[15];
};};
class trialclass trial
{{
private :private :
node obj1, *temp1, *temp2, *temp3;node obj1, *temp1, *temp2, *temp3;
int I, length;int I, length;
char *p,*q;char *p,*q;
public :public :
trial();trial();
~trial(); // Prototype~trial(); // Prototype
void startin();void startin();
};};
//-----------------------------------------------------------------//-----------------------------------------------------------------
void main()void main()
{{
clrscr();clrscr();
trial lnk;trial lnk;
lnk.startin();lnk.startin();
getch();getch();
}//----------------------------------------------------------------------}//----------------------------------------------------------------------
trial :: trial()trial :: trial()
{{
temp1 = temp2 = temp3 = NULL;temp1 = temp2 = temp3 = NULL;
}//--------------------------------------------------------------------}//--------------------------------------------------------------------
trial :: ~trial()trial :: ~trial()
{{
delete temp1;delete temp1;
delete temp2, temp3;delete temp2, temp3;
delete[] p; // delete 10 charsdelete[] p; // delete 10 chars
}//--------------------------------------------------------------------}//--------------------------------------------------------------------
void trial :: startin()void trial :: startin()
{{
cout<<"n Making use of "new" and "delete" is as follows.n";cout<<"n Making use of "new" and "delete" is as follows.n";
cout<<"n ---------------------------------------------------nn";cout<<"n ---------------------------------------------------nn";
temp1 = new node;temp1 = new node;
temp2 = new node;temp2 = new node;
cout<<"n Enter information about temp1.n";cout<<"n Enter information about temp1.n";
cin>>temp1->info;cin>>temp1->info;
cout<<"n Enter information about temp2.n";cout<<"n Enter information about temp2.n";
cin>>temp2->info;cin>>temp2->info;
temp3 = &obj1;temp3 = &obj1;
cout<<"n Enter information about temp3.n";cout<<"n Enter information about temp3.n";
cin>>temp3->info;cin>>temp3->info;
cout<<"n Showing information of temp1.n";cout<<"n Showing information of temp1.n";
cout<<temp1->info;cout<<temp1->info;
cout<<"n Showing information of temp2.n";cout<<"n Showing information of temp2.n";
cout<<temp2->info;cout<<temp2->info;
cout<<"n Showing information of temp3.n";cout<<"n Showing information of temp3.n";
cout<<temp3->info;cout<<temp3->info;
cout<<"n ---------------------------------------------------nn";cout<<"n ---------------------------------------------------nn";
cout<<" Now enter the length of character array.n";cout<<" Now enter the length of character array.n";
cin>>length;cin>>length;
p = new char[length]; // allocate 10 charsp = new char[length]; // allocate 10 chars
q = p;q = p;
cout<<" Now enter "<<length<<" characters to fill an array.n";cout<<" Now enter "<<length<<" characters to fill an array.n";
for( i=0;i<length; i++ )for( i=0;i<length; i++ )
{{
cin>>*p;cin>>*p;
p = p + 1;p = p + 1;
}}
p = q;p = q;
cout<<" nElements of array are as follows.n";cout<<" nElements of array are as follows.n";
for( i=0;i<length; i++ )for( i=0;i<length; i++ )
{{
cout<<*p<<", ";cout<<*p<<", ";
p = p + 1;p = p + 1;
}}
p = q;p = q;
}//--- END of startin( )---------------------------------------------------------------}//--- END of startin( )---------------------------------------------------------------
Thank You ….Thank You ….

More Related Content

What's hot

The Art Of Parsing @ Devoxx France 2014
The Art Of Parsing @ Devoxx France 2014The Art Of Parsing @ Devoxx France 2014
The Art Of Parsing @ Devoxx France 2014Dinesh Bolkensteyn
 
Intro To C++ - Class #17: Pointers!, Objects Talking To Each Other
Intro To C++ - Class #17: Pointers!, Objects Talking To Each OtherIntro To C++ - Class #17: Pointers!, Objects Talking To Each Other
Intro To C++ - Class #17: Pointers!, Objects Talking To Each OtherBlue Elephant Consulting
 
Lecturer23 pointersin c.ppt
Lecturer23 pointersin c.pptLecturer23 pointersin c.ppt
Lecturer23 pointersin c.ppteShikshak
 
Implementing of classical synchronization problem by using semaphores
Implementing of classical synchronization problem by using semaphoresImplementing of classical synchronization problem by using semaphores
Implementing of classical synchronization problem by using semaphoresGowtham Reddy
 
Lec 38.39 - pointers
Lec 38.39 -  pointersLec 38.39 -  pointers
Lec 38.39 - pointersPrincess Sam
 
Expert system with python -2
Expert system with python  -2Expert system with python  -2
Expert system with python -2Ahmad Hussein
 
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...corehard_by
 
Types of pointer in C
Types of pointer in CTypes of pointer in C
Types of pointer in Crgnikate
 
Data structures / C++ Program examples
Data structures / C++ Program examplesData structures / C++ Program examples
Data structures / C++ Program examplesKevin III
 
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 1
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 1Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 1
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 1PVS-Studio
 
Martin Chapman: Research Overview, 2017
Martin Chapman: Research Overview, 2017Martin Chapman: Research Overview, 2017
Martin Chapman: Research Overview, 2017Martin Chapman
 
Understanding Javascript Engine to Code Better
Understanding Javascript Engine to Code BetterUnderstanding Javascript Engine to Code Better
Understanding Javascript Engine to Code BetterIhsan Fauzi Rahman
 
Introduction to nsubstitute
Introduction to nsubstituteIntroduction to nsubstitute
Introduction to nsubstituteSuresh Loganatha
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentalsHCMUTE
 
Jumping-with-java8
Jumping-with-java8Jumping-with-java8
Jumping-with-java8Dhaval Dalal
 

What's hot (17)

The Art Of Parsing @ Devoxx France 2014
The Art Of Parsing @ Devoxx France 2014The Art Of Parsing @ Devoxx France 2014
The Art Of Parsing @ Devoxx France 2014
 
Intro To C++ - Class #17: Pointers!, Objects Talking To Each Other
Intro To C++ - Class #17: Pointers!, Objects Talking To Each OtherIntro To C++ - Class #17: Pointers!, Objects Talking To Each Other
Intro To C++ - Class #17: Pointers!, Objects Talking To Each Other
 
Lecturer23 pointersin c.ppt
Lecturer23 pointersin c.pptLecturer23 pointersin c.ppt
Lecturer23 pointersin c.ppt
 
Implementing of classical synchronization problem by using semaphores
Implementing of classical synchronization problem by using semaphoresImplementing of classical synchronization problem by using semaphores
Implementing of classical synchronization problem by using semaphores
 
Lec 38.39 - pointers
Lec 38.39 -  pointersLec 38.39 -  pointers
Lec 38.39 - pointers
 
Expert system with python -2
Expert system with python  -2Expert system with python  -2
Expert system with python -2
 
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...
 
Types of pointer in C
Types of pointer in CTypes of pointer in C
Types of pointer in C
 
Data structures / C++ Program examples
Data structures / C++ Program examplesData structures / C++ Program examples
Data structures / C++ Program examples
 
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 1
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 1Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 1
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 1
 
Martin Chapman: Research Overview, 2017
Martin Chapman: Research Overview, 2017Martin Chapman: Research Overview, 2017
Martin Chapman: Research Overview, 2017
 
Understanding Javascript Engine to Code Better
Understanding Javascript Engine to Code BetterUnderstanding Javascript Engine to Code Better
Understanding Javascript Engine to Code Better
 
Introduction to nsubstitute
Introduction to nsubstituteIntroduction to nsubstitute
Introduction to nsubstitute
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
Jumping-with-java8
Jumping-with-java8Jumping-with-java8
Jumping-with-java8
 
Problemas secuenciales.
Problemas secuenciales.Problemas secuenciales.
Problemas secuenciales.
 
Chtp414
Chtp414Chtp414
Chtp414
 

Similar to Lecture1

Diploma ii cfpc- u-5.1 pointer, structure ,union and intro to file handling
Diploma ii  cfpc- u-5.1 pointer, structure ,union and intro to file handlingDiploma ii  cfpc- u-5.1 pointer, structure ,union and intro to file handling
Diploma ii cfpc- u-5.1 pointer, structure ,union and intro to file handlingRai University
 
Btech 1 pic u-5 pointer, structure ,union and intro to file handling
Btech 1 pic u-5 pointer, structure ,union and intro to file handlingBtech 1 pic u-5 pointer, structure ,union and intro to file handling
Btech 1 pic u-5 pointer, structure ,union and intro to file handlingRai University
 
Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)tech4us
 
Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanMohammadSalman129
 
358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3sumitbardhan
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directivesVikash Dhal
 
Introduction To Python.pptx
Introduction To Python.pptxIntroduction To Python.pptx
Introduction To Python.pptxAnum Zehra
 
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxJLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxvrickens
 
C language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C languageC language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C languageRakesh Roshan
 
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docxAssignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docxbraycarissa250
 
Pointers Refrences & dynamic memory allocation in C++
Pointers Refrences & dynamic memory allocation in C++Pointers Refrences & dynamic memory allocation in C++
Pointers Refrences & dynamic memory allocation in C++Gamindu Udayanga
 

Similar to Lecture1 (20)

Diploma ii cfpc- u-5.1 pointer, structure ,union and intro to file handling
Diploma ii  cfpc- u-5.1 pointer, structure ,union and intro to file handlingDiploma ii  cfpc- u-5.1 pointer, structure ,union and intro to file handling
Diploma ii cfpc- u-5.1 pointer, structure ,union and intro to file handling
 
Btech 1 pic u-5 pointer, structure ,union and intro to file handling
Btech 1 pic u-5 pointer, structure ,union and intro to file handlingBtech 1 pic u-5 pointer, structure ,union and intro to file handling
Btech 1 pic u-5 pointer, structure ,union and intro to file handling
 
Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)
 
Computation Chapter 4
Computation Chapter 4Computation Chapter 4
Computation Chapter 4
 
Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad Salman
 
358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directives
 
General Talk on Pointers
General Talk on PointersGeneral Talk on Pointers
General Talk on Pointers
 
Lecture2.ppt
Lecture2.pptLecture2.ppt
Lecture2.ppt
 
Pointer.pptx
Pointer.pptxPointer.pptx
Pointer.pptx
 
C
CC
C
 
Introduction To Python.pptx
Introduction To Python.pptxIntroduction To Python.pptx
Introduction To Python.pptx
 
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxJLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
 
Operators1.pptx
Operators1.pptxOperators1.pptx
Operators1.pptx
 
C language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C languageC language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C language
 
Chapter16 pointer
Chapter16 pointerChapter16 pointer
Chapter16 pointer
 
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docxAssignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
 
Welcome to python workshop
Welcome to python workshopWelcome to python workshop
Welcome to python workshop
 
Python fundamentals
Python fundamentalsPython fundamentals
Python fundamentals
 
Pointers Refrences & dynamic memory allocation in C++
Pointers Refrences & dynamic memory allocation in C++Pointers Refrences & dynamic memory allocation in C++
Pointers Refrences & dynamic memory allocation in C++
 

More from Muhammad Zubair (14)

Cloud computing
Cloud computingCloud computing
Cloud computing
 
Cloud computing disadvantages
Cloud computing disadvantagesCloud computing disadvantages
Cloud computing disadvantages
 
Lecture10
Lecture10Lecture10
Lecture10
 
Lecture9 recursion
Lecture9 recursionLecture9 recursion
Lecture9 recursion
 
Lecture8
Lecture8Lecture8
Lecture8
 
Lecture7
Lecture7Lecture7
Lecture7
 
Lecture6
Lecture6Lecture6
Lecture6
 
Lecture5
Lecture5Lecture5
Lecture5
 
Lecture4
Lecture4Lecture4
Lecture4
 
Lecture3
Lecture3Lecture3
Lecture3
 
Lecture3
Lecture3Lecture3
Lecture3
 
Lecture2
Lecture2Lecture2
Lecture2
 
Indin report by zubair
Indin report by zubairIndin report by zubair
Indin report by zubair
 
Cyber crime in pakistan by zubair
Cyber crime in pakistan by zubairCyber crime in pakistan by zubair
Cyber crime in pakistan by zubair
 

Recently uploaded

Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
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
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
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
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 

Recently uploaded (20)

Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
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
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
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
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 

Lecture1

  • 1. Lecture # 1Lecture # 1 (Data Structure)(Data Structure)
  • 2. Fazl-e-BasitFazl-e-Basit ProgramProgram InstitutionInstitution MS (Software Engineering )MS (Software Engineering ) (2 years)(2 years) NUST (National UniversityNUST (National University of Science &of Science & Technology), RawalpindiTechnology), Rawalpindi Computer SoftwareComputer Software EngineeringEngineering (4 years)(4 years) Foundation UniversityFoundation University Islamabad (FUI)Islamabad (FUI) B. Sc (Computer Science)B. Sc (Computer Science) Peshawar UniversityPeshawar University
  • 3. Working ExperienceWorking Experience  CurrentlyCurrently Assistant ProfessorAssistant Professor herehere –– CSCS DepartmentDepartment  Worked as “Worked as “Project DirectorProject Director” LEADS Software” LEADS Software House Peshawar (Registered with PSEB).House Peshawar (Registered with PSEB).  Worked as “Worked as “Lecturer/CoordinatorLecturer/Coordinator” Greenwich” Greenwich University Peshawar.University Peshawar.  Worked as “Worked as “Software DeveloperSoftware Developer” Pi-Sigma (Prosol)” Pi-Sigma (Prosol) Technologies, Software Technology Park,Technologies, Software Technology Park, Islamabad.Islamabad.
  • 4. Objective of the CourseObjective of the Course  Covering well-known data structures suchCovering well-known data structures such as dynamic arrays, linked lists, stacks,as dynamic arrays, linked lists, stacks, queues, trees and graphs etc.queues, trees and graphs etc.  To Prepare students for (and is aTo Prepare students for (and is a prerequisite for) the more advancedprerequisite for) the more advanced material students will encounter in latermaterial students will encounter in later courses.courses.  Implementing data structures and classicalImplementing data structures and classical computer science problems in C++.computer science problems in C++.
  • 5. Teaching ProcedureTeaching Procedure  LecturesLectures  DiscussionsDiscussions  Assignments (Assignments ( ImportantImportant ))  Sudden QuizzesSudden Quizzes  Mid TermMid Term  Final ExamFinal Exam
  • 6. Material / ResourcesMaterial / Resources  Text BookText Book  Fundamentals of Data Structures in C++ byFundamentals of Data Structures in C++ by horowitz, sahni and mehta.horowitz, sahni and mehta.  wwwwww  Any other good book on Data StructureAny other good book on Data Structure
  • 7. GradingGrading  Assignments/Lab Exam …..…………… 15Assignments/Lab Exam …..…………… 15 %%  Quizzes ………..…………..…..……………Quizzes ………..…………..…..…………… 05 %05 %  Mid Term….…………………………………Mid Term….………………………………… 30 %30 %  Final Exam..…………………………………Final Exam..………………………………… 50 %50 %
  • 8. Keys for success in the course…….Keys for success in the course…….  100 %100 % AttendanceAttendance  Solving AssignmentsSolving Assignments YourselvesYourselves  AttentiveAttentive in class sessionsin class sessions  AskingAsking questionsquestions && questionsquestions unless youunless you are clear about your problem.are clear about your problem.
  • 10.  Every byte in the computer’s memory has anEvery byte in the computer’s memory has an address.address. Addresses are numbers just as everyAddresses are numbers just as every house in a locality has got an address.house in a locality has got an address.  Your program, when it is loaded into memory,Your program, when it is loaded into memory, occupies certain range of these addresses. Thisoccupies certain range of these addresses. This means that every variable and every function inmeans that every variable and every function in your program starts with a particular addressyour program starts with a particular address  NOTE :NOTE : Pointer can only contain thePointer can only contain the ADDRESSADDRESS of certain memory location.of certain memory location.
  • 11.  Normally a variable directly contains a specificNormally a variable directly contains a specific value. Pointer, on the other hand, contains anvalue. Pointer, on the other hand, contains an address of the variable that contains the specificaddress of the variable that contains the specific value.value.  Pointers, like other variables must be declaredPointers, like other variables must be declared before they are used. For e.g.before they are used. For e.g. int *pttrr, temp;int *pttrr, temp;  Pointers should be initialized either when they arePointers should be initialized either when they are declared or in an assignment statement. A pointerdeclared or in an assignment statement. A pointer may be initialized tomay be initialized to 00,, NULLNULL or anor an addressaddress. A. A pointer with the valuepointer with the value 00 oror NULLNULL points to nothing.points to nothing.
  • 12.  NULLNULL is a symbolic constant defined in theis a symbolic constant defined in the header fileheader file <iostream.h>.<iostream.h>. Initializing a pointer toInitializing a pointer to NULLNULL is equivalent to initializing a pointer tois equivalent to initializing a pointer to 00..  Initializing a pointer is necessary to prevent itInitializing a pointer is necessary to prevent it pointing to unknown or un-initialized area ofpointing to unknown or un-initialized area of memory.memory.  There are two pointer operators;There are two pointer operators;  thethe address ofaddress of operatoroperator && andand  indirection operatorindirection operator oror dereferencing operatordereferencing operator i.e.i.e. **..
  • 13.  && is a unary operator that returns theis a unary operator that returns the address ofaddress of itsits operand. For e.g.operand. For e.g. int x = 5;int x = 5; int *ptrr = NULL;int *ptrr = NULL; ptrr = &x;ptrr = &x;  In aboveIn above ** showsshows ptrrptrr is pointer variable whose typeis pointer variable whose type isis intint i.e. it can only contain thei.e. it can only contain the address ofaddress of anyany integer variablesinteger variables in memory.in memory. SimilarlySimilarly
  • 14. cout<< *ptrr <<“n”;cout<< *ptrr <<“n”; cout<< x <<“n”;cout<< x <<“n”;  Will produce the same resultWill produce the same result 55. Here. Here ** meansmeans value ofvalue of the variable to whichthe variable to which ptrrptrr points to, whichpoints to, which isis xx..  Note that the dereferenced pointer may also beNote that the dereferenced pointer may also be used on the left side of an assignment statementused on the left side of an assignment statement as follows.as follows. *pttr = 9;*pttr = 9; oror cin>>*ptrr;cin>>*ptrr;  Following program explains the concept ofFollowing program explains the concept of pointerspointers
  • 15. #include<iostream.h>#include<iostream.h> void main( )void main( ) {{ int x = 5;int x = 5; int *ptrr = NULL;int *ptrr = NULL; ptrr = &x;ptrr = &x; cout<< *ptrr <<“n”;cout<< *ptrr <<“n”; cout<< x <<“n”;cout<< x <<“n”; *pttr = 9;*pttr = 9; cout<< &x <<“n”;cout<< &x <<“n”; cout<< *&ptrr <<“n”;cout<< *&ptrr <<“n”; // cancel effect of each other// cancel effect of each other ( &( & andand *)*) cout<< &*ptrr <<“n”;cout<< &*ptrr <<“n”; cout<< ptrr <<“n”;cout<< ptrr <<“n”; cout<< *ptrr <<“n”;cout<< *ptrr <<“n”; cout<< x <<“n”;cout<< x <<“n”; }} Output of ProgramOutput of Program 55 55 0x0064FDF40x0064FDF4 0x0064FDF40x0064FDF4 0x0064FDF40x0064FDF4 0x0064FDF40x0064FDF4 99 99
  • 16. newnew andand deletedelete operatorsoperators  Variables created during execution ( run time ) ofVariables created during execution ( run time ) of a program by means of special operation isa program by means of special operation is known asknown as Dynamic DataDynamic Data. In C++ operation is. In C++ operation is new.new.  The new operation has two formsThe new operation has two forms newnew DataTypeDataType newnew DataType [intExpression]DataType [intExpression] First form is used for creating a single varaible ofFirst form is used for creating a single varaible of type DataType ( e.g. int,…) attype DataType ( e.g. int,…) at run timerun time.. SecondSecond form creates an array whose elements are ofform creates an array whose elements are of type DataType ( e.g. char,…) attype DataType ( e.g. char,…) at run time.run time.
  • 17.  ExampleExample intint **intptr;intptr; charchar **namestr;namestr; intptr =intptr = newnew int;int; namestr =namestr = newnew char[8];char[8];  Variables created byVariables created by newnew are said to be on theare said to be on the free storefree store oror heapheap, a region of memory set aside, a region of memory set aside forfor Dynamic VariablesDynamic Variables..  The new operator obtains a chunk (portion) ofThe new operator obtains a chunk (portion) of memory from thememory from the free storefree store..
  • 18.  AA Dynamic VariableDynamic Variable isis unnamedunnamed and cannotand cannot bebe directly addresseddirectly addressed. It must be. It must be indirectlyindirectly addressedaddressed through the pointer returned by thethrough the pointer returned by the newnew operator.operator. intint **intptr =intptr = newnew int;int; charchar **namestr =namestr = newnew char[8];char[8]; *intptr = 357;*intptr = 357; strcpy( namestr, “datastructure” );strcpy( namestr, “datastructure” );
  • 19.  Dynamic dataDynamic data can becan be destroyeddestroyed at any timeat any time during theduring the executionexecution of a program when it is noof a program when it is no longer needed. The built-in operatorlonger needed. The built-in operator deletedelete doesdoes that and has two forms,that and has two forms, oneone for deleting singlefor deleting single variable, thevariable, the otherother for deleting an array.for deleting an array. deletedelete pointer;pointer; deletedelete [ ] pointer;[ ] pointer;
  • 20.  Example :Example : intint **ptr1 =ptr1 = newnew int;int; intint **ptr2 =ptr2 = newnew int;int; *ptr2 = 44;*ptr2 = 44; *ptr1 = *ptr2;*ptr1 = *ptr2; ptr1 = ptr2;ptr1 = ptr2; deletedelete ptr2;ptr2;
  • 21.  Inaccessible object :Inaccessible object : A dynamic variable on the free store withoutA dynamic variable on the free store without any pointer pointing to it.any pointer pointing to it.  Dangling pointer :Dangling pointer : A pointer that points to a variable that hasA pointer that points to a variable that has been deallocated.been deallocated. NOTE :NOTE : Leaving inaccessible objects on the freeLeaving inaccessible objects on the free store should be considered a logic error.store should be considered a logic error.
  • 22. Implementation ofImplementation of newnew andand deletedelete operatorsoperators
  • 23. Example :Example : #include<iostream.h>#include<iostream.h> #include<conio.h>#include<conio.h> struct nodestruct node {{ char info[15];char info[15]; };}; class trialclass trial {{ private :private : node obj1, *temp1, *temp2, *temp3;node obj1, *temp1, *temp2, *temp3; int I, length;int I, length; char *p,*q;char *p,*q; public :public : trial();trial(); ~trial(); // Prototype~trial(); // Prototype void startin();void startin(); };};
  • 24. //-----------------------------------------------------------------//----------------------------------------------------------------- void main()void main() {{ clrscr();clrscr(); trial lnk;trial lnk; lnk.startin();lnk.startin(); getch();getch(); }//----------------------------------------------------------------------}//---------------------------------------------------------------------- trial :: trial()trial :: trial() {{ temp1 = temp2 = temp3 = NULL;temp1 = temp2 = temp3 = NULL; }//--------------------------------------------------------------------}//-------------------------------------------------------------------- trial :: ~trial()trial :: ~trial() {{ delete temp1;delete temp1; delete temp2, temp3;delete temp2, temp3; delete[] p; // delete 10 charsdelete[] p; // delete 10 chars }//--------------------------------------------------------------------}//--------------------------------------------------------------------
  • 25. void trial :: startin()void trial :: startin() {{ cout<<"n Making use of "new" and "delete" is as follows.n";cout<<"n Making use of "new" and "delete" is as follows.n"; cout<<"n ---------------------------------------------------nn";cout<<"n ---------------------------------------------------nn"; temp1 = new node;temp1 = new node; temp2 = new node;temp2 = new node; cout<<"n Enter information about temp1.n";cout<<"n Enter information about temp1.n"; cin>>temp1->info;cin>>temp1->info; cout<<"n Enter information about temp2.n";cout<<"n Enter information about temp2.n"; cin>>temp2->info;cin>>temp2->info; temp3 = &obj1;temp3 = &obj1; cout<<"n Enter information about temp3.n";cout<<"n Enter information about temp3.n"; cin>>temp3->info;cin>>temp3->info; cout<<"n Showing information of temp1.n";cout<<"n Showing information of temp1.n"; cout<<temp1->info;cout<<temp1->info; cout<<"n Showing information of temp2.n";cout<<"n Showing information of temp2.n"; cout<<temp2->info;cout<<temp2->info; cout<<"n Showing information of temp3.n";cout<<"n Showing information of temp3.n"; cout<<temp3->info;cout<<temp3->info; cout<<"n ---------------------------------------------------nn";cout<<"n ---------------------------------------------------nn";
  • 26. cout<<" Now enter the length of character array.n";cout<<" Now enter the length of character array.n"; cin>>length;cin>>length; p = new char[length]; // allocate 10 charsp = new char[length]; // allocate 10 chars q = p;q = p; cout<<" Now enter "<<length<<" characters to fill an array.n";cout<<" Now enter "<<length<<" characters to fill an array.n"; for( i=0;i<length; i++ )for( i=0;i<length; i++ ) {{ cin>>*p;cin>>*p; p = p + 1;p = p + 1; }} p = q;p = q;
  • 27. cout<<" nElements of array are as follows.n";cout<<" nElements of array are as follows.n"; for( i=0;i<length; i++ )for( i=0;i<length; i++ ) {{ cout<<*p<<", ";cout<<*p<<", "; p = p + 1;p = p + 1; }} p = q;p = q; }//--- END of startin( )---------------------------------------------------------------}//--- END of startin( )---------------------------------------------------------------