What is the reason for explicitly declaring L or UL to long values?

If we donot declare a value explicitly then it uses the first data type available for it.

Some examples:

int a = 2; //  2’s data type is int.

long a = 2; // 2’s data type is int.

In both the above cases there will not be any problem.

but what if,,,

unsigned long long a = 21< 36;

as in the above case 1 has int type but we are trying to shift it 36 bits left, and as we all know an int is not that long, so it will overflow.

That’s the reason it’s a good practice to write,

unsigned long long a = 1ULL <  36;

Using Macros to clear and set a bit

There are many ways to clear and set a bit in a variable. But not all the ways are fast and efficient. The quickest way to do this is by shifting 1 or 0 to the bit you want to set or clear respectively.

To set a bit:

#define setBit(var, bit) (var |= 1 << bit)

To clear a bit:

#define clearBit(var, bit) (var &= ~(1 << bit))

you can compile this code and check the output:

#include <stdio.h>

#define setBit(var, bit) (var |= 1 << bit)
#define clearBit(var, bit) (var &= ~(1 << bit))

int main()
{
int a = 2;

printf(“Before setting bit 1: %d\n”, a);
setBit(a, 0);
printf(“After setting bit 1: %d\n”, a);

printf(“Before Clearing bit 1: %d\n”, a);
clearBit(a, 1);
printf(“After Clearing bit 1: %d\n”, a);

return 0;
}

output can be seen in the picture below: