Question

In: Computer Science

Determine the output using C++ of the following code fragment i) double *pt; double a[3] =...

Determine the output using C++ of the following code fragment

i)

double *pt;
double a[3] = {1.2, 2.3, 3.4}; pt = &a[1];
pt += 1;
cout << *pt << endl;

ii)

int i = 1;
while (i <= 4)
{
int num = 1;
for (int j = 1; j <= i; j++) {
cout << num << "bb";
num *= 3;
}
cout << endl;

i++;

}

Solutions

Expert Solution

i)

​​​​​Output:

3.4

Explanation:

pt stores address of 2.3

then pointer is incremented to point 3rd element

3rd element is printed

ii)

​​​​​Output:

1bb3bb                                                                       

1bb3bb9bb                                                                    

1bb3bb9bb27bb  

Explanation:

bb is appended between 1, 3 , 9... powers of 3 at each iteration


Related Solutions

Consider the following fragment of C code: for (i=0; i<100; i++) { A[i]=B[i]+C; } Assume that...
Consider the following fragment of C code: for (i=0; i<100; i++) { A[i]=B[i]+C; } Assume that A and B are arrays of 64-bit integers, and C and i are 64-bit integers. Assume that all data values and their addresses are kept in memory (at addresses 1000, 3000, 5000, and 7000 for A, B, C, and i, respectively) except when they are operated on. Assume that values in registers are lost between iterations of the loop. Assume all addresses and words...
pleade provide the output and a brief explanation of the following C++ code: double dec1 =...
pleade provide the output and a brief explanation of the following C++ code: double dec1 = 2.5; double dec1 = 3.8; double *p, *q; p = &dec1; *p = dec2 - dec1; q = p; *q = 10.0; *p = 2 * dec1 + (*q); q =&dec2; dec1 = *p + *q; cout<<dec1<<" "<<dec2<< endl; cout<<*p<<" "<<*q<< endl; The following code should output the radius of th ebase, height , volume, and surface area of a cylinder. However, it fails...
Given the following Java source code fragment double price[]; price = new double[16]; What's the name...
Given the following Java source code fragment double price[]; price = new double[16]; What's the name of the array? How many elements are in the array? What's the index of the first element in the array? What's the index of the last element in the array? What's the value of the element at index 3 after the last statement executes?
Javascript. Consider the following code fragment, that is supposed to compute the pixel value let c...
Javascript. Consider the following code fragment, that is supposed to compute the pixel value let c = image.getPixel(x, y); const m1 = (c[0] + c[1] + c[2]) / 3; c = image.getPixel(x + 1, y); const m2 = (c[0] + c[1] + c[2]) / 3; image.setPixel(x, y, [m1 - m2, m1 - m2, m1 - m2]); Give three pairs of pixel values (x, y) = [?, ?, ?] and (x+1, y) = [?, ?, ?] in the input image, for...
I have to translate C++ code into MIPS. It is expected to have an output of:...
I have to translate C++ code into MIPS. It is expected to have an output of: Value of a: 25 Value of b: 31 Value of c: 18 Value of d: 49 Here is the C++ code: I need to translate this C++ into MIPS code. #include using namespace std; int main(void) { int a = 5; int b = 6; int c = 7; int d; d = -1; if ( a < 10){ a++; }else{ a--; } d...
c# code working but output not right, I need to output all numbers like : Prime...
c# code working but output not right, I need to output all numbers like : Prime factors of 4 are: 2 x 2 here is just 2 Prime factors of 7 are: 7 Prime factors of 30 are: 2 x 3 x 5 Prime factors of 40 are: 2 x 2 x 2 x 5 here is just 2,5 Prime factors of 50 are: 2 x 5 x 5 here is just 2,5 1) How I can fix it 2)I...
Complete the following exercises using C programming language. Take screenshots of the code and its output...
Complete the following exercises using C programming language. Take screenshots of the code and its output where specified and paste them into in a well-labeled Word document for submission. Scenario Assume you are the CIO of an organization with three different IT department locations with separate costs. You want a program to perform simple IT expenditure calculations. Your IT expenditure target is $35,000 per site. Site expenditures: Site 1 – $35,000. Site 2 – $37,500. Site 3 – $42,500. Exercise...
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 = 8; j > 3; j -= 2)         cout << setw(5) << j;     Answer:      2. int sum = 5;    for (int k = -4; k <= 1; k++)         sum = sum...
Write a code fragment in C language that tests the value of an integer num1. If...
Write a code fragment in C language that tests the value of an integer num1. If the value is 10, square num1. If it is 9, read a new value into num1. If it is 2 or 3, multiply num1 by 99 and print out the result. Implement your code using SWITCH statements
C++ program. Please explain how the code resulted in the output. The code and output is...
C++ program. Please explain how the code resulted in the output. The code and output is listed below. Code: #include <iostream> #include <string> using namespace std; int f(int& a, int b) {    int tmp = a;    a = b;    if (tmp == 0) { cout << tmp << ' ' << a << ' ' << b << endl; }    b = tmp;    return b;    return a; } int main() {    int a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT