Thread: sizeof(struct) gives different values

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    25

    sizeof(struct) gives different values

    I have few structures, & I get different values for each structure's sizeof() operator in a 32-bit processor

    Code:
    struct test1{
    int i;
    int j;
    char c;
    }
    
    sizeof(struct test1) = 12 
    
    struct test2{
    char c;
    }
    
    sizeof(struct test2) = 1
    
    
    struct test3{
    char c[5];
    }
    
    sizeof(struct test3) = 5
    why it doesn't give 4 bytes for test2 & 8 bytes for test3?

    thanks
    onebrother

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,662
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    25
    thanks for your reply...

    is there any good link on C tricky questions?

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by onebrother View Post
    thanks for your reply...

    is there any good link on C tricky questions?
    This is one:
    C Board - Search Forums

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DHCP Discover
    By Xandux in forum C Programming
    Replies: 4
    Last Post: 03-06-2010, 12:41 AM
  2. scanf return values
    By pirog in forum C Programming
    Replies: 15
    Last Post: 09-13-2009, 03:58 AM
  3. Need help with project
    By chrisa777 in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2006, 05:01 PM
  4. ascii values for keys
    By acid45 in forum C Programming
    Replies: 2
    Last Post: 05-12-2003, 07:13 AM
  5. Checking ascii values of char input
    By yank in forum C Programming
    Replies: 2
    Last Post: 04-29-2003, 07:49 AM