Can we use % operator on floating point numbers?
Predict the output of following program:
Can % be used with floating point numbers in C++?
The above program fails in compilation and compiler report the following error in line 5:
invalid operands of types 'float' and 'float' to binary 'operator%'
% operator cannot be used with floating point numbers in C & C++.
What about Java and C#?
This behavior is different in Java & C#. % operator can be used on floating point numbers in these languages.
Consider following example of Java program:
Same way try this C# program. It works fine:
This article is contributed by Meet Pravasi. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above