Go Down

### Topic: Syntax for arrays as operands (Read 606 times)previous topic - next topic

#### kyrpav

##### Mar 20, 2013, 01:37 pm
What is the syntax in order to pass an array that is not predefined in a function as operand?

For example i have this function:

void kilos(int percentage[2],char liquid[2][4]);

So  if i make 2 different arrays(declare and define) and pass them as operands everything work properly.

How can this work if i do not want to make the arrays before the call of the function?
If i have the variables i want to pass and i do not have a and also do not want to make the arrays before i call the function.How can i do it all at once?

Is the only solution to analyze the operands and not use arrays?

#### PaulS

#1
##### Mar 20, 2013, 01:44 pm
Quote
How can this work if i do not want to make the arrays before the call of the function?

It can't. If the function expects an argument, you must pass it one. That means you need to have one to pass it.

#### kyrpav

#2
##### Mar 20, 2013, 01:49 pmLast Edit: Mar 20, 2013, 01:51 pm by kyrpav Reason: 1
this is want i guess. so there is no way that i could declare(this can happen) and initialize the arrays as i call the function inside the parenthesis.Something like:

kilos(int percent[2]={40,60},char liq[2][4]={'wate','milk'})

#### PaulS

#3
##### Mar 20, 2013, 01:55 pm
Quote
so there is no way that i could declare(this can happen) and initialize the arrays as i call the function inside the parenthesis.

No.

#### mistergreen

#4
##### Mar 20, 2013, 03:59 pm
I'm not 100% sure what you're asking but you can write overriding functions with the same name that expect different parameters.

Code: [Select]
`void setup() {  func(1,2);  func();}void loop() {}void func(int a, int b) { // do stuff with a & b}void func() {   // nothing}`

#### PeterH

#5
##### Mar 20, 2013, 04:39 pm

this is want i guess. so there is no way that i could declare(this can happen) and initialize the arrays as i call the function inside the parenthesis.Something like:

No, but you could define a local or global const array containing the values and use that as the argument.
I only provide help via the forum - please do not contact me for private consultancy.

Go Up

Please enter a valid email to subscribe