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

What is a pragma?

866


can we have joblib in a proc ?

1918


What is || operator and how does it function in a program?

835


What are terms in math?

782


What are the advantages of external class?

785


What is stack in c?

827


Is c object oriented?

717


What is c programing language?

816


What are all different types of pointers in c?

763


Explain what is the purpose of "extern" keyword in a function declaration?

804


What is int main () in c?

844


write a c program in such a way that if we enter the today date the output should be next day's date.

1902


c program for searching a student details among 10 student details

1862


What is the use of parallelize in spark?

746


Can we change the value of static variable in c?

744