Thinking and talking about the issue of whether my OS is 32-bit or a 64-bit one, I found out there were many ways to know that. But we discuss none of them over here. Here we discuss a cool way in order to find it out.
We all know about pointers in C right? It points to a memory location. That is it holds an address whose contents maybe dereferenced using the ‘*’ operator. There I already said it! The pointer stores an address.
But what is the size of an address? And who determines it?
That is where the matter of 32 and 64 bit comes in. A 32-bit OS means that its addresses are of size 32-bits and it can address upto 2^32 memory locations. As such, a maximum of 4GB. In a previous post of mine, I have mentioned the fact of the file system FAT32 not supporting files larger than 4GB. It is because that file system uses 32-bit addressing.
But our concern is with the OS. The OS determines the addressing and as such, a 32-bit OS allocates 32 bits to a pointer whereas a 64-bit OS allocates 64 bits to a pointer.
We can exploit this allocation to find out if the OS running on our system is 32 or 64 bit. For that, we write a small C code as follows:
printf(“Size is : %d\n”, sizeof(p));
Compile the code using gcc as:
And run it as:
See what number you get as your output. If it is 4, your OS is 32-bit and if it 8, your OS is 64-bit. This is because the 4 and 8 are shown in bytes.
I was hoping to get a way of knowing what my system’s architecture is. But this method can only recognize the OS and not the system.