Oracle Technical TestWhat will be the output of the following program on GCC compiler?
#include
int main() {
char str[]=`MalayalaM`;
char $\times$ s;
s= str + 8;
while(s>=str){
printf("%c", $\times$ s);
s--;
}
return 0;
}
The address of the 8th character from the base address of the string` is stored in the character pointer `s`.Here, `s` is pointing to the 8th value in the `str` i.e. `M`.
In the start of the loop, since the address at `s` is greater than the address at `str`, the condition evaluates to true. Then printf() prints the value at address at s` i.e. `M` and the value of `s` is decremented which will now point to the 7th value in the `str` i.e. `a`.
In the same way loop is executed and the characters `str` are printed in reverse order. When the address at `s` becomes less than the address at `str`, the loop is terminated. Hence, we get the output "MalayalaM".