-1

Can anyone help me out, I am not getting how gcc is compiling the below statement and printing its output.:-

printf("%d",7["sunderban"]);
  • Gcc is taking base address of "sunderban" adding 7 to it and printing the decimal equivalent of data at that location,which is for 'a' is 97. – Vagish Jun 06 '14 at 12:10
  • 2
    You are asking about the output of that statement, without stating what this output is, and why it's unexpected to you. Please improve your question. – moooeeeep Jun 06 '14 at 12:12

1 Answers1

0

C allows to access array's elements in two ways (see Accessing arrays by index[array] in C and C++ and the answers) :

int v[5];
// 1)
v[2] = 33;
// 2)
2[v] = 44;

So, what happens in your case is that you access the 8th element of the string, and it is interpret as int by the printf.

Community
  • 1
  • 1
BЈовић
  • 62,405
  • 41
  • 173
  • 273