The * in a function.

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2007
Posts: 15
Reputation: warpstar is an unknown quantity at this point 
Solved Threads: 0
warpstar warpstar is offline Offline
Newbie Poster

The * in a function.

 
0
  #1
Oct 26th, 2007
The Function

double *solve( double a[ ][N], double b[ ])

what does the pointer notation * represent in front of solve?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,672
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1502
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: The * in a function.

 
0
  #2
Oct 26th, 2007
It means the function is going to return a pointer to a double variable or possibly a pointer to an array of doubles. The * means a pointer.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,055
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: The * in a function.

 
3
  #3
Oct 26th, 2007
Read it as if the * sticks to the type name, not the function name.
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: The * in a function.

 
1
  #4
Oct 27th, 2007
Pointer syntax in C/C++ is very flexible, but likewise very confusing. You can say something like
int i, *pi, **ppi;
but this should be read carefully as
int i;
int* pi;
int** ppi;

:an integer, a pointer to an integer, and a pointer to a pointer to an integer. Yeah, I know... read it again anyway... (I attached the "*" to the int because it is part of the type of each variable, but it could be anywhere between the base type and the variable name.)

In C, you are forgiven a lot when dealing with the type of things. Hence, as already mentioned, the variable int* pi can be a pointer to a single integer or a pointer to a whole lot of them. Typically, programmers will state their intent by saying either
int *a --pointer to a single int, or
int a[] --pointer to an array of ints.
However, you can't use the [] brackets when declaring a function return type, so you are stuck with the *.

Hope this helps.
Last edited by Duoas; Oct 27th, 2007 at 12:42 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 595 | Replies: 3
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC