Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Example 2 : Pointers. #include using namespace std; void increment _ all ( int * start, int * stop ) { int * current =
Example : Pointers.
#include
using namespace std;
void incrementallint start, int stop
int current start;
while current stop
current;
current;
void printallconst int start, const int stop
const int current start;
while current stop
cout current
;
current;
int main
int numbers;
incrementallnumbers numbers ;
printallnumbers numbers ;
return ;
Assume that the address of the variable a FAA
int a;
int aPtr;
a ;
aPtr &a;
cout &a endl;
cout aPtr endl;
cout a endl;
cout aPtr endl;
cout &aPtr endl;
cout &aPtr endl;
return ;
#include
using namespace std;
int main
int num num;
int mypointer;
mypointer #
mypointer ;
mypointer #
mypointer ;
cout "firstvalue is num endl;
cout "secondvalue is num endl;
return ;
#include
using namespace std;
int main
int firstvalue secondvalue ;
int pp;
p &firstvalue;
p &secondvalue;
p;
pp;
p p;
p;
cout "firstvalue is firstvalue endl;
cout "secondvalue is secondvalue endl;
return ;
#include
using namespace std;
void doubleitint p
p p ;
void doubleitint n
n n;
int main
int var ;
int pvar &var;
cout pvar
using namespace std;
int main
int pc c;
c ;
cout "Address of c &c: &c endl;
cout "Value of c c: c endl endl;
pc &c; Pointer pc holds the memory address of variable c
cout "Address that pointer pc holds pc: pc endl;
cout "Content of the address pointer pc holds pc: pc endl endl;
c ; The content inside memory address &c is changed from to
cout "Address pointer pc holds pc: pc endl;
cout "Content of the address pointer pc holds pc: pc endl endl;
pc ;
cout "Address of c &c: &c endl;
cout "Value of c c: c endl endl;
return ;
Example : Pointers.
pointers as arguments:
#include
using namespace std;
void incrementall int start, int stop
int current start;
while current stop
current; increment value pointed
current; increment pointer
void printall const int start, const int stop
const int current start;
while current stop
cout current
;
current; increment pointer
int main
int numbers;
incrementall numbersnumbers;
printall numbersnumbers;
return ;
Example : void Pointers
increaser
#include
using namespace std;
void increase void data, int psize
if psize sizeofchar
char pchar; pcharchardata; pchar;
else if psize sizeofint
int pint; pintintdata; pint;
int main
char a x;
int b ;
increase &asizeofa;
increase &bsizeofb;
cout a b
;
return ;
Example : Pointers to functions
pointer to functions
#include
using namespace std;
int addition int a int b
return ab;
int subtraction int a int b
return ab;
int operation int x int y int functocallintint
int g;
g functocallxy;
return g;
int main
int mn;
int minusintint subtraction;
m operation addition;
n operation m minus;
cout
using namespace std;
const int MAX ;
int main
int varMAX;
int ptrMAX;
for int i ; i MAX; i
ptri &vari; assign the address of integer.
for int i ; i MAX; i
cout "Value of var i ;
cout ptri endl;
return ;
Example : Pointer Array
#include
using namespace std;
const int MAX ;
int main
char namesMAX
"Zara Ali",
"Hina Ali",
"Nuha Ali",
"Sara Ali",
;
for int i ; i MAX; i
cout "Value of names i ;
cout namesi endl;
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started