What is the differnece between long and int?
Printable View
What is the differnece between long and int?
Sometimes long is bigger than int - are you doing a test or something?
--
Mats
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.
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.
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
What compiler?
>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;
}
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