It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
Which is executes faster?
1:
n = n << 1;
2:
n = n + n;
Any good compiler will end up making them both the same, so I can't imagine it matters.
In principle, << can be faster for signed types because it's less-strictly defined. n+n is defined whenever it doesn't overflow, but n<<1 is defined only when n is non-negative and the result does not overflow.
In reality, the compiler will generate the exact same machine code for both.
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
If I have to store and do an operation on integers in the wide range of [1, 10^50000]. How can I do them? How can I store such large integers values first of all? And, how can I perform basic operations on them subsequently?
There are specialized libraries for arbitrary precision that will help you with this. One I had success with is GMP.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
int a = 8;
if (a==8)
printf("x");
else
printf("y");
Though a is equal to 8, it outputs y.
The code above always prints x. If your code prints something else, then you omitted vital information in your question.
To find out what that might be, try this:
Insert #undef a before the int a = 8; to make sure there isn't a C preprocessor macro that messes with the code.
Swap the condition to see if a is really what you expect:
if( 8 == a )
This little trick also prevents you from the accidental assignment bug (if( a = 8 ))
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
Just the question! Why can it not sort more than 254859 elements?
It can, but:
It takes forever
You need to use data types that can hold enough elements.
Other than that, there is absolutely no reason why the algorithm itself would be limited to any particular input size.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
How to Optimize this piece of C code...??
int c = no, diff = u - d;
while (no--)
for (d = u; d < p[no]; d += diff)
c++;
The best optimization, for size, speed, cleverness, clarity, and anything else you may think of, is to have no code.
So, just remove those 4 lines from your source(s) and you've optimized your code.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
void main()
{
char c='0';
printf("%d %d",sizeof(c),sizeof('0'));
}
In C, size of char literal is equal to sizeof(int). So sizeof('0') gives the value of sizeof(int) on your implementation.
Also sizeof(char) is always 1 as mandated by the Standard.
The output will be 1 4. The type of the '0' literal is int, which on most systems has a size of 4. The C standard requires that sizeof(char) is 1.
If you get anything less than 4, get in your time machine, and dial in +25 years.