Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

What is the final value of the variable n after this C++ code excuted: int n=5; for(int i=1; i<=n; i++){ cout<<'*'; n--; }?

user-image
Question ajoutée par هاشم المشارقة , Key Account Manager , Advanced United Systems Ltd. ( A member of Taj Holding Group)
Date de publication: 2016/02/03
Gayasuddin Mohammed
par Gayasuddin Mohammed , Advocate , Practicing Law before High Court at Hyderabad

The value of n after the execution is2. it iterates3 times while n decrements by1 and i increments by1 so when3 < =2 (i <=2) fails, loop fails and comes out of the for loop. Thanks.

MohammedMansoor Sahul Hameed
par MohammedMansoor Sahul Hameed , Senior Software Engineer , Femina Lace International

Value of n will be2, since inside the loop value of n is decreasing and the loop will execute only till i<=n.

salma samreen
par salma samreen , Quality Assurance Engineer , Private Limited

int n=5; for (int i=1,i<=5,i++)

cout<<"* n--<<

}

here the output sequence will be you will increment the value of i, till you try to come out of for loop and simultaneously decrement the value of n,

the end result will be4,3,2,1,0

More Questions Like This