5 questions all need to bewritten in c++. --------------------------------------
ID: 3687023 • Letter: 5
Question
5 questions all need to bewritten in c++.
-------------------------------------------------------
Look at the following code.
int x = 7;
int *iptr = &x;
What will be displayed if you send the expression *iptr to cout? What happens if you send the expression iptr to cout?
Look at the following array definition.
int numbers[] = {2, 4, 6, 8, 10};
What will the following statement display?
cout << *(numbers + 3) << endl;
Look at the following code.
double value = 29.7;
double *ptr = &value;
Write a cout statement that uses the ptr variable to display the contents of the value variable.
Look at the following function definition.
void getNumber(int &n)
{
cout << “Enter a number: “;
cin >> n)
}
In this function, the parameter n is a reference variable. Rewrite the function so that n is a pointer.
Correct the following code snippet -
int x, *ptr = nullptr;
ptr = &x;
ptr = 100; / Store 100 in x
cout << x << endl;
Explanation / Answer
1.
int x = 7;
int *iptr = &x;
cout<<*iptr; // it will show 7, value of variable to whic iptr points
cout<<iptr; // it will print address of x, content of iptr
2.
int numbers[] = {2, 4, 6, 8, 10};
cout << *(numbers + 3) << endl; // it will print element at index 3- numbers[3], 8
3.
double value = 29.7;
double *ptr = &value;
cout<<*ptr; // will dispaly value of value variable
4.
void getNumber(int &n)
{
cout << “Enter a number: “;
cin >> n)
}
Using pointer:
void getNumber(int *n)
{
cout << “Enter a number: “;
cin >> *n
}
5.
int x, *ptr = nullptr;
ptr = &x;
*ptr = 100; // Store 100 in x
cout << x << endl;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.