473,406 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

c 2d array to pointer

Hi!

I have the following function declaration:

"void store(int** ppi)"

But the element to store is an array of type:

"int array[10][10]"

How can I cast it to an int** ?
Dec 29 '11 #1
1 1619
weaknessforcats
9,208 Expert Mod 8TB
The basic problem is that your array is 10 elements where each element is an array of 10 int.

Therefore, the name "array" is the address of element 0. Elemet 0 is an array of 10 int.

Therefore, the name "array" must be passed to a pointer to an array of 10 int. That is, a (*pp1)[10]. Calling the address of an array of 10 int an int** is a design error.

Eiither change the function arguement to be a pointer to an array of 10 int, or change the argument to an int* and pass in
&array[0][0].

In any case, when an array s passed t a function all that's passed is the address. The number of elements is lost. So you will need additional arguments for the array dimensions.

Read this: http://bytes.com/topic/c/insights/77...rrays-revealed
Dec 29 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Fabian Wauthier | last post by:
Hi list, I am trying to dynamically grow a 2 dimensional array (Atom ***Screen) of pointers to a struct Atom (i.e. the head of a linked list). I am not sure if this is the right way to do it: ...
4
by: Kobu | last post by:
I've read the FAQ and several posts on multidimensional arrays and how their names decay to pointer to arrays (not pointer to pointers). If this is so, why does the following code fragment...
3
by: Kenny | last post by:
Will is affect the result if I pass Array Pointer as a parameter to a function compare to Array as a parameter? For example, BYTE buffer a.) function(&buffer) b.) function(buffer) Is it any...
5
by: s88 | last post by:
Howdy: the follows is my program, I wanna change my structure array pointer in the function "testfunc", but I fail..., I also try to call the testfunc by reference, but the compiler says...
7
by: André Hänsel | last post by:
Hi! This: function foo() { $a = array('a' => 'b', 'c' => 'd'); return array_keys($a); } while ($a = each(foo()))
6
by: c19h28o2 | last post by:
Hi, I'm learning to use pointers with multidemensional arrays so please bear with me! Here is the problem which is from c primer plus Ch10 Programming excercise 1 Modify the rain program...
12
by: howa | last post by:
// example #include <iostream> using namespace std; size_t bsearch(int *a) { cout<<a<<endl; cout<<sizeof(a) / sizeof(a)<<endl;
5
by: Kiran | last post by:
Hi all, another newbie question from me, but here goes. Ok, I have a double array defined as follows: int cluster; now, i know that if you say for example cluster, this will give me the...
3
by: Peter Oliphant | last post by:
Below are the definitions of two classes. VList creates two static integer arrays (v_0, v_1), creates an array of pointers to these arrays (vlist), and has a public method to return a pointer to...
26
by: =?iso-8859-1?q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
Do you think we can reach any kind of consensus on whether the following code's behaviour is undefined by the Standard? int my_array; int const *const pend = *(&my_array + 1); Considering...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.