What is the output of the following program?
#include <stdion.h>
#include <string.h>
main()
{
static char a[] = “Exforsys”
printf(“%d”, *(a+ strlen(a)));
}
The immediate answer one might give seeing the program would be 8 which is the length of the string “Exforsys”. But the output is not that. The wondering what would be the output. It is 0. Interesting at the same time strange to see the output is it not? The output is so because the strlen() function give the length of the string and in this case gives the length of “Exforsys” which is 8. Now if we see carefully the next statement namely the printf we can find that it is given to print the contents of the value at the 8th address from the base address.
E - Stored in base address a[0]
x - Stored in a[1]
f - Stored in a[2]
o - Stored in a[3]
r - Stored in a[4]
s - Stored in a[5]
y - Stored in a[6]
s - Stored in a[7]
‘
What is the output of the following program? #include <stdion.h> #include <string.h> main() { static char a[] = “Exforsys” printf(“%d”, *(a+ strlen(a))); }
The immediate answer one might give seeing the program would be 8 which is the length of the string “Exforsys”. But the output is not that. The wondering what would be the output. It is 0. Interesting at the same time strange to see the output is it not? The output is so because the strlen() function give the length of the string and in this case gives the length of “Exforsys” which is 8. Now if we see carefully the next statement namely the printf we can find that it is given to print the contents of the value at the 8th address from the base address.