+ 1

Why the count is 5 as if(c>5)....in the following code...pls explain????...I m a very beginner...

#include <stdio.h> enum { kristi,mh}; int main() { int c=1,count=0; do { printf("%d\n",c++); count ++; if(c>5) break ; } while(mh); printf("%d",count); return 0; }

8th May 2020, 6:14 AM
kristidhar pandit
kristidhar pandit - avatar
14 Antworten
+ 1
Loop breaks then c=6 (6>5) and count =5
8th May 2020, 6:24 AM
Igor Kostrikin
Igor Kostrikin - avatar
+ 1
Igor Kostrikin ...pls explain
8th May 2020, 6:27 AM
kristidhar pandit
kristidhar pandit - avatar
+ 1
Ok..got it😊
8th May 2020, 6:36 AM
kristidhar pandit
kristidhar pandit - avatar
+ 1
Igor Kostrikin xplain pls
8th May 2020, 6:47 AM
kristidhar pandit
kristidhar pandit - avatar
+ 1
Igor Kostrikin ..frm which country u r??
8th May 2020, 7:29 AM
kristidhar pandit
kristidhar pandit - avatar
+ 1
Igor Kostrikin ...will u give me ur email_id ...so that I can contact with u...if u hav no problem....??
8th May 2020, 8:09 AM
kristidhar pandit
kristidhar pandit - avatar
0
Your condition for break operator c>5. This work then c=6. initially c=1, count=0 Loop steps(variables increments on each step) : 1. c=2 count=1 2. c=3 count=2 3. c=4 count=3 4. c=5 count=4 5. c=6 count=5 <- at this step break occurs
8th May 2020, 6:31 AM
Igor Kostrikin
Igor Kostrikin - avatar
0
Here we are printing the value of "c" and then incrementing the value of variable "c" Simultaneously we incrementing the count value by "1". After that we are checking the value of "c" >5 or not using if condition
8th May 2020, 6:37 AM
Dasarath Singh
0
Why you use internal if operator for loop break? This can be done with correct while(condition)
8th May 2020, 6:42 AM
Igor Kostrikin
Igor Kostrikin - avatar
0
do { printf("%d\n",c++); count++; } while(c<6)
8th May 2020, 6:51 AM
Igor Kostrikin
Igor Kostrikin - avatar
0
If you use ++c instead of c++ in printf you will see correct values of variable c on each step
8th May 2020, 6:57 AM
Igor Kostrikin
Igor Kostrikin - avatar
0
Russia
8th May 2020, 8:01 AM
Igor Kostrikin
Igor Kostrikin - avatar
0
gosh.tk@yandex.ru
8th May 2020, 8:16 AM
Igor Kostrikin
Igor Kostrikin - avatar
0
C=1 and count =0 initially Loop will be stopped when c=6 and by that tym count equals to 5
9th May 2020, 6:24 PM
BADAL BAHINIPATI
BADAL BAHINIPATI - avatar