SlideShare a Scribd company logo
Kinan keshkeh 
IT Engineering-Damascus University 
3rd year 
Summer course- 2014 
2 bytes team
Welcome !
Pointers !
Pointers 
•A pointer is the memory address of a variable. 
•If a variable holds numbers of Bytes then its address in memory is the address of the first byte ! 
•Pointer variable declarations : SYNTAX Type_Name *Variable_Name1, *Variable_Name2,. . .; EXAMPLE: double *pointer1, *pointer2;
Pointers 
•A pointer is the memory address of a variable. 
•If a variable holds numbers of Bytes then its address in memory is the address of the first byte ! 
•Pointer variable declarations : SYNTAX Type_Name *Variable_Name1, *Variable_Name2,. . .; EXAMPLE: double *pointer1, *pointer2; 
Asterisk sign
Pointers 
•void manipulatePointer(int *p); //Accepted but not as nice. int* p1, *p2; //Accepted but dangerous. 
•void manipulatePointer(int* p); int *p1, *p2;
Pointers 
•int* findOtherPointer(int* p); 
Pointers can be Returned type
Pointers 
42 
42 
v1 = 0; 
p1 = &v1; 
*p1 = 42; 
cout << v1 << endl; 
cout << *p1 << endl;
Pointers 
42 42 
v1 = 0; 
p1 = &v1; 
*p1 = 42; 
cout << v1 << endl; 
cout << *p1 << endl;
Pointers 
•See the difference
Pointers 
•MyType *p; p = new MyType; 
•MyType *mtPtr; mtPtr = new MyType(32.0, 17); // calls MyType(double, int); 
constructor 
•If the type is a class type :
Pointers 
•MyType *p; p = new MyType; 
•MyType *mtPtr; mtPtr = new MyType(32.0, 17); // calls MyType(double, int); 
•If the type is a class type : 
•int *n; n = new int(17); // initializes *n to 17 
•nonclass types
Pointers
Pointers 
•Explanation:
Pointers 
int *p; p = new int; if (p == NULL) { cout << "Error: Insufficient memory.n"; exit(1); } delete p; //If new succeeded, the program continues from here.
Pointers 
int *p; p = new int; if (p == NULL) { cout << "Error: Insufficient memory.n"; exit(1); } delete p; //If new succeeded, the program continues from here. 
Memory ensuring
Pointers 
int *p; 
p = new int; 
if (p == NULL) 
{ 
cout << "Error: Insufficient memory.n"; 
exit(1); 
} 
delete p; 
//If new succeeded, the program continues from here. 
Free the memory location
Pointers
Pointers
Pointers 
Output:
“Typedef“
typedef 
•You can use typedef to define an alias for any type name or definition. 
typedef double Kilometers; 
………………… Kilometers distance; 
•You can define a pointer type name so that pointer variables can be declared like other variables without the need to place an asterisk in front of each pointer variable. 
………………… IntPtr p1,p2,p3; 
typedef int* IntPtr;
typedef 
•You can use typedef to define an alias for any type name or definition. 
typedef double Kilometers; 
………………… Kilometers distance; 
•You can define a pointer type name so that pointer variables can be declared like other variables without the need to place an asterisk in front of each pointer variable. 
………………… IntPtr p1,p2,p3; 
typedef int* IntPtr;
ARRAYS & POINTERS !
ARRAYS & POINTERS 
•The Array name is a pointer to the first of array , so you can use a pointer instead of array name ( but in the opposite way can’t )
ARRAYS & POINTERS
ARRAYS & POINTERS 
Output :
Dynamic array !
Dynamic array 
•Determine memory places as we need ! 
•The User would put its dimension from runtime . 
Type *p; 
p=new Type[n];
Dynamic array 
•Determine memory places as we need ! 
•The User would put its dimension from runtime . 
Type *p; 
p=new Type[n]; 
Double , float , char …
Dynamic array 
•Determine memory places as we need ! 
•The User would put its dimension from runtime . 
Type *p; p=new Type[n]; 
It could be by « User »
Dynamic array 
•Determine memory places as we need ! 
•The User would put its dimension from runtime . 
Type *p; p=new Type[n]; 
It could be by « User » 
So it’s Dynamic !!!
Dynamic array
Dynamic array
Dynamic array 
delete a [] ; « Illegal »
Dynamic array
POINTER ARITHMETIC !
POINTER ARITHMETIC 
•*(p + i) == p[i] *(p++) == p[i++] *(++p ) == p[++i] and the same if “ - “ 
•subtract tow pointers(the same type ) returns the number of the same type elements !
POINTER ARITHMETIC 
#include <iostream> using std::cout; using std::endl; int main( ) { int a[] = {1, 2, 3, 4, 5}; int* b; b = a; for (int i = 0; i < 5; i++) cout << *(b+i) << " "; return 0 ; } /* The above is equivalent to the following: for (int i = 0; i < arraySize; i++) cout << b[i] << " "; */
Multi dimensional dynamic array !
Multi dimensional dynamic array 
•It’s an Array of Array ! 
•To make an Array n * m 
•We make an (m) array of pointers from the type ( T ) by “new” 
•then from each pointer we make an (n) array of type ( T ) by “new”
Multi dimensional dynamic array 
#include <iostream> 
using std::cin; 
using std::cout; 
using std::endl; 
typedef int* IntArrayPtr; 
int main( ) 
{ 
int d1, d2; 
cout << "Enter the row and column dimensions of the array:n"; 
cin >> d1 >> d2; 
IntArrayPtr *m = new IntArrayPtr[d1]; 
int i, j; 
for (i = 0; i < d1; i++) 
m[i] = new int[d2]; 
//m is now a d1-by-d2 array. 
cout << "Enter " << d1 << " rows of " 
<< d2 << " integers each:n"; 
for (i = 0; i < d1; i++) 
for (j = 0; j < d2; j++) 
cin >> m[i][j]; 
cout << "Echoing the two-dimensional array:n"; 
for (i = 0; i < d1; i++) 
{ 
for (j = 0; j < d2; j++) 
cout << m[i][j] << " "; 
cout << endl; 
} 
for (i = 0; i < d1; i++) 
delete[] m[i]; 
delete[] m; 
return 0; 
}
Multi dimensional dynamic array 
#include <iostream> using std::cin; using std::cout; using std::endl; typedef int* IntArrayPtr; int main( ) { int d1, d2; cout << "Enter the row and column dimensions of the array:n"; cin >> d1 >> d2; IntArrayPtr *m = new IntArrayPtr[d1]; int i, j; for (i = 0; i < d1; i++) m[i] = new int[d2]; //m is now a d1-by-d2 array. cout << "Enter " << d1 << " rows of " << d2 << " integers each:n"; for (i = 0; i < d1; i++) for (j = 0; j < d2; j++) cin >> m[i][j]; cout << "Echoing the two-dimensional array:n"; for (i = 0; i < d1; i++) { for (j = 0; j < d2; j++) cout << m[i][j] << " "; cout << endl; } for (i = 0; i < d1; i++) delete[] m[i]; delete[] m; return 0; }
Multi dimensional dynamic array 
Enter the row and column dimensions of the array: 
3 4 
Enter 3 rows of 4 integers each: 
1 2 3 4 
5 6 7 8 
9 0 1 2 
Echoing the two-dimensional array: 
1 2 3 4 
5 6 7 8 
9 0 1 2
ARRAYS & classes !
ARRAYS & classes 
struct Record 
{ 
int number; 
char grade; 
}; 
Record *p; 
p = new Record; 
p->number = 2001; 
p->grade = ’A’; // <===========> (*p).grade=‘A’ 
•The operator “ -> “ :
ARRAYS & classes 
class Sample 
{ 
public: 
... 
void showStuff( ) const; 
... 
private: 
int stuff; 
... 
}; 
•THE this POINTER :
ARRAYS & classes 
void Sample::showStuff( ) const { cout << stuff; } //Not good style, but this illustrates the this pointer void Sample::showStuff( ) { cout << this->stuff; } 
•THE this POINTER :
ARRAYS & classes 
•THE this POINTER : 
It is useful when you have a collision with another variable at the same namespace !
ARRAYS & classes 
#include <iostream> 
#include <cstdlib> 
using namespace std; 
class DayOfYear{ 
public: 
void input( ); 
void output( ); 
void set(int month, int day); 
void set(int month); 
int getMonthNumber( ); 
int getDay( ); 
private: 
int month; 
int day; 
}; 
void DayOfYear::set(int month, int day) 
{ 
if ((month >= 1) && (month <= 12)) 
this->month = month; 
else{ 
cerr << "Illegal month value! Program aborted.n"; 
exit(1); 
} 
if ((day >= 1) && (day <= 31)) 
this->day = day; 
else{ 
cout << "Illegal day value! Program aborted.n"; 
exit(1); 
} 
}
Code discussion !
Code discussion
Code discussion
Code discussion
Code discussion
Code discussion
Code discussion 
Output Example :
Homework 
• سؤال عممي : 
ي ا رد بناء سمسمة خطية لمسيا ا رت لشركة ما حيث لكل سيارة 
)رقم السيارة – تاريخ التسجيل ( 
• المطموب: 
1 - كتابة اج ا رئية Insert لبناء السمسة بحيث يضاف المعطى 
حسب الرقم بالمكان الصحيح 
2 - كتابة اج ا رئية Print لطباعة بيانات السمسمة 
3 - كتابة تابع يقوم بالبحث عن عنصر حسب الرقم 
4 -كتابة تابع يقوم بمقارنة تاريخين 
5 - طباعة السيا ا رت المسجمة قبل تاريخ معين بالاستعانة بالتابع 
السابق
That’s for today 
That’s for today guys !!
That’s for today 
Go and Play ! 
Bye Bye !
2 bytes team 
Group : group link 
Mobile phone- Kinan : 0994385748 
Facebook account : kinan’s account 
2 bytes team
Ad

More Related Content

What's hot (20)

C++11
C++11C++11
C++11
ppd1961
 
What's New in C++ 11/14?
What's New in C++ 11/14?What's New in C++ 11/14?
What's New in C++ 11/14?
Dina Goldshtein
 
C++ references
C++ referencesC++ references
C++ references
corehard_by
 
Pointers
PointersPointers
Pointers
sanya6900
 
Smart Pointers in C++
Smart Pointers in C++Smart Pointers in C++
Smart Pointers in C++
Francesco Casalegno
 
06.Loops
06.Loops06.Loops
06.Loops
Intro C# Book
 
Array notes
Array notesArray notes
Array notes
Hitesh Wagle
 
13 Strings and Text Processing
13 Strings and Text Processing13 Strings and Text Processing
13 Strings and Text Processing
Intro C# Book
 
Smart pointers
Smart pointersSmart pointers
Smart pointers
Vishal Mahajan
 
C++11: Rvalue References, Move Semantics, Perfect Forwarding
C++11: Rvalue References, Move Semantics, Perfect ForwardingC++11: Rvalue References, Move Semantics, Perfect Forwarding
C++11: Rvalue References, Move Semantics, Perfect Forwarding
Francesco Casalegno
 
C++11 smart pointer
C++11 smart pointerC++11 smart pointer
C++11 smart pointer
Lei Yu
 
C++ L09-Classes Part2
C++ L09-Classes Part2C++ L09-Classes Part2
C++ L09-Classes Part2
Mohammad Shaker
 
C++11 concurrency
C++11 concurrencyC++11 concurrency
C++11 concurrency
xu liwei
 
Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)
Geeks Anonymes
 
Advanced C - Part 2
Advanced C - Part 2Advanced C - Part 2
Advanced C - Part 2
Emertxe Information Technologies Pvt Ltd
 
C++ L11-Polymorphism
C++ L11-PolymorphismC++ L11-Polymorphism
C++ L11-Polymorphism
Mohammad Shaker
 
C++ L02-Conversion+enum+Operators
C++ L02-Conversion+enum+OperatorsC++ L02-Conversion+enum+Operators
C++ L02-Conversion+enum+Operators
Mohammad Shaker
 
C++ Pointers
C++ PointersC++ Pointers
C++ Pointers
Chaand Sheikh
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
Ilio Catallo
 
friends functionToshu
friends functionToshufriends functionToshu
friends functionToshu
Sidd Singh
 

Viewers also liked (17)

2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph
kinan keshkeh
 
10 Little Tricks to Get Your Class’s Attention (and Hold It)
10 Little Tricks to Get Your  Class’s Attention (and Hold It)10 Little Tricks to Get Your  Class’s Attention (and Hold It)
10 Little Tricks to Get Your Class’s Attention (and Hold It)
kinan keshkeh
 
2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templates2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templates
kinan keshkeh
 
Pointers in C
Pointers in CPointers in C
Pointers in C
Prabhu Govind
 
2CPP06 - Arrays and Pointers
2CPP06 - Arrays and Pointers2CPP06 - Arrays and Pointers
2CPP06 - Arrays and Pointers
Michael Heron
 
Authorship and Autership
Authorship and AutershipAuthorship and Autership
Authorship and Autership
Michael Heron
 
ACCESS: A Technical Framework for Adaptive Accessibility Support
ACCESS:  A Technical Framework for Adaptive Accessibility SupportACCESS:  A Technical Framework for Adaptive Accessibility Support
ACCESS: A Technical Framework for Adaptive Accessibility Support
Michael Heron
 
Pointers in c
Pointers in cPointers in c
Pointers in c
Mohd Arif
 
Ise rt c2_s14_nour_40714
Ise rt c2_s14_nour_40714Ise rt c2_s14_nour_40714
Ise rt c2_s14_nour_40714
Alaa Bar Avi
 
أخلاقيات العالم الافتراضي نهائي
أخلاقيات العالم الافتراضي نهائيأخلاقيات العالم الافتراضي نهائي
أخلاقيات العالم الافتراضي نهائي
Alaa Bar Avi
 
Accessibility Support with the ACCESS Framework
Accessibility Support with the ACCESS FrameworkAccessibility Support with the ACCESS Framework
Accessibility Support with the ACCESS Framework
Michael Heron
 
Musings on misconduct
Musings on misconductMusings on misconduct
Musings on misconduct
Michael Heron
 
تصميم مواقع الشرق الأوسط
تصميم مواقع الشرق الأوسطتصميم مواقع الشرق الأوسط
تصميم مواقع الشرق الأوسط
Alaa Bar Avi
 
النشرالإلكتروني
النشرالإلكترونيالنشرالإلكتروني
النشرالإلكتروني
Alaa Bar Avi
 
مبادئ التحرير الإعلامي
مبادئ التحرير الإعلاميمبادئ التحرير الإعلامي
مبادئ التحرير الإعلامي
Alaa Bar Avi
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
LPU
 
التحرير الإخباري
التحرير الإخباريالتحرير الإخباري
التحرير الإخباري
Alaa Bar Avi
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph
kinan keshkeh
 
10 Little Tricks to Get Your Class’s Attention (and Hold It)
10 Little Tricks to Get Your  Class’s Attention (and Hold It)10 Little Tricks to Get Your  Class’s Attention (and Hold It)
10 Little Tricks to Get Your Class’s Attention (and Hold It)
kinan keshkeh
 
2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templates2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templates
kinan keshkeh
 
2CPP06 - Arrays and Pointers
2CPP06 - Arrays and Pointers2CPP06 - Arrays and Pointers
2CPP06 - Arrays and Pointers
Michael Heron
 
Authorship and Autership
Authorship and AutershipAuthorship and Autership
Authorship and Autership
Michael Heron
 
ACCESS: A Technical Framework for Adaptive Accessibility Support
ACCESS:  A Technical Framework for Adaptive Accessibility SupportACCESS:  A Technical Framework for Adaptive Accessibility Support
ACCESS: A Technical Framework for Adaptive Accessibility Support
Michael Heron
 
Pointers in c
Pointers in cPointers in c
Pointers in c
Mohd Arif
 
Ise rt c2_s14_nour_40714
Ise rt c2_s14_nour_40714Ise rt c2_s14_nour_40714
Ise rt c2_s14_nour_40714
Alaa Bar Avi
 
أخلاقيات العالم الافتراضي نهائي
أخلاقيات العالم الافتراضي نهائيأخلاقيات العالم الافتراضي نهائي
أخلاقيات العالم الافتراضي نهائي
Alaa Bar Avi
 
Accessibility Support with the ACCESS Framework
Accessibility Support with the ACCESS FrameworkAccessibility Support with the ACCESS Framework
Accessibility Support with the ACCESS Framework
Michael Heron
 
Musings on misconduct
Musings on misconductMusings on misconduct
Musings on misconduct
Michael Heron
 
تصميم مواقع الشرق الأوسط
تصميم مواقع الشرق الأوسطتصميم مواقع الشرق الأوسط
تصميم مواقع الشرق الأوسط
Alaa Bar Avi
 
النشرالإلكتروني
النشرالإلكترونيالنشرالإلكتروني
النشرالإلكتروني
Alaa Bar Avi
 
مبادئ التحرير الإعلامي
مبادئ التحرير الإعلاميمبادئ التحرير الإعلامي
مبادئ التحرير الإعلامي
Alaa Bar Avi
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
LPU
 
التحرير الإخباري
التحرير الإخباريالتحرير الإخباري
التحرير الإخباري
Alaa Bar Avi
 
Ad

Similar to 2 BytesC++ course_2014_c9_ pointers and dynamic arrays (20)

Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Language
madan reddy
 
C Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory managementC Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory management
Sreedhar Chowdam
 
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
 
2 BytesC++ course_2014_c1_basicsc++
2 BytesC++ course_2014_c1_basicsc++2 BytesC++ course_2014_c1_basicsc++
2 BytesC++ course_2014_c1_basicsc++
kinan keshkeh
 
C++ process new
C++ process newC++ process new
C++ process new
敬倫 林
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
kinan keshkeh
 
C
CC
C
Jerin John
 
Lecture#9 Arrays in c++
Lecture#9 Arrays in c++Lecture#9 Arrays in c++
Lecture#9 Arrays in c++
NUST Stuff
 
C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8
Christian Nagel
 
Pointers
PointersPointers
Pointers
Frijo Francis
 
UNIT 4 POINTERS.pptx pointers pptx for basic c language
UNIT 4 POINTERS.pptx pointers pptx for basic c languageUNIT 4 POINTERS.pptx pointers pptx for basic c language
UNIT 4 POINTERS.pptx pointers pptx for basic c language
wwwskrilikeyou
 
Learn C program in Complete c programing string and its functions like array...
Learn C program in Complete c programing  string and its functions like array...Learn C program in Complete c programing  string and its functions like array...
Learn C program in Complete c programing string and its functions like array...
paraliwarrior
 
ch03-parameters-objects.ppt
ch03-parameters-objects.pptch03-parameters-objects.ppt
ch03-parameters-objects.ppt
Mahyuddin8
 
Bsc cs 1 pic u-5 pointer, structure ,union and intro to file handling
Bsc cs 1 pic u-5 pointer, structure ,union and intro to file handlingBsc cs 1 pic u-5 pointer, structure ,union and intro to file handling
Bsc cs 1 pic u-5 pointer, structure ,union and intro to file handling
Rai University
 
Dynamic Memory Allocation.pptx for c language and basic knowledge.
Dynamic Memory Allocation.pptx for c language and basic knowledge.Dynamic Memory Allocation.pptx for c language and basic knowledge.
Dynamic Memory Allocation.pptx for c language and basic knowledge.
2024163103shubham
 
CPP Language Basics - Reference
CPP Language Basics - ReferenceCPP Language Basics - Reference
CPP Language Basics - Reference
Mohammed Sikander
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
WondimuBantihun1
 
Object Oriented Programming using C++ - Part 4
Object Oriented Programming using C++ - Part 4Object Oriented Programming using C++ - Part 4
Object Oriented Programming using C++ - Part 4
University College of Engineering Kakinada, JNTUK - Kakinada, India
 
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
Rai University
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Language
madan reddy
 
C Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory managementC Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory management
Sreedhar Chowdam
 
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
 
2 BytesC++ course_2014_c1_basicsc++
2 BytesC++ course_2014_c1_basicsc++2 BytesC++ course_2014_c1_basicsc++
2 BytesC++ course_2014_c1_basicsc++
kinan keshkeh
 
C++ process new
C++ process newC++ process new
C++ process new
敬倫 林
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
kinan keshkeh
 
Lecture#9 Arrays in c++
Lecture#9 Arrays in c++Lecture#9 Arrays in c++
Lecture#9 Arrays in c++
NUST Stuff
 
C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8
Christian Nagel
 
UNIT 4 POINTERS.pptx pointers pptx for basic c language
UNIT 4 POINTERS.pptx pointers pptx for basic c languageUNIT 4 POINTERS.pptx pointers pptx for basic c language
UNIT 4 POINTERS.pptx pointers pptx for basic c language
wwwskrilikeyou
 
Learn C program in Complete c programing string and its functions like array...
Learn C program in Complete c programing  string and its functions like array...Learn C program in Complete c programing  string and its functions like array...
Learn C program in Complete c programing string and its functions like array...
paraliwarrior
 
ch03-parameters-objects.ppt
ch03-parameters-objects.pptch03-parameters-objects.ppt
ch03-parameters-objects.ppt
Mahyuddin8
 
Bsc cs 1 pic u-5 pointer, structure ,union and intro to file handling
Bsc cs 1 pic u-5 pointer, structure ,union and intro to file handlingBsc cs 1 pic u-5 pointer, structure ,union and intro to file handling
Bsc cs 1 pic u-5 pointer, structure ,union and intro to file handling
Rai University
 
Dynamic Memory Allocation.pptx for c language and basic knowledge.
Dynamic Memory Allocation.pptx for c language and basic knowledge.Dynamic Memory Allocation.pptx for c language and basic knowledge.
Dynamic Memory Allocation.pptx for c language and basic knowledge.
2024163103shubham
 
CPP Language Basics - Reference
CPP Language Basics - ReferenceCPP Language Basics - Reference
CPP Language Basics - Reference
Mohammed Sikander
 
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
Rai University
 
Ad

More from kinan keshkeh (20)

Simpson and lagranje dalambair math methods
Simpson and lagranje dalambair math methods Simpson and lagranje dalambair math methods
Simpson and lagranje dalambair math methods
kinan keshkeh
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
kinan keshkeh
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
kinan keshkeh
 
GeneticAlgorithms_AND_CuttingWoodAlgorithm
GeneticAlgorithms_AND_CuttingWoodAlgorithm  GeneticAlgorithms_AND_CuttingWoodAlgorithm
GeneticAlgorithms_AND_CuttingWoodAlgorithm
kinan keshkeh
 
Algorithm in discovering and correcting words errors in a dictionary or any w...
Algorithm in discovering and correcting words errors in a dictionary or any w...Algorithm in discovering and correcting words errors in a dictionary or any w...
Algorithm in discovering and correcting words errors in a dictionary or any w...
kinan keshkeh
 
2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units
kinan keshkeh
 
2Bytesprog2 course_2014_c7_double_lists
2Bytesprog2 course_2014_c7_double_lists2Bytesprog2 course_2014_c7_double_lists
2Bytesprog2 course_2014_c7_double_lists
kinan keshkeh
 
2Bytesprog2 course_2014_c6_single linked list
2Bytesprog2 course_2014_c6_single linked list2Bytesprog2 course_2014_c6_single linked list
2Bytesprog2 course_2014_c6_single linked list
kinan keshkeh
 
2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointers2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointers
kinan keshkeh
 
2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfiles2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfiles
kinan keshkeh
 
2Bytesprog2 course_2014_c3_txtfiles
2Bytesprog2 course_2014_c3_txtfiles2Bytesprog2 course_2014_c3_txtfiles
2Bytesprog2 course_2014_c3_txtfiles
kinan keshkeh
 
2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_records2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_records
kinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
kinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
kinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
kinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
kinan keshkeh
 
2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphism2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphism
kinan keshkeh
 
2 BytesC++ course_2014_c11_ inheritance
2 BytesC++ course_2014_c11_ inheritance2 BytesC++ course_2014_c11_ inheritance
2 BytesC++ course_2014_c11_ inheritance
kinan keshkeh
 
2 BytesC++ course_2014_c10_ separate compilation and namespaces
2 BytesC++ course_2014_c10_ separate compilation and namespaces 2 BytesC++ course_2014_c10_ separate compilation and namespaces
2 BytesC++ course_2014_c10_ separate compilation and namespaces
kinan keshkeh
 
2 BytesC++ course_2014_c8_ strings
2 BytesC++ course_2014_c8_ strings 2 BytesC++ course_2014_c8_ strings
2 BytesC++ course_2014_c8_ strings
kinan keshkeh
 
Simpson and lagranje dalambair math methods
Simpson and lagranje dalambair math methods Simpson and lagranje dalambair math methods
Simpson and lagranje dalambair math methods
kinan keshkeh
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
kinan keshkeh
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
kinan keshkeh
 
GeneticAlgorithms_AND_CuttingWoodAlgorithm
GeneticAlgorithms_AND_CuttingWoodAlgorithm  GeneticAlgorithms_AND_CuttingWoodAlgorithm
GeneticAlgorithms_AND_CuttingWoodAlgorithm
kinan keshkeh
 
Algorithm in discovering and correcting words errors in a dictionary or any w...
Algorithm in discovering and correcting words errors in a dictionary or any w...Algorithm in discovering and correcting words errors in a dictionary or any w...
Algorithm in discovering and correcting words errors in a dictionary or any w...
kinan keshkeh
 
2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units
kinan keshkeh
 
2Bytesprog2 course_2014_c7_double_lists
2Bytesprog2 course_2014_c7_double_lists2Bytesprog2 course_2014_c7_double_lists
2Bytesprog2 course_2014_c7_double_lists
kinan keshkeh
 
2Bytesprog2 course_2014_c6_single linked list
2Bytesprog2 course_2014_c6_single linked list2Bytesprog2 course_2014_c6_single linked list
2Bytesprog2 course_2014_c6_single linked list
kinan keshkeh
 
2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointers2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointers
kinan keshkeh
 
2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfiles2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfiles
kinan keshkeh
 
2Bytesprog2 course_2014_c3_txtfiles
2Bytesprog2 course_2014_c3_txtfiles2Bytesprog2 course_2014_c3_txtfiles
2Bytesprog2 course_2014_c3_txtfiles
kinan keshkeh
 
2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_records2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_records
kinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
kinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
kinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
kinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
kinan keshkeh
 
2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphism2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphism
kinan keshkeh
 
2 BytesC++ course_2014_c11_ inheritance
2 BytesC++ course_2014_c11_ inheritance2 BytesC++ course_2014_c11_ inheritance
2 BytesC++ course_2014_c11_ inheritance
kinan keshkeh
 
2 BytesC++ course_2014_c10_ separate compilation and namespaces
2 BytesC++ course_2014_c10_ separate compilation and namespaces 2 BytesC++ course_2014_c10_ separate compilation and namespaces
2 BytesC++ course_2014_c10_ separate compilation and namespaces
kinan keshkeh
 
2 BytesC++ course_2014_c8_ strings
2 BytesC++ course_2014_c8_ strings 2 BytesC++ course_2014_c8_ strings
2 BytesC++ course_2014_c8_ strings
kinan keshkeh
 

Recently uploaded (20)

Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Ranjan Baisak
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Ranjan Baisak
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 

2 BytesC++ course_2014_c9_ pointers and dynamic arrays

  • 1. Kinan keshkeh IT Engineering-Damascus University 3rd year Summer course- 2014 2 bytes team
  • 4. Pointers •A pointer is the memory address of a variable. •If a variable holds numbers of Bytes then its address in memory is the address of the first byte ! •Pointer variable declarations : SYNTAX Type_Name *Variable_Name1, *Variable_Name2,. . .; EXAMPLE: double *pointer1, *pointer2;
  • 5. Pointers •A pointer is the memory address of a variable. •If a variable holds numbers of Bytes then its address in memory is the address of the first byte ! •Pointer variable declarations : SYNTAX Type_Name *Variable_Name1, *Variable_Name2,. . .; EXAMPLE: double *pointer1, *pointer2; Asterisk sign
  • 6. Pointers •void manipulatePointer(int *p); //Accepted but not as nice. int* p1, *p2; //Accepted but dangerous. •void manipulatePointer(int* p); int *p1, *p2;
  • 7. Pointers •int* findOtherPointer(int* p); Pointers can be Returned type
  • 8. Pointers 42 42 v1 = 0; p1 = &v1; *p1 = 42; cout << v1 << endl; cout << *p1 << endl;
  • 9. Pointers 42 42 v1 = 0; p1 = &v1; *p1 = 42; cout << v1 << endl; cout << *p1 << endl;
  • 10. Pointers •See the difference
  • 11. Pointers •MyType *p; p = new MyType; •MyType *mtPtr; mtPtr = new MyType(32.0, 17); // calls MyType(double, int); constructor •If the type is a class type :
  • 12. Pointers •MyType *p; p = new MyType; •MyType *mtPtr; mtPtr = new MyType(32.0, 17); // calls MyType(double, int); •If the type is a class type : •int *n; n = new int(17); // initializes *n to 17 •nonclass types
  • 15. Pointers int *p; p = new int; if (p == NULL) { cout << "Error: Insufficient memory.n"; exit(1); } delete p; //If new succeeded, the program continues from here.
  • 16. Pointers int *p; p = new int; if (p == NULL) { cout << "Error: Insufficient memory.n"; exit(1); } delete p; //If new succeeded, the program continues from here. Memory ensuring
  • 17. Pointers int *p; p = new int; if (p == NULL) { cout << "Error: Insufficient memory.n"; exit(1); } delete p; //If new succeeded, the program continues from here. Free the memory location
  • 22. typedef •You can use typedef to define an alias for any type name or definition. typedef double Kilometers; ………………… Kilometers distance; •You can define a pointer type name so that pointer variables can be declared like other variables without the need to place an asterisk in front of each pointer variable. ………………… IntPtr p1,p2,p3; typedef int* IntPtr;
  • 23. typedef •You can use typedef to define an alias for any type name or definition. typedef double Kilometers; ………………… Kilometers distance; •You can define a pointer type name so that pointer variables can be declared like other variables without the need to place an asterisk in front of each pointer variable. ………………… IntPtr p1,p2,p3; typedef int* IntPtr;
  • 25. ARRAYS & POINTERS •The Array name is a pointer to the first of array , so you can use a pointer instead of array name ( but in the opposite way can’t )
  • 27. ARRAYS & POINTERS Output :
  • 29. Dynamic array •Determine memory places as we need ! •The User would put its dimension from runtime . Type *p; p=new Type[n];
  • 30. Dynamic array •Determine memory places as we need ! •The User would put its dimension from runtime . Type *p; p=new Type[n]; Double , float , char …
  • 31. Dynamic array •Determine memory places as we need ! •The User would put its dimension from runtime . Type *p; p=new Type[n]; It could be by « User »
  • 32. Dynamic array •Determine memory places as we need ! •The User would put its dimension from runtime . Type *p; p=new Type[n]; It could be by « User » So it’s Dynamic !!!
  • 35. Dynamic array delete a [] ; « Illegal »
  • 38. POINTER ARITHMETIC •*(p + i) == p[i] *(p++) == p[i++] *(++p ) == p[++i] and the same if “ - “ •subtract tow pointers(the same type ) returns the number of the same type elements !
  • 39. POINTER ARITHMETIC #include <iostream> using std::cout; using std::endl; int main( ) { int a[] = {1, 2, 3, 4, 5}; int* b; b = a; for (int i = 0; i < 5; i++) cout << *(b+i) << " "; return 0 ; } /* The above is equivalent to the following: for (int i = 0; i < arraySize; i++) cout << b[i] << " "; */
  • 41. Multi dimensional dynamic array •It’s an Array of Array ! •To make an Array n * m •We make an (m) array of pointers from the type ( T ) by “new” •then from each pointer we make an (n) array of type ( T ) by “new”
  • 42. Multi dimensional dynamic array #include <iostream> using std::cin; using std::cout; using std::endl; typedef int* IntArrayPtr; int main( ) { int d1, d2; cout << "Enter the row and column dimensions of the array:n"; cin >> d1 >> d2; IntArrayPtr *m = new IntArrayPtr[d1]; int i, j; for (i = 0; i < d1; i++) m[i] = new int[d2]; //m is now a d1-by-d2 array. cout << "Enter " << d1 << " rows of " << d2 << " integers each:n"; for (i = 0; i < d1; i++) for (j = 0; j < d2; j++) cin >> m[i][j]; cout << "Echoing the two-dimensional array:n"; for (i = 0; i < d1; i++) { for (j = 0; j < d2; j++) cout << m[i][j] << " "; cout << endl; } for (i = 0; i < d1; i++) delete[] m[i]; delete[] m; return 0; }
  • 43. Multi dimensional dynamic array #include <iostream> using std::cin; using std::cout; using std::endl; typedef int* IntArrayPtr; int main( ) { int d1, d2; cout << "Enter the row and column dimensions of the array:n"; cin >> d1 >> d2; IntArrayPtr *m = new IntArrayPtr[d1]; int i, j; for (i = 0; i < d1; i++) m[i] = new int[d2]; //m is now a d1-by-d2 array. cout << "Enter " << d1 << " rows of " << d2 << " integers each:n"; for (i = 0; i < d1; i++) for (j = 0; j < d2; j++) cin >> m[i][j]; cout << "Echoing the two-dimensional array:n"; for (i = 0; i < d1; i++) { for (j = 0; j < d2; j++) cout << m[i][j] << " "; cout << endl; } for (i = 0; i < d1; i++) delete[] m[i]; delete[] m; return 0; }
  • 44. Multi dimensional dynamic array Enter the row and column dimensions of the array: 3 4 Enter 3 rows of 4 integers each: 1 2 3 4 5 6 7 8 9 0 1 2 Echoing the two-dimensional array: 1 2 3 4 5 6 7 8 9 0 1 2
  • 46. ARRAYS & classes struct Record { int number; char grade; }; Record *p; p = new Record; p->number = 2001; p->grade = ’A’; // <===========> (*p).grade=‘A’ •The operator “ -> “ :
  • 47. ARRAYS & classes class Sample { public: ... void showStuff( ) const; ... private: int stuff; ... }; •THE this POINTER :
  • 48. ARRAYS & classes void Sample::showStuff( ) const { cout << stuff; } //Not good style, but this illustrates the this pointer void Sample::showStuff( ) { cout << this->stuff; } •THE this POINTER :
  • 49. ARRAYS & classes •THE this POINTER : It is useful when you have a collision with another variable at the same namespace !
  • 50. ARRAYS & classes #include <iostream> #include <cstdlib> using namespace std; class DayOfYear{ public: void input( ); void output( ); void set(int month, int day); void set(int month); int getMonthNumber( ); int getDay( ); private: int month; int day; }; void DayOfYear::set(int month, int day) { if ((month >= 1) && (month <= 12)) this->month = month; else{ cerr << "Illegal month value! Program aborted.n"; exit(1); } if ((day >= 1) && (day <= 31)) this->day = day; else{ cout << "Illegal day value! Program aborted.n"; exit(1); } }
  • 58. Homework • سؤال عممي : ي ا رد بناء سمسمة خطية لمسيا ا رت لشركة ما حيث لكل سيارة )رقم السيارة – تاريخ التسجيل ( • المطموب: 1 - كتابة اج ا رئية Insert لبناء السمسة بحيث يضاف المعطى حسب الرقم بالمكان الصحيح 2 - كتابة اج ا رئية Print لطباعة بيانات السمسمة 3 - كتابة تابع يقوم بالبحث عن عنصر حسب الرقم 4 -كتابة تابع يقوم بمقارنة تاريخين 5 - طباعة السيا ا رت المسجمة قبل تاريخ معين بالاستعانة بالتابع السابق
  • 59. That’s for today That’s for today guys !!
  • 60. That’s for today Go and Play ! Bye Bye !
  • 61. 2 bytes team Group : group link Mobile phone- Kinan : 0994385748 Facebook account : kinan’s account 2 bytes team