using namespace std;
void getdata (int a, int size);
int main ()
getdata (a, size);
void getdata (int a, int size)
for (int i=0; i<size; i++)
Also, please provide the purpose of this program. I assume you want your function to populate the array. Sure, this may happen in the function, but you aren't returning the edited variable nor are you passing it by reference.
It's pretty obvious that the purpose is to populate an array from a function.
but you aren't returning the edited variable nor are you passing it by reference.
Arrays are passed by simulated reference (ie. by pointer), so there's nothing wrong there. The two issues are thus:
Semantic error: size is not a compile-time constant, and C++ doesn't allow array sizes that are not compile-time constants.
Syntax error: The subscript operator is not used when passing an array to a function, just the array name.
The corrections are simple and obvious, provided the OP doesn't want a dynamically sized array:
using namespace std;
void getdata(int a, int size);
const int size = 10;
void getdata(int a, int size)
for (int i = 0; i < size; i++)
cin >> a[i];
You might say that failing to use the populated array is an error as well, since the only way to confirm the code works is by stepping through it in a debugger.
Hi, as I was told that my code doesn’t scale well at all, I thought perhaps I’d try to get a better understanding of interfaces/abstract classes and classes and the relationship between them.
I don’t want at this stage work on a big separate project as I've already got plenty ...
Hey, so I wanna ask how I need to create a method who will remove word if in that word is 2 same chars. Example: "Potato" in this word there is a 2 "o" chars so this word will need to be removed. "Forum" in this word there is no ...
Hi I'm having a problem implementing a mini shopping cart drop down in the header to show the user all the products they have in their shopping cart. It seems the only solution for this is Ajax, and I've looked all over and can't find anything that I could possibly ...