What is the differnece between long and int?
What is the differnece between long and int?
Sometimes long is bigger than int - are you doing a test or something?
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
long is always 4 bytes.
int is 2 bytes on 16-bit systems, 4-bytes on 32-bit systems, and I'm guessing it's 8 bytes on 64-bit systems.
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
The C standard specifies what the minimum requirements are for each data type.
Your compiler's limits.h file tells you what you've really got in terms of data type ranges.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
inserThe output is 10. Actually p is declared twice in a file. Hence, it should give compile time error. Then, why we get the output 10?Code:int p=10; int p; int main() { printf("%d",p) getch(); return 0; } inser
>Hence, it should give compile time error.
What makes you think that? C allows an object to be declared multiple times, and one of those declarations will be used as a definition. So in the end, there's really only one object. If you try to initialize more than one of the declarations, that constitutes a multiple definition, and you would get an error, but the following is perfectly legal C:
So is this:Code:#include <stdio.h> int x; int x; int x; int x; int x; int x; int x; int x; int x; int x; int x; int x; int x; int x; int x; int x; int x; int x; int x; int x; int x; int x; int x; int x; int main ( void ) { x = 12345; printf ( "%d\n", x ); return 0; }
But this is not:Code:#include <stdio.h> int x; int x; int x; int x; int x; int x; int x; int x; int x; int x; int x = 12345; int x; int x; int x; int x; int x; int x; int x; int x; int x; int x; int x; int x; int x; int main ( void ) { printf ( "%d\n", x ); return 0; }
There's no benign redefinition rule, so even if the initialization values are identical, it's still seen as multiple definitions. Only the third example will give you an error.Code:#include <stdio.h> int x = 12345; int x = 12345; int main ( void ) { printf ( "%d\n", x ); return 0; }
My best code is written with the delete key.
Why would you exhume a 4 month old thread to ask a different question?
I think cpjust has a point - could one of the moderators dig out the other thread with exactly the same question, and perhaps merge the content of this thread to here.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.