Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: Passing Two-Dimensional Array as a Function Parameter

Reply
Thread Tools

Re: Passing Two-Dimensional Array as a Function Parameter

 
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      10-01-2010
Jason S wrote:

> I'm working on a program and have encountered a bit of an issue with
> getting my program to work correctly. When I print the array in main(),
> the values print out correctly. But when I debug the program to print
> out their values in the calculatesquares(int[][], int. int) function,
> they come out as very large integers. I assume they might be memory
> addresses? Here's the code:

[...]
> int calculatesquares(int squares[][5], int r, int c)
> {
> int valsAcross[5];
> int valsDown[5];
> int valsDiag[2];

[...]

Just a quick guess, but that looks like uninitialized memory. Could you try:

int valsAcross [5] = {0,0,0,0,0};
...


Best

Kai-Uwe Bux
 
Reply With Quote
 
 
 
 
Juha Nieminen
Guest
Posts: n/a
 
      10-03-2010
Pete Becker <> wrote:
>> int valsAcross [5] = {0,0,0,0,0};

>
> Or, if you don't like counting all those zeros,
>
> int valsAcross[5] = { 0 };


I think this will work too:

int valsAcross[5] = { };
 
Reply With Quote
 
 
 
 
Luc Danton
Guest
Posts: n/a
 
      10-03-2010
On 03/10/2010 15:42, Pete Becker wrote:
> On 2010-10-03 03:31:50 -0400, Juha Nieminen said:
>
>> Pete Becker <> wrote:
>>>> int valsAcross [5] = {0,0,0,0,0};
>>>
>>> Or, if you don't like counting all those zeros,
>>>
>>> int valsAcross[5] = { 0 };

>>
>> I think this will work too:
>>
>> int valsAcross[5] = { };

>
> Maybe. But mine is much clearer. <g>
>


Do you find:

template<typename T>
T make()
{
return T();
}

unclear ?
What is the result of make<int>() ?

What about:

template<typename T>
T*
make()
{
return new T[10]();
}

?
What is make<int>()[0] ?

To me
int valsAcross[5] = {};
is just as clear as
int valsAcross[5] = { 0 };

Then again I've seen presentations/read things about C++0x and
value-initialization.
 
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
Re: Passing Two-Dimensional Array as a Function Parameter Luc Danton C++ 2 10-03-2010 11:46 PM
Passing parameter to function not expecting parameter Mister B C Programming 8 08-26-2010 08:01 AM
How to pass a parameter for a function parameter in a function AzamSharp Javascript 2 07-05-2008 12:24 AM
creating multidimensional array at runtime and passing it as parameter to a function nitinm C Programming 2 09-14-2007 09:30 PM
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
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57