+ 1

Why it's output to show 256?

Int n=2 ,m=2; While(m--) n*=n; Cout<<n;

22nd Aug 2020, 1:46 PM
Suparna Podder
Suparna Podder - avatar
10 Réponses
+ 3
May be the value of m will be 3 Output will be 256 because int n =2 ,m=3 in while loop you wrote m While(m--) when first time loop will run it will be while(3--) here value will be decrease after that n*=n means n=2*2 (here n=2) Now n=4 then loop will run again m will be 2 now then n*=n ,n=4*4, n=16 then again loop will run and now value of m will be 1 so again n*=n , n=16*16=256 then m-- here m will be 0 so final answer 256 will print on screen
22nd Aug 2020, 3:03 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 3
Suparna Podder this is very helpful here u can learn pointers in detail Click on this link https://www.youtube.com/playlist?list=PLBlnK6fEyqRjoG6aJ4FvFU1tlXbjLBiOP loop are easy first make simple loop code like print Numbers from 1 to 5 and see how many times it working then increase value and see how its working then use nested loop analyze it . First do dry run in rough copy u will understood much better and write value after one by one .
22nd Aug 2020, 4:21 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 2
Include your code with this method https://www.sololearn.com/post/75089/?ref=app And also correct your code.. there are some syntax error.
22nd Aug 2020, 2:06 PM
AKSHAY🇮🇳
AKSHAY🇮🇳 - avatar
+ 1
Suparna Podder take screen shot and post it your feed post share link here... You may miising something there.. May m=3, not 2.
22nd Aug 2020, 2:36 PM
Jayakrishna 🇮🇳
+ 1
I actually facing problem some output questions like pointer function loop .
22nd Aug 2020, 4:15 PM
Suparna Podder
Suparna Podder - avatar
+ 1
Suparna Podder you can share that problems or make questions. Some one from community, who knows the answer will help you to clear your doubt.. So directly share your problems of those concepts... But don't ask just output🤨
22nd Aug 2020, 4:20 PM
Jayakrishna 🇮🇳
+ 1
Your formatting and indentation is not correct 🤔
24th Aug 2020, 3:01 AM
Sanjay Kamath
Sanjay Kamath - avatar
0
Suparna Podder what is your expected output? Are you sure output 256? Add proof? Wrong output..
22nd Aug 2020, 2:32 PM
Jayakrishna 🇮🇳
0
It's sololearn questions nd it's show to output 256 @jayakrisna
22nd Aug 2020, 2:33 PM
Suparna Podder
Suparna Podder - avatar
0
Thanks a lot its helps me more🗡️ Ulduz 🗡️
22nd Aug 2020, 4:14 PM
Suparna Podder
Suparna Podder - avatar