I need an output for the following questions: 1.) int main() { int x=50, y=60, z
ID: 3581805 • Letter: I
Question
I need an output for the following questions:
1.)
int main()
{
int x=50, y=60, z=70;
int *ptr;
cout << x << y << x;
ptr=&x;
*ptr ++;
ptr = &y;
*ptr = x;
ptr = &z;
*ptr = *ptr * 2;
cout << x << y << z;
}
2.)
int main()
{
//Call the showStatic function five times
for(int count = 0; count <5; count++)
{
showStatic();
}
return 0;
}
void showStatic()
{
static int numCalls = 0; //Static local variable
numCalls ++;
cout << "This function has been called" << numCalls << "times. " << endl;
}
3.) A program contains the follwoing function
void display(int arg1, double arg2, char arg3)
{
cout << arg1 << arg2 << arg3;
}
WRITE A STATEMENT THAT CALLS THE FUNCTION AND PASSES THE FOLLOWING VARIABLE TO IT:
char name;
int age;
double income;
Explanation / Answer
1)
50 60 50
ptr points to x
*ptr++ increment value in address in ptr i.e x
Hence ,x=51
Again ptr pointer to location of y
Assigned x to pointer ,hence y=51
Again ptr points to location of z
Then,*ptr=70*2=140
Hence,z=140
Final output : 51 51 140
2)
This function has been called 1 times
This function has been called 1 times
This function has been called 1 times
This function has been called 1 times
This function has been called 1 times
This is because the static local variable is deleted every time the function ends.hence same output is observed.
3)
name='s'
age=20
income=100000.0
display(age,income,name);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.