Problem with pointers

Saturday, February 23, 2008

Question : Union

Question
main()
{
union a
{
int i;
char ch[2];
};
union a u;
u.ch[0]=3;
u.ch[1]=2;
printf("%d %d %d",u.ch[0],u.ch[1],u.i);

}

o/p is:3 2 515......how??


Solution
Photobucket
unioprob2
unioprob3

Sunday, February 17, 2008

A problem with pointer conversion

Question
int i=300;
char *ptr=&i;
*++ptr=2;
printf("%d",i);

Solution
Photobucket
Photobucket
Photobucket
Photobucket
Photobucket