Give a oneline C expression to test whether a number is a
power of 2?
Answers were Sorted based on User's Feedback
Answer / dan
if (x & (x-1)) // false only if x is a power of 2
Is This Answer Correct ? | 102 Yes | 8 No |
Answer / ashutosh
I think
if (x & (x-1)) wont work when number is negative.
Is This Answer Correct ? | 12 Yes | 10 No |
Answer / fjords
if (int(log(x)) == log(x)) // log is to the base 2
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / rahul priyadarshi
#define ISPOW2(x) ((x==1)?1:(x&(x-1)))?0:1
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / yevgen
if ((num XOR (num - 1)) == num + num - 1) return true;
else return false;
Is This Answer Correct ? | 1 Yes | 0 No |
1. const char *a; 2. char* const a; 3. char const *a; -Differentiate the above declarations.
void ( * abc( int, void ( *def) () ) ) ();
write a program to count the number the same (letter/character foreg: 's') in a given sentence.
#include<stdio.h> main() { register i=5; char j[]= "hello"; printf("%s %d",j,i); }
Extend the sutherland-hodgman clipping algorithm to clip three-dimensional planes against a regular paralleiepiped
programming in c lanugaue programm will errror error with two header file one as stdio.h and other one is conio.h
Write a routine that prints out a 2-D array in spiral order
Which version do you prefer of the following two, 1) printf(ā%sā,str); // or the more curt one 2) printf(str);
What is the difference between proc means and proc tabulate ? explain with a simple example when you have to use means or tabulate?
A program that will create a movie seat reservation. The program will display the summary seats and its status. The user will be ask what seat no. to be reserved, then it will go back again to the summary to display the updated seat status. If the seat no. is already reserved then it will prompt an error message. And also if the input seat no is out of range then it will also prompt an error message. The program is continuously running. Termination of the program will depends on how the programmer will apply. Sample output: Movie Seats Reservation Summary of Seats: Seat 1: Available Seat 2: Available Seat 3: Available Seat 4: Available Seat 5: Available Enter seat no. (Press 0 to terminate Or the assigned seat capacity) : 1 Movie Seats Reservation Summary of Seats: Seat 1: Reserve Seat 2: Available Seat 3: Available Seat 4: Available Seat 5: Available Enter seat no. (Press 0 to terminate Or the assigned seat capacity) : 6 The Seat no. is out of range! Movie Seats Reservation Summary of Seats: Seat 1: Reserve Seat 2: Available Seat 3: Available Seat 4: Available Seat 5: Available Enter seat no. (Press 0 to terminate Or the assigned seat capacity) : 1 The Seat no. is already reserved! Movie Seats Reservation Summary of Seats: Seat 1: Reserve Seat 2: Available Seat 3: Available Seat 4: Available Seat 5: Available Enter seat no. (Press 0 to terminate Or the assigned seat capacity) : 0 GoodBye... Thank You!!!
main() { char *a = "Hello "; char *b = "World"; clrscr(); printf("%s", strcat(a,b)); } a. Hello b. Hello World c. HelloWorld d. None of the above
main() { char i=0; for(;i>=0;i++) ; printf("%d\n",i); }