GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Tech FAQs  >  Concepts

 Print  |  
Question:  Take this example:

#include

int main ()
{
int a [5];
a [3] = 1111;

printf ("3[a] = %dn", 3[a]);

return 0;
}

You notice that I use 3[a] instead of a[3], however, this code works fine but I don't know how.
It will be grateful if someone explians to me why and how this code works fine.
Thanks.




January 01, 2007 23:52:10 #3
 Bhushan   Member Since: Visitor    Total Comments: N/A 

RE: Take this example:#include
 

regarding that printf statement.......... a[3] is internally calculated by compiler as (a+3). so 3[a] will be calculated

as (3+a) . and these two statements calculates the same value and this is the reason why that code works.  (Name of array itself acts as starting address of the array.)

     

 

Back To Question