Strange Result on Struct

Write here if you have problems with your C source code

Moderator: Board moderators

Post Reply
User avatar
Roby
Experienced poster
Posts: 101
Joined: Wed May 04, 2005 4:33 pm
Location: Tangerang, Banten, Indonesia
Contact:

Strange Result on Struct

Post by Roby » Fri Aug 18, 2006 7:50 am

My friend of mine ask me about this code and I was unable to answer it why. Here's the code:

Code: Select all

#include<stdio.h>

struct da{
int a;
short b;
}asd;

void main(){
printf("%d",sizeof(asd));
}
It supposed to be 6 bytes, didn't it? But when my friend compiled it with GCC and VC++ 6, he got 8 bytes? Why?

Thanx in advance :)

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post by mf » Fri Aug 18, 2006 7:52 am

This question was asked just three days ago here.
http://online-judge.uva.es/board/viewtopic.php?t=11577

Post Reply

Return to “C”