What is the output after executing the following code int x


What is the output after executing the following code? int x = 5, y = 8; while (x

Solution

5)

Output:

I lIke C++

I Like C++

I Like C++

I really do !!

_________________

Reason:

initially x is initialized as 5 and y is intialized as 8

the while loop continue to iterate until the condition x<y satisfying .

for every iteration the value of x is incrementing by 1

so the while lopp will get executed for 3 times.

By the end of the loop the value of x will become 8

but while executingh do- while loop initially there is no condition to check so atleast one time the do-while

loop wil get executed.

I this way this do -while loop will print I really do !!

after the condition check will happen (x<6) but (8<6) is false

so the condition fails.and next iteration will not happen.So finally the output is :

I lIke C++

I Like C++

I Like C++

I really do !!

___________________________________

6)

Output:

Hey There !

Hey There!

Who me ?

Hey There !

Hey There !

Who me ?

Hey There !

____________________

Reason:

Here the for loop gets executed for 5 times.

every time \" Hey There ! \" will get displayed on the console

after that there is as condition check n%2==0 ,

In the first iteration 0%2==0 is true

so the next statement will get executed .i.e continue

so the next statement after the continue will not get executed.

again it executes from first stament inside the loop.

So in the next iteration again it prints \"Hey There !\" on the console

as n value will get increment by 1 now the n value is 1

now as 1%2!=0 then continue statement wont get executed.

the next statements after the continue will get executed.

so it prints \"Who me ?\" on the console

In the next Iteration n value will become 2

\"Hey There \" will be displayed on the console

now as 2%2==0 the continue statement will get executed

continue statement will get executed .so now it wont print \"Who me ?\" on the console.

Like this this program execution takes place

so the final output is

Hey There !

Hey There!

Who me ?

Hey There !

Hey There !

Who me ?

Hey There !

_______________Thank You

 What is the output after executing the following code? int x = 5, y = 8; while (x Solution5) Output: I lIke C++ I Like C++ I Like C++ I really do !! __________
 What is the output after executing the following code? int x = 5, y = 8; while (x Solution5) Output: I lIke C++ I Like C++ I Like C++ I really do !! __________

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site