Thread: Int data type size

  1. #1
    n00b
    Join Date
    Feb 2005
    Location
    United Kingd00m
    Posts
    5

    Int data type size

    Very simple solution, I guess, (I am new to C) but when I use this:

    Code:
    #include <stdio.h>
    
    main()
    {
       printf("Size of int data type: %d",  sizeof(int));
       return 0;
    }
    I get 4 - I understand that the size of the int data type should be 2. So my question is... why am I getting 4?

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    The standard only specifies the min size for an int. Your system is free to expand the size as it sees fit. Most of the modern compiler uses 32 bit integers. Since on the majority of systems CHAR_BIT is set to 8, 32 / 8 = 4

  3. #3
    n00b
    Join Date
    Feb 2005
    Location
    United Kingd00m
    Posts
    5
    Ah, thank you, I had assumed that it was the same in every C program.

    Funny, I swear earlier it was 2-byte...

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    It was. It wasn't that long ago that 16 bit integers were the common thing. Some time not too far off, they'll likely be 64 bits.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Replies: 1
    Last Post: 10-27-2006, 01:21 PM
  4. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 05:20 AM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM