Thread: Unexpected Output in structure

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    18

    Unexpected Output in structure

    Hi I am getting the strange output when I run the following code:

    Code:
    #include "conio.h"
    
    struct bhagwat
    {
    
    	char name[30];
    
    	int age;
    };
    
    bhagwat a;
    int main(int argc, char* argv[])
    {
    	printf("%d",sizeof(a));
    	getch();
    	return 0;
    }
    
    output::36
    Why this?? instead of 34 .....

    I am using VS6.0 complier for this.....

    And integer in VS tooks 4 byte...so the output should be 34.

    Also when I commented char name[30],the output is 4

    Can anybody explain why this....

    Thanks

    bhagwat

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    http://c-faq.com/struct/endpad.html
    32+4=36
    You've got a whole host of other learning issues, but let's try to address them one at a tmie.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Connecting input iterator to output iterator
    By QuestionC in forum C++ Programming
    Replies: 2
    Last Post: 04-10-2007, 02:18 AM
  2. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  3. C structure within structure problem, need help
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 11-30-2001, 05:48 PM
  4. Simple File Creation Algorithm
    By muffin in forum C Programming
    Replies: 13
    Last Post: 08-24-2001, 03:28 PM