473,387 Members | 1,532 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,387 software developers and data experts.

One and two - dimensional array passing

21
If I have an array int a[10] (just for example) , I can pass the array to a function void myf ( int * x) with the call myf ( a ) . But with the 2-dimensional array int a[10][10] , using myf ( int ** x ) ( or ( int a[][]) with the call myf ( a ) will generate an error (unrelated pointed types , etc..) . Why ?
Sep 18 '07 #1
3 2377
VanKha
21
Please help me . Thanks a lot.
Sep 19 '07 #2
JosAH
11,448 Expert 8TB
Please help me . Thanks a lot.
Note that a two dimensional array is just a one dimensional array where each of
its elements happen to be one dimensional arrays as well.

Similar to passing a one dimensional array 'a', where the parameter 'a' is considered
a pointer to its first element, as in:

Expand|Select|Wrap|Line Numbers
  1. char array[42]; // first element is a char
  2. f(a);
  3. ...
  4. void f(char* a) { ... }
  5.  
so is the two dimensional array considered a pointer to its first element:

Expand|Select|Wrap|Line Numbers
  1. char array[42][54]; // first element is a char[54]
  2. f(a);
  3. ...
  4. void f(char *a[54]) { ... }
  5.  
kind regards,

Jos
Sep 19 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
Not correct:
char array[42][54]; // first element is a char[54]
f(a);
...
void f(char *a[54]) { ... }
This shows the argument to be an array of 54 character pointers. What is needed is a pointer to an array of 54 characters:

Expand|Select|Wrap|Line Numbers
  1. [54]; // first element is a char[54]
  2. f(a);
  3. ...
  4. void f(char (*a)[54]) { ... }
  5.  
Sep 24 '07 #4

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

Similar topics

1
by: seemanta dutta | last post by:
greetings C gurus, I would be grateful if I could know the answers to 2 questions: 1. I want to know how to pass a 2-dimensional array to a function, say foo() and what will be its prototype...
9
by: Luke Wu | last post by:
Hello, I'm having some problems understanding 2 dimensional arrays. My problem relates to the following code: #include <stdio.h> #define M 3 #define N 3
11
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to...
18
by: bsder | last post by:
Hi, Can anyone please tell me how to calculate the size of the following 4-dimensional array, and now to use qsort for sorting on this array? double sp = { 4.0, 5.0, 6.0 }; double spa = { {...
3
by: SQLScott | last post by:
I have looked all over and I cannot find an example or information on passing a multi-dimensional array. Well, that is not true. I found a close example in C++ but it didn't work when I...
4
by: entitledX | last post by:
Hi, I'm trying to use the HDF library to read a few HDF files that I need to process. The data in each file varies in rows, but the columns remain constant. Because of that, I had dynamically...
22
by: spam.noam | last post by:
Hello, I discovered that I needed a small change to the Python grammar. I would like to hear what you think about it. In two lines: Currently, the expression "x" is a syntax error. I suggest...
3
by: ZMan | last post by:
The following code won't compile with gcc version 3.4.2 (mingw-special). How come? Error: cannot convert `char (*)' to `char**' /**********************************************************/...
6
by: hyena | last post by:
Hi, I have a problem regarding passin 2 dimensional array into a function. I have a to pass into function f(), f is called many times and the size of a will change for each call. I am not...
152
by: vippstar | last post by:
The subject might be misleading. Regardless, is this code valid: #include <stdio.h> void f(double *p, size_t size) { while(size--) printf("%f\n", *p++); } int main(void) { double array = { {...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.