| | |
compile error
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2006
Posts: 15
Reputation:
Solved Threads: 0
Hi,
Can someone tell me how to fix the function below. I am getting this compile error regarding the last line:
cannot convert `const double' to `const double*' in return
What should I return according to the function parameters I've written?
Thanks.
Can someone tell me how to fix the function below. I am getting this compile error regarding the last line:
cannot convert `const double' to `const double*' in return
What should I return according to the function parameters I've written?
Thanks.
C Syntax (Toggle Plain Text)
const double * maximum(const double a[], int size) { if (size == 0) return NULL; const double *highest = a; for (int i = 0; i < size; i++) if (a[i] > *highest) { *highest == a[i]; } return *highest;
Last edited by Dave Sinkula; May 9th, 2006 at 10:11 pm.
hi
There are two things first
this line says highest is a pointer to a costant means u cant change the content highest is pointing to, next
removing that if u do it like
u will be trying to change a contant, which is illegal.
better if u write
There are two things first
C Syntax (Toggle Plain Text)
const double *highest = a;
C Syntax (Toggle Plain Text)
if (a[i] > *highest) { *highest == a[i]; // "==" ?? }
C Syntax (Toggle Plain Text)
if (a[i] > *highest) { *highest = a[i]; }
better if u write
C Syntax (Toggle Plain Text)
const double * maximum(const double a[], int size) { if (size == 0) return NULL; double *highest = (double*)a; for (int i = 0; i < size; i++) if (a[i] > *highest) { *highest = a[i]; } return highest; }
![]() |
Similar Threads
- visual c++ strange compile error... (C++)
- compile error (C++)
- C++ Compile Error's (C++)
- Out of Error Compile error (Visual Basic 4 / 5 / 6)
- compile error (C++)
- PLEASE help with project - compile error (C++)
Other Threads in the C Forum
- Previous Thread: Translating from Matlab to C
- Next Thread: 1-D array
Views: 1115 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays asterisks binarysearch calculate changingto char character cm command copyimagefile creafecopyofanytypeoffileinc database directory dynamic execv feet fgets file floatingpointvalidation fork forloop framework function functions getlogicaldrivestrin givemetehcodez grade graphics gtkwinlinux hacking histogram homework ide include incrementoperators input intmain() iso kernel keyboard kilometer km lazy license linked linkedlist linux list lists looping loopinsideloop. lowest matrix microsoft mqqueue number oddnumber odf openwebfoundation overwrite owf pause pdf performance pointer posix probleminc process program programming radix recursion recv recvblocked research reversing scripting segmentationfault sequential single socket socketprogramming spoonfeeding standard string student systemcall testing threads turboc unix urboc user variable whythiscodecausesegmentationfault windowsapi






