Saturday, 8 March 2014

Why modulus operator does not work with floating point values ?

We have seen that modulus operator (%) does not support floating point numbers.

(If you have any doubt regarding this visit http://implementc.blogspot.in/2013/12/trap-1-error-illegal-use-of-floating.html ).

If you want to know the reason behind this then continue reading :

Any arithmetic operation between :

1. int and int  = int
2. int and float = float
3. float and float = float

What a%b does is give the remainder of the two numbers. And remainder of any division will always be an integer value. Floating point remainder of any division has no meaning. Think about it.


So if you are using modulus operator with floating point numbers then according to Arithmetic Operation Table result will also have to be floating point number.

How can a remainder of division be a floating type of number?? 

So modulus of two floating point number has no meaning.

Enumeration data type : enum

With advancement in learning to program one encounters many new concepts, remember to all this new concepts were designed to solve complexity of programming. One such concept is of enumeration data type in C. Read further to know about it.


An enumeration is a list of constant integer values, as in

enum boolean { NO, YES };


The first name in an enum has value 0, the next 1, and so on, unless explicit values are specified. If not all values are specified, unspecified values continue the progression from the last specified value, as the second of these examples:

enum escapes { BELL = '\a', BACKSPACE = '\b', TAB = '\t',NEWLINE = '\n', VTAB = '\v', RETURN = '\r' };

enum months { JAN = 1, FEB, MAR, APR, MAY, JUN,JUL, AUG, SEP, OCT, NOV, DEC };
                                                                                                           /* FEB = 2, MAR = 3, etc. */

Names in different enumerations must be distinct. Values need not be distinct in the same enumeration. Enumerations provide a convenient way to associate constant values with names, an alternative to #define with the advantage that the values can be generated for you.

Although variables of enum types may be declared, compilers need not check that what you store in such a variable is a valid value for the enumeration. Nevertheless, enumeration variables offer the chance of checking and so are often better than #defines. In addition, a debugger may be able to print values of enumeration variables in their symbolic form.