How and what is the output is this? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How and what is the output is this?

long i=0; for(i;i<10;i++) i+=5; cout<<i;

21st May 2021, 6:29 PM
RuntimeERROR
RuntimeERROR - avatar
7 Answers
+ 3
#include <iostream> using namespace std; int main() { //How and what is the output is this? long i; for(i=0;i<10;i++){ i+=5;//i=0+5=5 ,i=5+1=6(i++),i=6+5=11 //11+1(i++)=12 it will not enter the condition cout<<i<<" ";} return 0; }
21st May 2021, 6:33 PM
Atul [Inactive]
+ 1
As you have initialised f=0.01 and you have not initialised 0.01 in if so it is implicitly converting it to double and answer is 0
21st May 2021, 6:50 PM
Atul [Inactive]
+ 1
Yes
22nd May 2021, 4:57 AM
Atul [Inactive]
0
Atul And for this? float f=0.01; if(f==0.01) printf("1"); else printf("0");
21st May 2021, 6:40 PM
RuntimeERROR
RuntimeERROR - avatar
0
Atul int x=3; while(x++<10) x+=2; Printf(x);
21st May 2021, 6:52 PM
RuntimeERROR
RuntimeERROR - avatar
0
Atul U mean if double f=.01 and f==0.01 would have printed 1?
21st May 2021, 6:53 PM
RuntimeERROR
RuntimeERROR - avatar
- 1
For Loop is coded wrongly.. I should have integer data type
22nd May 2021, 12:43 PM
Sanjay Kamath
Sanjay Kamath - avatar