Question

Examine each of the following program segments carefully. Determine what is printed from each program. There...

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, z = 70; int *ptr; cout << x << “ “ << y << “ “ << z << endl; ptr = &x; *ptr *= 10; ptr = &y; *ptr *= 5; ptr = &z; *ptr *= 2; cout << x << “ “ << y << “ “ << z << endl; Output _________________________________

0 0
Add a comment Improve this question Transcribed image text
Answer #1
1.
Output of the code is
510152025

2.
Output of the code is
1

3.
Output of the code is
50 60 70
500 300 140


Add a comment
Know the answer?
Add Answer to:
Examine each of the following program segments carefully. Determine what is printed from each program. There...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 4. Each of the following definitions and program s egments has errors. Rewrite them without errors....

    4. Each of the following definitions and program s egments has errors. Rewrite them without errors. a. int x, *ptr; = ptr; b. int x, *ptr; c. int x, *ptr; ptr 100; // Store 100 in x cout << x << endl; d. int numbers10, 20, 30, 40, 50); cout << "The third element in the array is"; cout << *numbers 3<< endl; e. int values [20], *iptr; iptr - values; ptr *= 2;

  • howthe   output   of   the   following   4   program segments (a)    const int SIZE=8;    int values[SIZE]...

    howthe   output   of   the   following   4   program segments (a)    const int SIZE=8;    int values[SIZE] = {10, 10, 14, 16, 6, 25, 5, 8};    int index;    index=0;    res = values[index];    for (int j=1; j<SIZE; j++)    {        if (values[j] > res)        {            res = values[j];            index = j;        cout << index << res << endl;        }    }    cout <<...

  • What is the output from each of the following segments of C++ code? Record the output...

    What is the output from each of the following segments of C++ code? Record the output after the “Answer” prompt at the end of each program fragment. Assume all variables have been suitably declared. (Each problem is worth 3 points.) 1. for (int j = 25; j > 16; j -= 3)        cout << setw(5) << j;     Answer: 2. int sum = 0;       for (int k = -2; k <= 2; k++)         sum = sum +...

  • Find the error in each of the following c++ program segments and explain how the error...

    Find the error in each of the following c++ program segments and explain how the error can be corrected. And rewrite the program appropriately using c++ a. int g(void){ cout<<”Inside function g”<<endl; int h(void) {             cout<<”Inside function h”<<endl; }                         } int sum(int x, int y){ int result; result = x+y;                         } void f(double a); {             float a;             cout<<a<<endl; }

  • // Write a program that determines how many of each type of vowel are in an...

    // Write a program that determines how many of each type of vowel are in an entered string of 50 characters or less. // The program should prompt the user for a string. // The program should then sequence through the string character by character (till it gets to the NULL character) and count how many of each type of vowel are in the string. // Vowels: a, e, i, o, u. // Output the entered string, how many of...

  • USE THE TABLE AND OUTPUT TECHNIQUE FOR THIS 8 POINT PROBLEM What is the output from...

    USE THE TABLE AND OUTPUT TECHNIQUE FOR THIS 8 POINT PROBLEM What is the output from the following SEGMENT: note TYPES OF PARAMETERS AND VARIABLE SCOPES Hint: A table is not necessary but it may help you get the output and its order int (4), C(2): HINT THESE ARE GLOBAL int TestMe(int &Y, int Z) / PROTOTYPE FOR THE FUNCTION int main 0 int A BW: A = 4: B-3 W = Test Me A, B) MI CALL TO THE...

  • [10pts] 7) What is the output of the following program? In other words, what is printed...

    [10pts] 7) What is the output of the following program? In other words, what is printed to the screen when you run it? #include <iostream> #include <queue> using namespace std int main) char qu[5] ('a, 'b',c'd','e' queue <char> q int N = 4; char ch for(int í - 0:ì < 5;++1) q.push(qu (]) for (int ǐ 0;i < N;++i) { = ch q.front); q push(ch): q.pop while(!q.emptyO) f cout << q.front ) <<endl; q.pop )

  • What is the output from each of the following segments of C++ code? Record the output...

    What is the output from each of the following segments of C++ code? Record the output after the “Answer” prompt at the end of each program fragment. Assume all variables have been suitably declared. (Each problem is worth 3 points.) for (int k = 2; k < 5; k++)                    {       for (int j = 3; j < 6; j++)      cout << setw(4) << (k + j) << " ";       cout << endl;    }

  • Question 1) Suppose a program has the following code: const int X = 2, Y =...

    Question 1) Suppose a program has the following code: const int X = 2, Y = 3; int sum; int values[X][Y] = {{1, 2, 3},                                  {4, 5, 6}}; for(int i=0; i<X; i++) {      sum=0;      for(int j=0; j<Y; j++)         sum+=values[i][j];    cout<<sum<<endl; } What is this program getting the sum of? Group of answer choices D-) The columns of the 2D array C-) The rows of the 2D array A-) All of the elements of the 2D...

  • c++ only. Please follow directions. What does the following program print and why? Comment each line...

    c++ only. Please follow directions. What does the following program print and why? Comment each line of code to explain what it is doing.   #include <iostream> using namespace std; int main() { int track[ ] = { 10, 20, 30, 40 }; int * ptr; ptr = track; track[1] += 30; cout << * ptr << " "; *ptr -= 10; ptr++; cout << * ptr << " "; ptr += 2; cout << * ptr << " "; cout...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT