Determine what will be printed from each output of statement of this code below: #include using namespace std; int main() { int apple; int *location; apple = 24; // a is an integer // aPtr is a pointer to an integer location = &apple; // aptr set to address of a cout << "The location of apple is " << &apple << << "\n The value of the location of the apple is location; cout << "\n\nThe value of apple is " << apple << "\nThe value of the location is " << *location; cout << "\n\nOveral inverse operator are as follows" << "\n & (* aPtr) << &*location) << "\n*(&aPtr) '<< *(&location) << endl; return 0; }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Determine what will be printed from each output of statement of this code below:

#include <iostream>

using namespace std;

int main()

{

int apple;

int *location;

apple = 24;

// a is an integer

// aPtr is a pointer to an integer

location = &apple;

// aptr set to address of a

cout << "The location of apple is " << &apple

<<

<< "\n The value of the location of the apple is

location;

cout << "\n\nThe value of apple is " << apple

<< "\nThe value of the location is " << *location;

cout << "\n\nOveral inverse operator are as follows"

<< "\n & (* aPtr) << &*location)

<< "\n*(&aPtr) '<< *(&location) << endl;

return 0;

 

Expert Solution
Code output explanation:

#include <iostream>

using namespace std;

int main()

{

int apple;//varaible declaration

int *location;//integer pointer declaration

apple = 24;//assigning value to variable

// a is an integer

// aPtr is a pointer to an integer

location = &apple;//now pointing pointer varaible to address of integer apple

// aptr set to address of a

//now: & isused to get address:, for example &a :gives the address of variable a
//* is used to get value at address: for example *a: gives the value at the address where a is points to
//note: *&a this means a: here *& both gets cancelled out here 

//note:syntax errors in below line are fixed
cout << "The location of apple is " << &apple<< "\n The value of the location of the apple is "<<
location;//this line prints first address of variable :apple, and its also prints value of location which is again address of apple, since location points to apple, along with text

cout << "\n\nThe value of apple is " << apple<< "\nThe value of the location is " << *location;//this line prints value stored in apple, and *location which means again value stored in apple, since location points to apple, , along with text

//note:syntax errors in below line are fixed
cout << "\n\nOveral inverse operator are as follows "<<"\n& (* aPtr) "<< &(*location)<< "\n*(&aPtr) "<< *(&location) << endl;
//above line prints: &(*location):means we know location = &a, so &(*&a) = &a so prints address of a, , along with text
//then it prints : *(&location): *&&a = &a: so this one alos prints address of a only, , along with text
return 0;

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY