The following program gives different results when compiled using gcc compiler, and turbo C
#include<stdio.h>
#include<string.h>
void main()
{
char* c = "gatecs2017";
char* p = c;
printf( "%d", (int)strlen( c + 2[p] - 6[p] - 1 ) );
}
Somebody please explain the working of the program. Also why it generates different results?
2[p]does? Do you know anything about pointer arithmetic? What is the result ofc + 2[p]? What is the result ofc + 2[p] - 6[p]? What is the result ofc + 2[p] - 6[p] - 1? Is that result a valid pointer to a valid and terminated string?