Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following are different programs that implement pointers. What would be the result of each ? Explain in details the concept of each line of

The following are different programs that implement pointers. What would be the result of
each ? Explain in details the concept of each line of below codes.
1 #include
using namespace std;
int main()
{//Assume that the address of the variable a =0015FAA0
int a;
int *aPtr;
a =7;
aPtr = &a;
cout << &a << endl;
cout << aPtr << endl;
cout << a << endl;
cout <<*aPtr << endl;
cout << &*aPtr << endl;
cout <<*&aPtr << endl;
return 0;}
2 #include
using namespace std;
int main ()
{ int num1, num2;
int *mypointer;
mypointer = &num1;
*mypointer =10;
mypointer = &num2;
*mypointer =20;
cout << "firstvalue is "<< num1<< endl;
cout << "secondvalue is "<< num2<< endl;
return 0;}
3 #include
using namespace std;
int main ()
{
int firstvalue =5, secondvalue =15;
int *p1,*p2;
p1= &firstvalue;
p2= &secondvalue;
*p1=10;
*p2=*p1;
p1= p2;
*p1=20;
cout << "firstvalue is "<< firstvalue << endl;
cout << "secondvalue is "<< secondvalue << endl;
return 0;
}
4 #include
using namespace std;
void double_it_1(int *p)
{
*p =*p *2;
}
void double_it_2(int n)
{
n = n*2;
}
int main(){
int var =10;
int *pvar = &var;
cout <<*pvar <

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions