开发者

question about % operator in C++

开发者 https://www.devze.com 2023-01-10 10:00 出处:网络
i have following code #include <iostream> #include<exception> #include <cstdlib> int main(){

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

精彩评论

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

关注公众号