Constants in C Language

Source: Internet
Author: User

There is such a C program:

 

View code

The results of the final program can be easily guessed, but there is also a useful knowledge: 0xfe is a constant, and the final translation into assembly language is an immediate number, which is stored in registers. This indicates that this constant occupies a word length, and the upper limit of less than one word length is eventually extended to 0. Based on this principle, we can write a mask program that does not depend on a specific machine.

1 # include <stdio. h> 2 3 int main () 4 {5 char hex1 = 0xfe; 6 int hex2 = 0 xfefe; 7 8 char hex3 = hex1 & 0xfe; 9 int hex4 = hex2 & 0 xfefe; 10 11 printf ("hex3 = % x, hex4 = % x \ n", hex3, hex4); 12}

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.