Judge whether Ubuntu is 32bit or 64bit in C Language

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.