开发者

question about % operator in C++

i have following code

#include <iostream>
#include<exception>
#include <cstdlib>
int main(){
     for (int i=0;i<100;i++){
        std::cout<<i<<" ";
        if (i %5==0){
         abort();
        }

     }




         return 0;开发者_运维百科


}

but it only writes 0 and says that abort was called why?i think it should ouput 0 1 2 3 4 and than exit program yes?


Think of % as "remainder after division." 0 / 5 equals 0 with a remainder of 0.


when i is 0, 0 % 5 equals 0

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜