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...
3) Consider the following IA32 assembly language code fragment. Assume that a, b and c are...
3) Consider the following IA32 assembly language code fragment. Assume that a, b and c are integer variables declared in the data segment. movl a, %eax movl b, %ebx cmpl %ebx, %eax jge L1 movl %eax, %ecx jmp L2 L1: movl %ebx, %ecx L2: movl %ecx, c Write the C code which is equivalent to the above assembly language code. You don't need to include the variable declarations, a function or anything like that, just show the 1 to 4...
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?
What output is produced by the following code fragment? int num = 0, max = 20;...
What output is produced by the following code fragment? int num = 0, max = 20; while (num < max) { System.out.println(num); num += 4; }
Project on a double pendulum using MATLAB. I have simulated double pendulum chaos using the code...
Project on a double pendulum using MATLAB. I have simulated double pendulum chaos using the code I found in Chegg. Could you please guide in adding a code to determine the time it takes for the second arm of the pendulum to "flip" based on initial starting conditions?
In C++, Complete the Code & Show the output. Schedule the following process using Shortest Job...
In C++, Complete the Code & Show the output. Schedule the following process using Shortest Job First Scheduling algorithm Porcress Burst time Arrival time 1 8 0 2 2 0 3 1 0 4 4 0 Compute the following and show the output a) Individual Waiting time & Turnaround time b) Average Waiting time & Turnaround time c) Display the Gantt chart (Order of Execution)    #include using namespace std; //structure for every process struct Process { int pid; //...
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...
What is the output of the following piece of Java code? int id = 4; double...
What is the output of the following piece of Java code? int id = 4; double grossPay = 81.475; String jobType = "Intern"; System.out.printf("Id: %d, Type: %s, Amount:%.2f", id,grossPay,jobType); Select one: Error Id: 4, Type: Intern, Amount: $81.475 Id: 4, Type: $81.475, Amount: Intern Id: 4, Type: $81.48, Amount:Intern Id: 4, Type: Intern, Amount: $81.48
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT