Why do I get different result on Xcode (C Language) [duplicate] - printf

This question already has answers here:
Why does sizeof(int) vary across different operating systems?
(4 answers)
Closed 3 years ago.
long number = 100;
printf("the sizeof: %d", sizeof(number));
In Visual Studio, I get the result 4.
In Xcode, whereas I get the result 8.
Same code, different result. Could you tell me why I get this result?

See here: long is guaranteed by the standard to be "at least 32 bits", and depending on the data model may be bigger.
If you want "exactly 32 bits", try if int32_t is supported.

Related

Why arc4random_uniform instead of random or rand? [duplicate]

This question already has answers here:
Arc4random modulo biased
(1 answer)
What's the difference between arc4random and random?
(2 answers)
Closed 8 years ago.
I've been trying to create program in Objective-C to return random value between specific minimum to maximum value.
I've searched online and found out people are using arc4random_uniform instead of random() or rand().
My question is how arc4random is different from random()?
random() is definitely easier to remember and I get same result from both arc4random and random()
Thank You.
Regards.

Performance of "x IN (a,b)" vs. "x = a OR x = b" [duplicate]

This question already has answers here:
SQL statements with equals vs in
(2 answers)
Closed 9 years ago.
Is there likely to be any difference in performance on SQL Server between:
where (anothercolumn=17) OR (anothercolumn=23) OR (anothercolumn=33)
and
where anothercolumn IN (17,23,33)
No, they optimize exactly the same way, and you should never see any performance difference whatsoever. The only exception would be if you have a very large amount of columns and the actual network performance of transferring the query text itself introduces some latency (or exceeds the transfer size). If that happens you should hire new network people.

Storing and computing with real numbers up to an arbitrary precision in vb.net [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
.NET Framework Library for arbitrary digit precision
How can I store a real number, eg, root 2 or one third, up to an arbitrary precision (the precision I need is infinate precision) in vb.net?
I would like to be able to store real numbers and perform operations on them (ie root 2 times root 2) without losing any accuracy - IE storing 1/3 would return the value 1/3 if I needed to retrieve this value.
I was thinking of using a fractal encoding but I am unsure as to the best way to do this.
Storage capacity is not an issue, I just need the real numbers to be 100% accurate.
Will that be a single real number there or does it need to be an arbitrary number of (almost) arbitrary figures? (Sorry for "answer" - for some reason i can't add comments now...)

Data Types Obj-C [duplicate]

This question already has an answer here:
Closed 11 years ago.
Exact Duplicate:
Issue with float and double data types in objective C
[Ironically, to find the duplicate questions you need to know the answer.]
What Every Computer Scientist Should Know About Floating-Point Arithmetic
If it cannot be expressed in base 2, it will not be precise. See also floating point inaccuracy.
0.1 is a 'repeating decimal' in binary (0.0001100110011...) so the representation of 0.1 is inexact. NSLog is likely rounding or truncating the output.

same random number should not generate again and again? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicates:
C++ random number generator without repeating numbers
Unique random numbers in O(1)?
I am doing as following
int y = arc4random() % 50;
I am using objective-c
Now as I don't want same number again and again, like if 6 is once I get, then I don't need 6 again, because I am calling this line again and again and taking random numbers.
How about you generate an array (1,2,3,4,5,6,...) and sort it randomly, then read the array elements one at a time.
Otherwise, if you use a random number generator and make sure it only gives you numbers you haven't seen before, you can only call it a limited number of times.
sorting randomly will depend on what language you're using.