C Programming Language exercises

Source: Internet
Author: User

1: write a program to determine the value range of the char short long int defined by signed and unsigned respectively. You can print the corresponding values in the standard header file and calculate them directly.

Header file implementation:

#include <stdio.h>#include <limits.h>/*determin range of int types*/int main(){  /*signed*/  printf("signed char min = %d\n",SCHAR_MIN);  printf("signed char max = %d\n",SCHAR_MAX);    printf("signed short min = %d\n",SHRT_MIN);  printf("signed short max = %d\n",SHRT_MAX);    printf("signed int min = %d\n",INT_MIN);  printf("signed int max = %d\n",INT_MAX);    printf("signed long min = %ld\n",LONG_MIN);  printf("signed long max = %ld\n",LONG_MAX);    /*unsigned*/  printf("signed char max=%u\n",UCHAR_MAX);  printf("signed short max = %u\n",USHRT_MAX);    printf("signed int max = %u\n",UINT_MAX);    printf("signed long max = %lu\n",ULONG_MAX);    getchar();      return 0;}

Direct computing:

# Include <stdio. h> /*~ 0 returns all digits to 1 (unsigned char )~ 0 to unsigned char )~ 0> 1 shift one digit to the right to clear the sign (char) (unsigned char )~ 0> 1 convert to char type */INT main () {/* singed */printf ("min of singed char = % d \ n",-(char) (unsigned char )~ 0> 1); printf ("max of singed char = % d \ n", (char) (unsigned char )~ 0> 1); printf ("min of singed short = % d \ n",-(short) (unsigned short )~ 0> 1); printf ("max of singed short = % d \ n", (short) (unsigned short )~ 0> 1); printf ("min of singed Int = % LD \ n",-(INT) (INT long )~ 0> 1); printf ("max of singed Int = % LD \ n", (INT) (INT long )~ 0> 1); printf ("min of singed long = % LD \ n",-(long) (unsigned long )~ 0> 1); printf ("max of singed long = % LD \ n", (long) (unsigned long )~ 0> 1);/* unsigned */printf ("max of singed char = % u \ n", (unsigned char )~ 0); printf ("max of singed char = % u \ n", (unsigned short )~ 0); printf ("max of singed char = % u \ n", (unsigned INT )~ 0); printf ("max of singed char = % lu \ n", (unsigned long )~ 0); getchar (); Return 0 ;}

 

 

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.