I Want to know that what the difference between int and longint is
Although they have the same siza (4 bytes)

Recommended Answers

All 4 Replies

long int is guaranteed not to be smaller than int; that's it.

long int might be the same size as int, it might be bigger than int, it will not be smaller.

In your system, it's the same size. On some systems, it might be bigger, so it could hold a greater range of numbers.

look in limits.h for exact ranges for your compiler.

On most current 64-bit systems, a long int is 64 bits and an int is 32 bits. However, as AD said, look in /usr/include/limits.h (Unix/Linux), or wherever limits.h is found on your system. You can also use the sizeof(int) and sizeof(long int) in your code to determine what they are at run time, just in case your code can run on different architectures. Example:

#include <stdio.h>
int main(void)
{
    printf("sizeof(int) == %ld, sizeof(long int) == %ld\n",
            sizeof(int), sizeof(long int));
    return 0;
}

Note that this is vanilla C code. It works just as well in C++, and you could use cout << "sizeof(int) == " << dec << sizeof(int) << ", sizeof(long int) == " << sizeof(long int) << endl; just as easily.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.