Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I handle a Matrix in C ? 2

Status
Not open for further replies.

Oxidized

Programmer
Nov 20, 2000
8
KR
Hello, I'm a Pascal programmer, trying to make my way into
the C++ world.
I've been trying to pass a local matrix (bidimensional
array) to a function, but I could'nt.
It's suposed to be a very simple thing, but I've tried everything I still can't.
I know that I have to make a pointer to pass it by address,
that worked.
But inside the function I can't access the matrix like if
it where a matrix, I mean, something like that :

matrix[2][3]=2; (for example).

Is there any way to do that ?

Thatnx in advance.
 
The way to do it as follow:

const int col = 2;
...
void Example(int my_array[col][], int Size)
{
for (int q = 0;q < (Size / col);q ++)
for (int w = 0;w < (Size / col);w ++)
my_array[q][w] = 2;
}

// In this function you will assign 2 to all elements of the array.

// Function call

Example(my_array,(SizeOf(my_array) / SizeOf(int)));

Best Regards,

aphrodita@mail.krovatka.ru {uiuc rules}
 
Also, arrays are passed by reference, they are not copied. I don't know what you're used to, but this can be important. If you modify something, it's not a copy! Be careful about this.

MWB>

Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top