Function to find the given number is a power of 2 or not?
Answer Posted / abhishek sharma
unsigned int is_power_of_2(unsigned int x)
{
return (x != 0) && ((x & (x - 1)) == 0);
}
| Is This Answer Correct ? | 23 Yes | 3 No |
Post New Answer View All Answers
Can i use “int” data type to store the value 32768? Why?
What is #include stdlib h?
Can stdout be forced to print somewhere other than the screen?
Describe explain how arrays can be passed to a user defined function
WHAT IS THE DEFINATION OF IN TECHNOLOGY AND OFF TECHNOLOGY ?
Write a simple code fragment that will check if a number is positive or negative.
Describe the modifier in c?
Write a program to print fibonacci series using recursion?
Explain what are global variables and explain how do you declare them?
What are pragmas and what are they good for?
typedef enum { html, java, javascript, perl, cgi } lang;The above statement defines a : a) Union b) User defined type c) Enumerated variable d) none
Can variables be declared anywhere in c?
Explain how do you declare an array that will hold more than 64kb of data?
Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal. [ I gave the obvious solution of taking % 10 and / 10, which gives us the decimal value in reverse order. This requires an array since we need to print it out in the correct order. The interviewer wasn't too pleased and asked me to give a solution which didn't need the array ].
main(){char *str;scanf("%s",str);printf("%s",str); }The error in the above program is: a) Variable 'str' is not initialised b) Format control for a string is not %s c) Parameter to scanf is passed by value. It should be an address d) none