c++ - Differences between double *vec and double vec[] -


in our legacy c/c++ code encounter 2 versions of signatures

void foo1(double *vec, int n) 

and

void foo2(double vec[], int n) 

but there no difference in handling of parameter vec inside of methods e.g.:

void foo2(double vec[], int n){     for(int i=0;i<n;i++)       do_something(vec[i]); } 

is there difference between first version (double *) , second (double ..[])? in situations should version preferred on other?

edit: after hint of @khaled.k tried compile:

void foo(double *d, int n){} void foo(double d[], int n){} 

and got compile error due redefinition of void foo(double *d, int n). double *vec , double vec[] mean same.

the still open question version should used when.

here relevant quote k&r 2nd (*), starting @ bottom of page 99:

as formal parameters in function definition,

char s[]; 

and

char *s; 

are equivalent; prefer latter because says more explicity parameter pointer. when array name passed function, function can @ convenience believe has been haded either array or pointer, , manipulate accordingly. can use both notations if seems appropriate , clear.

(*) kernighan & ritchie: "the c programming language" (second edition)


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo