Foreword during the O & M work today, I suddenly forgot to check whether the Ubuntu system is a 32-bit or 64-bit command. So I thought of writing a small program in C language for judgment, which is quite interesting, record the C language method concept in 32bit machines. The memory address is identified by 32bit in 64bit machines. Therefore, the memory address is identified by 64bit, we can print the number of bytes of the pointer * 8 is not the number of digits of the cpu. Code # include & lt; stdio. h & gt
Preface
During the O & M work today, I suddenly forgot to check whether the Ubuntu system is a 32bit or 64bit command. So I thought of writing a small program in C language for judgment. It was quite interesting to record it.
C Language Method
Ideas
- In a 32bit machine, the memory address is identified by 32bit
- In 64-bit machines, the memory address is identified by 64-bit
- Therefore, we can print the number of pointer bytes * 8 is not the number of cpu digits
Code
# Include
# Include
Int main ()
{
Char * p;
Printf ("cpu bits: % d \ n", 8 * sizeof (p ));
Return 0;
}
Execution result
How to view Ubuntu commands
Uname-
Result
Description
I386 and i686 represent 32bit machines.
X86_64 stands for 64bit machines
Question
I reviewed the operating system a year and a half ago, but I almost forgot about it. I don't know if the number of cpu digits and pointer size can be associated. If I understand it wrong, thank you for your comments!