how % operator worked in c++?
3%5=3;
how?
it should be 0;

Well 3 divided by 5 has 3 left over. The modulus operator computes the remainder of integer division.

The modulus operator returns the remainder after the division operation. So 3%5 returns 3 because 3 divides by 5 zero times and the remainder is 3.

To add further information to JasonHippy's answer
just do cout<<3%5;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.