Function syntax

String abc = showData()["Hello"];
can somebody explain what is use of ["Hello"] after function call?

Questions by ak.nextptr   answers by ak.nextptr

Showing Answers 1 - 2 of 2 Answers

C doesn't have a String data type, unless that supposed to be a typedef for something.

Having said that, I think this is taking advantage of the fact that array indexing in C is commutative; IOW, "a[i]" and "i[a]" both evaluate to the ith element of the array a. If "showdata" returns an integral type, it can be used to index into the array expression "hello".

Ive attached a quick-n-dirty example that illustrates this.

Code
  1. #include <stdio.h>

  2. "%c

  3. ", foo()["Hello""%c

  4. ", "Hello"

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions