In: Computer Science
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++;
}
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