1 int n 3 int k n 2 int j n 2 k cout

1) int n = 3

int k = n++ * 2

int j = ++n * 2 + k

cout << j / n

When the code runs, what does it output to the console?

2) int k = 99

for (int i = 1 i < k + 1 ++i)

{

cout << \"hi again\"

}

How many times does the code print \"hi again\"?

Solution

a)

int n = 3

int k = n++ * 2 //here n++ means after execution of this statement \'n\' increment by 1. as it is post increment //so k=3*2=6 and n becomes 4

int j = ++n * 2 + k // here first n is incremented by 1 as it is pre increment so n=4+1=5

// j=5*2+6=16

cout << j / n // j/n=16/5 =3.2 but as j and n both are integer(in built data type mapping) so it will so it will //store only integer part =3

output on console: 3

b)

int k = 99

for (int i = 1 i < k + 1 ++i)

{

cout << \"hi again\"

}

it will print 99 times hi again, beacause for loop work as first it

it repeats this process till i=99 after that i=100 , (i<k+1 ) condition becomes false and it will stop execution

1) int n = 3 int k = n++ * 2 int j = ++n * 2 + k cout << j / n When the code runs, what does it output to the console? 2) int k = 99 for (int i = 1 i <

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site