Coupon Accepted Successfully!


Question 1

How to write functions which accept two-dimensional arrays when the width is not known before hand?

Try something like

myfunc(&myarray[0][0], NO_OF_ROWS, NO_OF_COLUMNS);

void myfunc(int *array_pointer, int no_of_rows, int no_of_columns)

  // myarray[i][j] is accessed as array_pointer[i * no_of_columns + j] 

Question 2

Is char a[3] = "abc"; legal? What does it mean?

It declares an array of size three, initialized with the three characters 'a', 'b', and 'c', without the usual terminating '\0' character. The array is therefore not a true C string and cannot be used with strcpy, printf %s, etc. But its legal.

Question 3

If a is an array, is a++ valid?


You will get an error like

Error message : Lvalue required in function main.

Doing a++ is asking the compiler to change the base address of the array. This the only thing that the compiler remembers about an array once its declared and it wont allow you to change the base address. If it allows, it would be unable to remember the beginning of the array.

Test Your Skills Now!
Take a Quiz now
Reviewer Name