In this experiment you will investigate the use of pointers and references in a
ID: 3637897 • Letter: I
Question
In this experiment you will investigate the use of pointers and references in a C++ program.Enter, save, compile and execute the following program in MSVS. Call the new project “PtrsAndRefsExp1” and the program “ptrsAndrefs1.cpp”. Answer the questions below:
#include <iostream>
using namespace std;
int main()
{
int i;
int *p;
cout<<&i<<endl;
cout<<p<<endl;
cout<<&p<<endl<<endl;
i=90;
p = &i;
cout<<i<<endl;
cout<<(*p)<<endl;
return 0;
}
Question 1: Please discuss the output (if any), and any errors or warnings your compiler gives. (Hint: Describe how the different operators are being used in different statements. Be as complete as possible in your description.)
Step 2: In this experiment you will investigate the use of pointers and references in a C++ program.
Enter, save, compile and execute the following program in MSVS. Call the new project “PtrsAndRefsExp2” and the program “ptrsAndrefs2.cpp”. Answer the questions below:
#include <iostream>
using namespace std;
int main()
{
int i;
int *p=0;
int &temp=i;
cout<<&i<<endl;
cout<<p<<endl;
cout<<&temp<<endl<<endl;
i=90;
p = &i;
cout<<i<<endl;
cout<<(*p)<<endl;
cout<<temp<<endl;
return 0;
}
Question 2: Please discuss the output (if any), and any errors or warnings your compiler gives. (Hint: Describe how the different operators are being used in different statements. Be as complete as possible in your description.)
Explanation / Answer
step 1: q)1) for the lines cout<<&i<<endl;cout<<p<<endl;
cout<<&p<<endl<<endl;
first some garbage value will be given for &i; nothing will print for p(because nothing is initialized to p ) some garbage value will be given for &p; step2: q)2) variable name should not start with & so we will get an error for &temp=i; invalid variable so remaining statements will not execute...
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.