Thread: int data type past 32767 in program no error received (program runs)

  1. #1
    Registered User
    Join Date
    Feb 2018
    San Diego, CA

    int data type past 32767 in program no error received (program runs)

    Hey all, i'm working on a programming question from a website. The question requires me to use a Fibonacci sequence whose values do not exceed four million. My question, to prepare me for the Fibonacci problem, data types:

    int signed -32,76 - +32,767
    unsigned long 0 - 4,294,967,295

    I wrote a quick program, below, with values of int outside of the specified range (-32,767 - +32,767) for int and the program ran & successfully (4000000 was reached). Was wondering what if any error I can expect (any compiler errors initializing a variable that is out of data type size?)

    #include <stdio.h>
    int main (void)
            int limit = 4000000;
            int i = 3500000;
            while (i < limit)
                    printf("%d\n", i);
            return 0;

  2. #2
    Registered User
    Join Date
    Dec 2017
    The range of [-32,767, +32,767] for an int is only the minimum range guaranteed by the standard. It would only usually be that limited on a 16-bit system. (And even there the lowest value would be -32,768 for a two's complement machine.)

    Try running this on your system.
    #include <stdio.h>
    #include <limits.h>
    int main() {
        printf("SHRT_MIN:    %20d\n",   SHRT_MIN);
        printf("SHRT_MAX:    %20d\n",   SHRT_MAX);
        printf("USHRT_MAX:   %20u\n",   USHRT_MAX);
        printf("INT_MIN:     %20d\n",   INT_MIN);
        printf("INT_MAX:     %20d\n",   INT_MAX);
        printf("UINT_MAX:    %20u\n",   UINT_MAX);
        printf("LONG_MIN:    %20ld\n",  LONG_MIN);
        printf("LONG_MAX:    %20ld\n",  LONG_MAX);
        printf("ULONG_MAX:   %20lu\n",  ULONG_MAX);
        printf("LLONG_MIN:   %20lld\n", LLONG_MIN);
        printf("LLONG_MAX:   %20lld\n", LLONG_MAX);
        printf("ULLONG_MAX:  %20llu\n", ULLONG_MAX);
        return 0;
    I get:
    SHRT_MIN:                  -32768
    SHRT_MAX:                   32767
    USHRT_MAX:                  65535
    INT_MIN:              -2147483648
    INT_MAX:               2147483647
    UINT_MAX:              4294967295
    LONG_MIN:    -9223372036854775808
    LONG_MAX:     9223372036854775807
    ULONG_MAX:   18446744073709551615
    LLONG_MIN:   -9223372036854775808
    LLONG_MAX:    9223372036854775807
    ULLONG_MAX:  18446744073709551615
    Last edited by john.c; 01-25-2020 at 05:20 PM.
    The best argument against democracy is a five minute conversation with the average voter. - Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 24
    Last Post: 02-09-2011, 09:19 AM
  2. which data type in image program?
    By TriKri in forum C++ Programming
    Replies: 13
    Last Post: 06-14-2008, 04:17 PM
  3. Error when my program runs
    By Just4Learning in forum C++ Programming
    Replies: 3
    Last Post: 05-22-2007, 07:20 PM
  4. Get an Error as soon as the program runs.
    By sara.stanley in forum C++ Programming
    Replies: 5
    Last Post: 05-28-2006, 11:47 PM
  5. How to use Long Data type in Pro*C program.
    By anwar_pat in forum C Programming
    Replies: 1
    Last Post: 05-16-2006, 03:00 AM

Tags for this Thread