What is the output of the following?
int x = 50, y = 60, z = 70;
int* ptr;
ptr = &x;
*ptr += 10;
ptr = &y;
*ptr += 5;
ptr = &z;
*ptr -= 3;
cout << x << “ ” << y << “ ” << z << endl;
A) 10 5 2
B) 50 60 70
C) 60 65 67
D) 60 65 72
Hopefully all yours doubt will clear if you have left with any doubt please let me know in comment. I will try my best to resolve that.
Answer 1) :-
Correct option is C. Which is 60 65 67. Because :-
//variable declaration
int x = 50, y = 60, z = 70;
//initialization of pointer ptr
int* ptr;
// A pointer variable that holds address of variable x
ptr = &x;
// Value at address is now incremented by 10 i.e. now x = 60
*ptr += 10;
// A pointer variable that holds address of variable y
ptr = &y;
// Value at address is now incremented by 5 i.e. now y = 65
*ptr += 5;
// A pointer variable that holds address of variable z
ptr = &z;
// Value at address is now decremented by 3 i.e. now z = 67
*ptr -= 3;
//print values of x, y, z separated by space i.e. 60 65 67
cout<<x<<" "<<y<<"
"<<z<<endl;
Option A is incorrect as values of x, y, z are incorrect.
Option B is incorrect as values of x, y, z are incorrect.
Option D is incorrect as values of z is incorrect.
Examine each of the following program segments carefully. Determine what is printed from each program. There are no intentional errors. 1. int array[] = {1, 2, 3, 4, 5}; for (int i = 0; i < 5; i++) cout << array[i]*5 << “ “; Output _________________________________ 2. int *iptr; iptr = new int[5]; for (int count = 0; count < 5; count++) iptr[count] = count+1; cout << *iptr << endl; Output _________________________________ 3. int x = 50, y = 60,...
What is the output of the following program? int main(void) { int x, y, z; x = 5; y= test(x); z= x + y; cout<< setw(4)<<x <<” + “<<setw(4)<<y<<”=” << setw(4)<<z<<endl; return 0; } int test (int x) { int w; w = x + 10; return (w); }
51. What is the output of the following code snippet? int number = 0; int ptr_num -&number ptr_num 60; number-80 cout < "ptr num << endl b, 60 c. 80 d. the address of number Answer 52. What is the output of the following code snippet? double num-0.0; double* ptr = # num = 15.0; ptr ptr 15.0 cout << num <<"ptr <<endl; a. 15 15 b. 15 30 С. 30 15 d. 30 30 Answer: 53. What is the...
12. What is the output of the following C++ code? int x; int y; int *p = &x; int *q = &y; *p = 35; *q = 98; *p = *q; cout << x << " " << y << endl; cout << *p << " " << *q << endl; 13. What is the output of the following C++ code? int x; int y; int *p = &x; int *q = &y; x = 35; y = 46; p...
What is the output? (3 pts) int num = 5; int* ptr = # cout << ptr << endl; cout << &ptr << endl; cout << *ptr << endl;
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int x;
int y;
int z;
int r1;
int r2;
cin >> x;
cin >> y;
cin >> z;
r1 = 4* pow(x,3)-5*pow(y,2)+3*z;
r2 = r1+7*pow(x,3)-2*pow(y,2)+11*z;
cout << "r1=";
cout << 4* pow(x,3)-5*pow(y,2)+3*z;
cout << endl;
cout << "r2=";
cout << r1+7*pow(x,3)-2*pow(y,2)+11*z;
cout << endl;
cout << "r3=";
cout << r2-9*pow(x,3)+22*pow(y,2)-6*z;
cout << endl;
return 0;
}
1-115 Your output r2-395 13-186 5:Compare output Output differs. See highlights below. -163...
What is the output of the following C program? int x=1, y=2; int * const ptr = &x; ptr = &y; printf("%d\n", *ptr); What is the output of the following C program? int x=1, y=2; const int * ptr = &x; ptr = &y; printf("%d\n", *ptr); What is the output of the following C program? int x=1, y=2; int * ptr = &x; ptr = &y; printf("%d\n", *ptr); What is the output of the following C program? int x=1, y=2;...
Computer Science C++ Program What is the output? int num =5; int* ptr = # cout << ptr << endl; cout << &ptr << endl; cout << *ptr << endl; What are the values stored in the following array? Draw a simple picture of the array with indexes and show what each element should be. int arrayExample [4] = { 5 };
What does the following code output? int x = 7, y = 10; X -= 30; y *= 5; X += 32; y /= 4; cout << "y = " « y << " and x = " << x << "; " << endl; X -= 10; y /= 5; cout << "x = " << x < " and y = " << y « ";" << endl;
What is the output of the program? int function1( int x, int& y) { if( x % 2 == 0) { x = x + y; } y = y - x; return x; } int main() { int a, b, result; cin >> a >> b; result = function1(a, b); cout << "a = "<< a << ", b = " << b << endl; cout << "result = " << result << endl; } Please make comments...