Write a preprocessor command that halves its input value.


Difficulty level
This exercise is mostly suitable for students
#include <stdio.h>
#define HALFOFWRONG(value) value/2
#define HALFOF(value) ((value)/2)

int main()
{
     int x = 4;
     printf("Value = %d \n",HALFOFWRONG(x+x));
     printf("Value = %d \n",HALFOF(x+x));

     return 0;
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Star pattern 20