Sunday, 29 September 2013

asterisk on an array in C

asterisk on an array in C

here is a question from a book I have which I don't understand
int ia[] = { 10, 12, 13 };
char ca[] = { 'a', 'b', 'c' };
char st[] = "abc";
If i am not wrong, we have declared arrays of int and chars. But then the
question asked to evaluate a few expression (answers included). I don't
understand the following expressions:
(*ia)+1 => 11
*(ca+2) => c
*(st+3) => \0
I don't understand how this works. Isn't the asterisk using with pointers
to deference them? or declare a pointer variable? What is it doing here?
and how did those answers come to be?
Sorry I am very new to C

No comments:

Post a Comment