Problem statementSend feedbackint a = 7;int b = 17;int *c = &b;*c = 7;cout << a << " “ << b << endl;
Question
Problem statementSend feedbackint a = 7;int b = 17;int *c = &b;*c = 7;cout << a << " “ << b << endl;
Solution
The code you've written is in C++. Here's a step-by-step explanation of what it does:
-
int a = 7;This line declares an integer variableaand assigns it the value7. -
int b = 17;This line declares an integer variableband assigns it the value17. -
int *c = &b;This line declares a pointercand assigns it the address ofb. This meanscis pointing tob. -
*c = 7;This line changes the value at the address pointed to bycto7. Sincecis pointing tob, this effectively changes the value ofbto7. -
cout << a << " “ << b << endl;This line prints the values ofaandbto the console. Sinceb's value was changed to7in the previous step, the output will be7 7.
Similar Questions
What is the final output of the following code?int a = 5;int b = 10;int c = 3;for(int x =0; x< 5; x++){ a += 2; b -= 1; c *= 2;}cout<<"A is "<<a<<" and C is "<<c<<endl
Which of the following are invalid statements.*1 pointint Scanner = 45;int Class = 45;int main = 45;int If = 45;None of the above
#include<iostream>using namespace std;void demo(int a, int b) { cout << a << " " << b;}int main() { int a = 5; int b = 15; demo(a);}Options: Pick one correct answer from below5 15Compilation Error5 0None of these
n the following code,int f(int *a) { *a = 20;}int main() { int m = 30; f(&m);}a.The parameter passing is "pass by address", and the "address of m" is passedb.Parameter passing is by value, the value passed is "address of m", and copied into the argument *a c.Parameter passing is by value, the value passed is "m", and copied into the argument a d.Parameter passing is by value, the value passed is "address of m", and copied into the argument ae.The parameter passing is "pass by reference" and variable a is a reference to variable m.
This code produces an error message. Where will the error occur, and why?1 bool a = 1;2 int b = 2 + 4;3 float c = 4;4 cout<<a + b<<endl;
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.