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; }
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;
}
#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;
}
Step by step
Solved in 2 steps with 1 images