Array as pointers?

Well , i just read that when we pass an array to a function, then it is treated as a pointer.. n the parameter in function receives the array address as its argument.
So, will it make any difference if i say ...

1
2
3
4
5
void  func(char *r1) ;
void func(char r2[ ]) ;
//in the main function, I pass an array
//char a[]={"Hello"};
func(a);

Here, does it makes a differnce in the first the statements??
should not
@codewalker
Yes, it doesn't. But, which one should be preffered ??
I guess this http://c-faq.com/aryptr/aryptrequiv.html will answer the difference better than me.

Preference wise, I prefer the pointer; can't do ++ on array for one thing. Practically, it depends on the situation; you want to just use it in the function pass const char * (in case of character data and C++ use const std::string& instead). If you already know the size that you want then pass char str[size_of_array]

Usually I will pass char *str instead of char str[]
As a function argument, char *str is identical to char str[], and a can be used inside the same way -- as it is a pointer, not withstanding the [] notation.
@codewalker

If you already know the size that you want then pass char str[size_of_array]

Are you talking about using this as part of a function signture, e.g.

void func(char str[size_of_array]) ;

If you are, then you need to be aware that the value of size_of_array is ignored and str still looks like a char* to the function. It's better to use an empty [], or the pointer form, so the function signature doesn't suggest that the size is passed to the function.

Andy
Topic archived. No new replies allowed.