Join us at IRC!
Few are those who can see with their own eyes and hear with their own hearts. - Albert Einstein
Wednesday, May 23, 2012
Navigation
Members Online
Total Online: 22
Web Spiders: 14
Guests Online: 22
Members Online: 0

Registered Members: 70170
Newest Member: bahmx
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

C++ Function call help

ghostraider100
Member



Posts: 53
Location: Place were peacemaker(Gandhi) was born
Joined: 01.08.10
Rank:
Elite
Posted on 13-02-11 06:11
How to call a function which consist of an array?
For example if i write a function like

int matrix(int a[3][3])


how can i call this function in my main() program? I use Turbo c++ ver 5.0, it pops out with an error

cannot convert (int , ) to (*)

please post ur solutions.
Author

RE: C++ Function call help

COM
Banned



Posts: 800
Location:
Joined: 31.08.07
Rank:
God
Posted on 13-02-11 06:48
I'm going to take a guess here and say that you tried calling the function in a manner such as this:
matrix(arr[3][3]);

rather than this:
matrix(arr);



K'aem'nhi kh'rn, K'aem'nhi kh'r, K'aem'nhi kh'rmnu.
I'a Y'gs-Othoth!
Author

RE: C++ Function call help

ghostraider100
Member



Posts: 53
Location: Place were peacemaker(Gandhi) was born
Joined: 01.08.10
Rank:
Elite
Posted on 13-02-11 11:37
Some other suggestion plz. I'm not satisfied with this reply...
Author

RE: C++ Function call help

COM
Banned



Posts: 800
Location:
Joined: 31.08.07
Rank:
God
Posted on 13-02-11 12:45
ghostraider100 wrote:
Some other suggestion plz. I'm not satisfied with this reply...

Huh, what? Oh shite, I'm sorry, I did not realise that I was addressing his majesty, the grand emperor of the golden city himself. Let me change my previous reply to a more appropriate one. What I meant to say was naturally:

I'm going to take a guess here and say that you tried calling the function in a manner such as this:
matrix(arr[3][3]);

rather than going and fucking yourself in your own grave.

I sincerely hope that this little oversight on my part can be forgiven.

With deepest respect, your loyal subject, COM.


K'aem'nhi kh'rn, K'aem'nhi kh'r, K'aem'nhi kh'rmnu.
I'a Y'gs-Othoth!
Author

RE: C++ Function call help

GTADarkDude
Member



Posts: 142
Location: The Netherlands
Joined: 23.02.08
Rank:
God
Posted on 13-02-11 13:40
We're not here to satisfy you, you're here to get our help, remember that.

Especially when Google could have answered your question in a few seconds: http://cplusplus.com/doc/tutorial/arrays/

Anyhow:

#include <iostream>

const int SIZE = 3;

int matrix(int arr[][SIZE])
{
//do something
return 0; //return something
}

int main()
{
int arr[SIZE][SIZE] = {{1,2,3},{4,5,6},{7,8,9}};
cout << "And the result is... " << matrix(arr) << "!\n";
return 0;
}



...
- - - -
Author

RE: C++ Function call help

korg
Admin from hell



Posts: 1704
Location: ENDING YOUR ONLINE EXPERIENCE!
Joined: 01.01.06
Rank:
The Master
Posted on 13-02-11 15:38
ghostraider100 wrote:
Some other suggestion plz. I'm not satisfied with this reply...


Stopped reading just about there.



I deal in pain, All life I drain, I dominate, I seal your fate.


Author

RE: C++ Function call help

j4m32
Member

Posts: 81
Location:
Joined: 01.05.10
Rank:
God
Posted on 13-02-11 16:40
Since you didn't really give us much to work with, we have to infer how you are using your function.

Sometimes it's better to provide a more informative snippet with the function definition.

1. Learn the difference between passing by reference and passing by value and you might that the answer given here is exactly the same as what COM said.

2. It's clear you have no idea about addressing, it is pretty key in low level programming as well as C/C++.

You can use as COM said, just the variable name since C/C++ will automatically take the reference:


matrix(arr);


it knows that it's expecting a pointer from the function definition (according to your error).

OR you can explicitly tell to pass the reference to the very first element in the array:


matrix(&arr[0][0]);


Both "notations" are EXACTLY the same in terms of their addresses,
since the address of "arr" is exactly the same as the first element/item in the array: arr[0][0]

Hope this clears things up, next time don't just dismiss what someone has said.

Jim,
Author

RE: Sorry guys

ghostraider100
Member



Posts: 53
Location: Place were peacemaker(Gandhi) was born
Joined: 01.08.10
Rank:
Elite
Posted on 16-02-11 06:04
I'm extremely sorry which i wrote here esp. com
Author

RE: C++ Function call help

Arabian
Member



Posts: 320
Location: inside you.
Joined: 22.09.10
Rank:
God
Posted on 16-02-11 06:45
ghostraider100 wrote:
Some other suggestion plz. I'm not satisfied with this reply...



Gold. Pure, comedic gold.


Hare Lambda!

Guest
Username

Password

Remember Me


Bookmark This Page
Affiliates
Adverts

 

 

Links
By using, viewing or obtaining any information contained on this site, you agree to the disclaimer.

© HellBound Hackers 2008- 2009. Since 3rd December 2004.