how to set Nth bit of variable by using MACRO

Answer Posted / vikram

The above code is wrong it should be n-1 instead of n.

#include<stdio.h>
#define SET(val,n) (val|=1<<(n-1))
main()
{
int n = 256;
printf("%d",SET(n,1));
}

Is This Answer Correct ?    13 Yes 8 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain how can I make sure that my program is the only one accessing a file?

629


diff between exptected result and requirement?

1596


What is masking?

638


How can I find the modification date and time of a file?

604


How many types of functions are there in c?

586






How will you delete a node in DLL?

686


What are the different file extensions involved when programming in C?

760


What does 1f stand for?

614


Place the #include statement must be written in the program?

573


What is a const pointer?

638


How can I generate floating-point random numbers?

609


Difference between exit() and _exit() function?

658


Explain the use of 'auto' keyword

679


Is c object oriented?

542


What is a ternary operator in c?

654