+ 2

What is the output? unsigned int i; int count=0; for (i=0; i<10;i--) cout++; printf("%d",count);

Cprog

12th Dec 2018, 2:17 PM
stephen muganyizi
stephen muganyizi - avatar
7 Answers
+ 11
Output is 1 because i is unsigned https://code.sololearn.com/c1vbAu60AH9V/?ref=app
12th Dec 2018, 2:21 PM
Rstar
Rstar - avatar
+ 6
The for loop has some issue if it was supposed to increment `count` 10 times. The loop's step should be incremented otherwise the program just step through the loop's body once and when the `i` decremented for the first time, the value will wrap around and it'll be 4294967295 which breaks the loop due to `i < 10` condition. Test: #include <stdio.h> int main() { unsigned int i; int count = 0; for (i = 0; i < 10; i--) { count++; printf("i = %u, count = %d\n", i, count); } printf("i = %u, count = %d", i, count); } Output: i = 0, count = 1 i = 4294967295, count = 1
12th Dec 2018, 3:13 PM
Babak
Babak - avatar
0
1
27th Dec 2018, 11:56 PM
ZoUler Alcantara
ZoUler Alcantara - avatar
0
Many errors in ur program
12th Jan 2019, 7:14 AM
Wasif Ali
Wasif Ali - avatar
0
I think it must give error as cout must be count
22nd Jan 2019, 12:40 PM
Mohammed Arish
Mohammed Arish - avatar
0
Ur prgm will generate many errors
27th Jan 2019, 5:05 AM
Anamika kumari
Anamika kumari - avatar
0
beacuse loop decremant to decreased fidelity
9th May 2019, 5:46 AM
Bianca
Bianca - avatar