Given the piece of codeint a[50];int *pa;pa=a;to access the 6th element of the array which of the following is incorrect?a.*(a+5)b.a[5]c.pa[5]d.*(*pa + 5)

A
This question is related to TCS Interview

Showing Answers 1 - 2 of 2 Answers

laxmikanth

  • Feb 10th, 2006
 

correct ans is  pa[5].

after executing the statement pa=a;pa will point to the array a.now array a has 2 pointers which are a and other is pa.we can use subscript operator for pointers also when it points to an array.

so pa[5] will give 6th value in that array.

  Was this answer useful?  Yes

MA

  • May 29th, 2007
 

You did not read the question correctly. Which option is WRONG.

And that is d), since you deference pa before the incrementation, this is likely going to give you an invalid memory access

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