Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > 2d array call in a function

Reply
Thread Tools

2d array call in a function

 
 
axcytz@gmail.com
Guest
Posts: n/a
 
      10-23-2013
Hi all,

I have a 2d array that I declared as:

int array[3][3] ={{1,2,3},{1,3,5},{3,2,5}};
int InitialArray[3] = {..};
int Result;

I also use this in a function:

int Calculate(int myarray[], int array[][3], int result)
{
for(int i=0; i<3 ;i++)
{
for(int j=0; j<i+1 ;j++)
result += array[myarray[i]][myarray[j]];
}
}

In main, I call it as

Calculate(InitialArray, array, Result);

I get some errors because of the 2d array in function. How should i fix this?

expected primary-expression before ] token
array bound is not an integer constant


Thanks in advance!
 
Reply With Quote
 
 
 
 
Barry Schwarz
Guest
Posts: n/a
 
      10-23-2013
On Tue, 22 Oct 2013 18:15:10 -0700 (PDT), http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

>Hi all,
>
>I have a 2d array that I declared as:
>
>int array[3][3] ={{1,2,3},{1,3,5},{3,2,5}};
>int InitialArray[3] = {..};
>int Result;
>
>I also use this in a function:
>
>int Calculate(int myarray[], int array[][3], int result)
>{
> for(int i=0; i<3 ;i++)
> {
> for(int j=0; j<i+1 ;j++)
> result += array[myarray[i]][myarray[j]];
> }
>}
>
>In main, I call it as
>
>Calculate(InitialArray, array, Result);
>
>I get some errors because of the 2d array in function. How should i fix this?
>
>expected primary-expression before ] token
>array bound is not an integer constant


It would help a whole bunch if you posted your actual code (use cut
and paste, do not retype) and the complete text of the error message.
You might also mention which compiler you are using.

What happens if you put the actual first dimension in the second
parameter?
What happens if you change the second parameter to the equivalent
int(*array)[3]?

--
Remove del for email
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to call function whose function call with arguments is in astring Options grbgooglefan C Programming 4 01-30-2008 05:12 PM
How to call function whose function call with arguments is in astring grbgooglefan C++ 2 01-30-2008 07:18 AM
How to call function whose function call with arguments is in astring Options grbgooglefan C Programming 0 01-30-2008 04:19 AM
defined? for recursive function call v/s defined? for function call stack Alok Ruby 3 04-13-2006 11:53 AM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM



Advertisments