Programmer --- C language details 24 (segment error, type improvement, sizeof & amp; #39; A & amp; #39 ;)

Source: Internet
Author: User

Programmer --- C language details 24 (segment error, type improvement, sizeof & #39; A & #39 ;)
Main Content: Segment error, type improvement, sizeof 'A'

# Include

 
  
Int main () {union test {char a [10]; int B;} u; int * p = (int *) & (u. a [1]); // No Bus Error Caused * p = 17; printf ("% d \ n", * p); # if 0 int * q = 0; // cause a segment error. You can see the segment error when running in linux. * q = 1 is a direct error when running in windows; # endif/* test */printf ("% d \ n", sizeof 'A'); // The output is 4 (or the length of the int on your machine) // because of the type improvement, char changes to int char c1 = 'A', c2 = 'B'; char c3 = c1 + c2; // overflow, the value is 97 + 98-256 =-61 printf ("% d \ n", c1, c2, c3); return 0 ;}

 

Output:


Related Article

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.