| | |
Array question
Thread Solved |
•
•
Join Date: Oct 2008
Posts: 48
Reputation:
Solved Threads: 0
Hello.,
Have a question about array being set from function argument. I wrote this little program, and want to know why cant i set an array size from the function argument. Any help would be greatly appreciated.
---
Andre Granovsky
Have a question about array being set from function argument. I wrote this little program, and want to know why cant i set an array size from the function argument. Any help would be greatly appreciated.
C Syntax (Toggle Plain Text)
int money(int deposit, ...){ int i, sum = 0, nextvar; // myArr[deposit]; // < -- in here i cant set the array size from function receiving argument? and why? va_list parg; va_start(parg, deposit); for(i=0;i<deposit;i++){ nextvar=va_arg(parg, int); // myArr[i]=nextvar; sum+=nextvar; } va_end(parg); return sum/deposit; } int main(void){ printf("%d", money(4,4,4,4,4)); getchar(); return 0; }
---
Andre Granovsky
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
>static arrays are ............
You meant to say "fixed-length" arrays, right?
OP>in here i cant set the array size from function receiving argument? and why?
Because, array size should be a compile time constant, that is: the array size should be known at the compile time. You are already been told what is the solution by Dave.
You meant to say "fixed-length" arrays, right?
OP>in here i cant set the array size from function receiving argument? and why?
Because, array size should be a compile time constant, that is: the array size should be known at the compile time. You are already been told what is the solution by Dave.
Siddhant Sanyam
(Not posting much)
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
(Not posting much)
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
![]() |
Similar Threads
- Little Simple array question :) (C)
- Simple array question (C++)
- Simple char array question (C)
- Newbie Constructor / Array question (C++)
- Array Question (C++)
- C++ Array Question (C++)
- array question (C++)
Other Threads in the C Forum
- Previous Thread: size of a file
- Next Thread: How can i more control rand()
| Thread Tools | Search this Thread |
#include adobe api array arrays asterisks binarysearch calculate char cm copyanyfile copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile createprocess() csyntax database directory dynamic feet fflush fgets file fork forloop frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o include incrementoperators input interest kernel kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix meter microsoft motherboard mqqueue mysql number odf open openwebfoundation owf pattern pdf performance pointer posix probleminc process program programming pyramidusingturboccodes radix read recursion recv repetition research scanf scheduling segmentationfault send sequential shape socket socketprograming stack standard string systemcall turboc unix user voidmain() wab win32api windows.h






