DSA-Lecture03-Pointers, Strings (Outputs)
DSA-Lecture03-Pointers, Strings (Outputs)
1. Pointers
◦ Chapter 1 DSA 4th Ed by Adam Drozdek
◦ SlideShare handouts
2. Strings
◦ Chapter 1 DSA 4th Ed by Adam Drozdek
◦ SlideShare handouts
3. Quiz
Today’s Outline -- Pointers (in C++)
◦ Introduction (Recap)
◦ Pointer Arithmetic
◦ Pointer & Arrays
◦ Reference Variables
◦ Pointers in Functions
◦ New, Delete Function
cout<<*ptr<<endl;
cout<<*ptr++<<endl;
cout<<*ptr<<endl;
cout<<ptr<<endl;
cout<<*ptr;
Pointers & Arrays
int arr[2]={6,87};
int* p1= &arr[0];
cout<<*p1<<" " <<p1<<endl;
cout <<*arr<<" " <<arr;
Pointers & Arrays contd..
int arr[2]={6,87};
int* p1= &arr[0];
cout <<p1 << " " <<*p1;
cout<<" \n " << *p1++ <<" " <<*p1;
_______________________________________________________
int arr[2]={6,87};
int* p1= &arr[0];
Length Length(string);
Concatenation Concate(string1, string2);
But
S1+ ‘ ’ + S2= ‘Hello Pakistan’
Copy To copy the characters of one string to the S1=‘Data Structures’, S2=‘Algorithms’
another Then Copy_String=(S1, S2) = ‘Algorithms’
string str;
str="DSA lecture";
int l=str.length();
cout<<l<<endl;
int pat= str.find('A');
cout<<pat;
Strings
Thank you
Q1. What is the difference between function
members that are virtual and those that are not?
Q2. Write an algorithm or Pseudo code that Counts
all zeros, Odd numbers and even number in a linear
array.
Q3. Consider 2D.Linear arrays AAA[4][5].
(a) Find the total number of elements.
(b) Suppose Base(AAA) = 300 and w=4 words per
memory cell for AAA. Find the address of AAA[3][2] .