hello,
what will be output of following program on INTEL machine
#include <stdio.h>
void main()
{
union s
{
int i;
char ch[2];
};
union s obj;
obj.i=256;
printf("%d\n",obj.i,"%d",obj.ch[0],"%d",obj.ch[1]);
}
Since you declared main as returning void, rather than the correct
return type of int, it invokes undefined behavior (unless you're using
an implementation that specifically accepts void main()). If you had
been following this newsgroup, or if you had read the FAQ, you would
know that.
Assuming your implementation accepts "void main()", the output on any
system will be the string "256" followed by a newline. If you had
actually tried running the program before posting it, you would know
that as well, though you might not yet understand why. Read your
textbook, or your system's documentation, to understand how the
printf() function works (hint: it takes a single format string).
I suspect you're also assuming that an int is two bytes. It may be,
but it commonly isn't.