Make the pointer point at the 5th element of an array

you have insert the following code :
ptr = &x[4];
ptr points to the 5th element of the array x.
Make the pointer point at the 5th element of an array 1 #include <iostream> 3 using namespace std; 4 //make the p...
Make the function take in the variables by reference #include <iostream> using namespace std; //Make the function take in the variables by reference void add_to_first_and_reset(int total, int to_add){ total += to_add; to_add = 0; } int main(){ int sum = 0, temp = 0; for(int i = 0; i < 10; i++){ cin >> temp; add_to_first_and_reset(sum,temp); cout << sum << " " << temp << endl; } }
Question 1: Fix the 2D dynamic array initialization in following code #include <iostream> using namespace std; int main(){ int rows = 5; int cols = 5; int x; int** arr = new int[rows][cols] cin >> x; arr[x][x] = x; cout << "arr[x][x] = " << arr[x][x]; return 0; } Question 2: Fix the code to initialize the 2D array elements to x #include <iostream> using namespace std; int main(){ int rows; int cols; int x;...
what is the output for the following code? explain the steps. /*#include <iostream> using namespace std; int f(int &i) { i = 10; return(5 * i); } int main() { int n = 5; f(n); cout << n << "\n"; return 0; } #include <iostream> using namespace std; int sub1(int n) { n--; return n; } int main() { int m = 10; for(int j = 0; j < 10; j++) m -= sub1(j); cout << m << "\n"; return...
#include <iostream> #include <chrono> using namespace std; double improvedPow(double x, int y) { // To be implemented by you } int main() { cout << "To calculate x^y ..." << endl; double x; int y; cout << "Please enter x: "; cin >> x; cout << "Please enter y: "; cin >> y; if(x == 0) { if (y > 0) cout << 0 << endl; else cout << "x^y is not defined" <<endl; } else { cout << improvedPow(x,y)...
4) What is the output if the input istom - Sawyer? #include <iostream> using namespace std; int main() { string playerName; cout << "Enter name"; cin >> playerName; cout << endl « playerName; return 0; } a. Tom - Sawyer b. Tom Sawyer c. Tom d. Sawyer 5) Which XXX generates "Adam is 30 years old." as the output? #include <iostream> using namespace std; int main() { string name = "Adam"; int age = 30; XXX return 0; } a....
15.6: Fix the code to print the count from 1 to x (to loop x times) #include <iostream> // include the header file using namespace std; void count(int x){ for(int i=1; i<=x; i++){ cout<<x; } } int main(){ int x,i; cin >> x; count(x); return 0; } 15.7 Fix the nested for loops to print the count from 1 to x twice, e.g. "12....x12.....x" #include <iostream> // include the header file using namespace std; int main(){...
#include <iostream> using namespace std; int main(void) { int SIZE; cout<<"Enter the size of the array"<<endl; cin>>SIZE; int *numlist = new int[SIZE]; // Read SIZE integers from the keyboard for (int i = 0; i<SIZE; i++ ) { cout << "Enter value #" << i+1 << ": "; cin >> numlist[i]; } // Display the numbers in a reverse order for (int i = SIZE; i > 0; i--...
One dimensional array What this code print #include <iostream> using namespace std; int main () { const int SIZE = 7; int numbers [SIZE] = {1, 2, 4, 8): // Initialize first 4 elements cout << Here are the contents of the array:\n"; for (int index = 0; index < SIZE: index++} cout << numbers[index] << ; cout << endl; return 0; }
Fix the code to print the result[] array properly:
1 #include <iostream> 2 3 using namespace std; 4 5 void printArray(int array 7 for(inti= 0: i < 2;i++) cout くく array[i] << " ". 10 12 int mainO 13 14 int firstArray[2]10,20}; 16 int resultr21 17 int x; 18 19 II take input for second array 20 cin >>x 21 secondArray[0]-x; 22 secondarrayL1」-X+15 ; // Add elements 23 24 result0]- firstArray[0] + secondArray [0]; 25 result [1]- firstArray[1] + secondArray[1];...
#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...