Broadsoft Interview Question
Solutions ArchitectsCountry: India
Interview Type: In-Person
hey srk,here it goes like this.
unix is a macro in stdio.h with val 1.
\0 is null
&1["\0c%set\012"]
here 12 is discarded as its after null character string ends at null.
&1["\0c%set\0"]
a string constant is internaly replaced by address.
therefore &1["\0c%set\0"]==&*(address+1)
therefore it finaly drops to c%set
samething for (unix)["chak"]=='h'+"trick"-0x67
ascci val 'h'=0x68-0x67=1+"trick"
1+"trick"="rick"
printf("c %s et","rick");
therefore ans: c rick et
The code which I'm writing below is same as the question.
- Hasit Bhatt January 08, 2015printf(&unix["\0c%set\012"],(unix)["chak"]+"Trick"-0x67);
printf(&1["\0c%set\012"],(1)["chak"]+"Trick"-0x67);
printf(&1["\0c%set\012"],(1)["chak"]+"Trick"-0x67);
printf(&1["\0c%set"],("chak")[1]+"Trick"-0x67);
printf("c%set",'h'+"Trick"-0x67);
printf("c%set",1+"Trick");
printf("c%set","rick");
So, ultimately, it prints cricket.