Follow us on Twitter!
Ideas are far more powerful than guns.
Monday, April 21, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 27
Guests Online: 25
Members Online: 2

Registered Members: 82857
Newest Member: varshith_kh
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

C++ Function call help

ghostraider100
Member



Posts: 71
Location:
Joined: 01.08.10
Rank:
Wiseman
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

Code
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


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
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:
Code
matrix(arr[3][3]);



rather than this:
Code
matrix(arr);





Author

RE: C++ Function call help

ghostraider100
Member



Posts: 71
Location:
Joined: 01.08.10
Rank:
Wiseman
Posted on 13-02-11 11:37
Some other suggestion plz. I'm not satisfied with this reply...
Author

RE: C++ Function call help


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
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:
Code
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.


Author

RE: C++ Function call help

GTADarkDude
Member



Posts: 142
Location: The Netherlands
Joined: 23.02.08
Rank:
Newbie
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:
Code

#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: 2798
Location: ENDING YOUR ONLINE EXPERIENCE!
Joined: 01.01.06
Rank:
God
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.


i57.photobucket.com/albums/g215/korg1269/shodan13.jpg

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

RE: C++ Function call help

j4m32
Member

Your avatar

Posts: 81
Location:
Joined: 01.05.10
Rank:
Newbie
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:

Code

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:

Code

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: 71
Location:
Joined: 01.08.10
Rank:
Wiseman
Posted on 16-02-11 06:04
I'm extremely sorry which i wrote here esp. com
Author

RE: C++ Function call help

Arabian
Banned



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



Gold. Pure, comedic gold.


G'bye y'all! I was an asshole, So korg banned me.