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

Write a Program to find whether the given number or string is palindrome.

605


What are 3 types of structures?

584


write a program fibonacci series and palindrome program in c

626


What is unary operator?

651


What are the functions to open and close the file in c language?

585






Explain what are compound statements?

595


What is far pointer in c?

798


What are the advantages of union?

619


Write a c program to build a heap method using Pointer to function and pointer to structure ?

4167


How can I read a binary data file properly?

626


What is identifier in c?

535


How can I recover the file name given an open stream or file descriptor?

586


Explain b+ tree?

614


In which layer of the network datastructure format change is done

1422


stripos — Find position of first occurrence of a case- insensitive string int stripos ( char* haystack, char* needle, int offset ) Returns the numeric position of the first occurrence of needle in the haystack string. Note that the needle may be a string of one or more characters. If needle is not found, stripos() will return -1. The function should not make use of any C library function calls.

1839