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

new c programmer question

Hi, my name is John and this is my first posting to comp.lang.c. I am
learning C. I am a high school student with interest in programming. I
have a copy of "The C programming language second edition by Brian W
Kernighan and Dennis M Ritchie". I am using gcc version 4.1 on SuSE 9.

Here is my simple question. I want to set a matrix to contain some
values in my program. I want to pass in the matrix array by address in
a function. The compiler is saying:

hello.c:15: warning: assignment from incompatible pointer type

I can see what is wrong but do not have the ability yet to fix it. Here
is the small code where the error is. I would appreciate some advice on
the syntax to use.

Thank you
John

void setupmatrix(int *m[])
{
int x[4][4]=
{
{ 1, 2, 3, 4},
{ 5, 6, 7, 8},
{ 9,10,11,12},
{13,14,15,16}
};
*m=x;
}

Sep 3 '06 #1
14 1891
John Gerrard schrieb:
Hi, my name is John and this is my first posting to comp.lang.c. I am
learning C. I am a high school student with interest in programming. I
have a copy of "The C programming language second edition by Brian W
Kernighan and Dennis M Ritchie". I am using gcc version 4.1 on SuSE 9.
Thank you for provding this background -- this is not strictly
necessary, of course, but helps us with the explanations and
suggestions :-)
You have a good book there, but don't miss the errata:
http://cm.bell-labs.com/cm/cs/cbook/2ediffs.html
Some stuff there is rather subtle but other is not; for example,
use
int main (void)
rather than
main ()
as suggested in your printed version.
Here is my simple question. I want to set a matrix to contain some
values in my program. I want to pass in the matrix array by address in
a function. The compiler is saying:

hello.c:15: warning: assignment from incompatible pointer type

I can see what is wrong but do not have the ability yet to fix it. Here
is the small code where the error is. I would appreciate some advice on
the syntax to use.
Please explain what _you_ think is wrong -- it is possible that
you are mistaken and tried to cure the wrong ill.
It would have been better if you provided a complete, compiling
(but for the warning/error) programme, for the same reason.
void setupmatrix(int *m[])
This is the same as
int **m
Use the latter rather than the former because it is unnecessarily
obscure.
{
int x[4][4]=
{
{ 1, 2, 3, 4},
{ 5, 6, 7, 8},
{ 9,10,11,12},
{13,14,15,16}
};
x is an array with 4 elements of type array with
4 elements of type int with automatic storage duration, i.e.
it lives only from here to the closing brace.
*m=x;
*m is a pointer to int.
&x[0][0] also is a pointer to int.
However, even if you made *m point at the address of x[0][0],
you could not use this address after you returned from the
function -- x does no longer live, so trying to access it
post mortem leads to undefined behaviour, which may be about
anything from your programme crashing, seeming to work, seeming
to work sometimes to having demons flying out your nose.

The question is: What was your aim?
That is, did you want to copy the contents of x?
Then you need not pass an int** but the start address of
either an int array sufficiently large to take the 16 ints
contained in x or an array of arrays with 4 elements of type
int sufficiently large to take at least the 4 "rows" of x.
This makes
void setupmatrix(int *m)
or
void setupmatrix(int (*m)[4])

Or do you want to set some pointer to the start of x? In this
case, you have to make sure that x lives even outside of
setupmatrix() by giving it static storage duration:
static int x[4][4]

In the former two cases, you need to copy the contents of
x to whatever m points to.
int i, j, k;
for (i=0, j=0; j<4; ++j)
for (k=0; k<4; ++k)
m[i++] = x[j][k];
or, in the second case
for (j=0; j<4; ++j)
for (k=0; k<4; ++k)
m[j][k] = x[j][k];
(easier, because m has the same layout as x)
or even using
memcpy(&m[0], &x[0][0], sizeof x);
or
memcpy(&m[0][0], &x[0][0], sizeof x);

The loops are easier to change if m has a different layout
than x, for example if m points to an object with different
number of "columns".
}
Have also a look at the comp.lang.c FAQ at
http://c-faq.com
especially the chapter about arrays and pointers.

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Sep 3 '06 #2
Thanks for taking the time about to write all this Michael. Your notes
just reinforce how much I don't know. I need to digest and understand
fully what you have written (rather than taking the easy option and
just posting more and more questions). I hope to ask more advanced
questions in the months ahead !

Regards
John
Michael Mair wrote:
John Gerrard schrieb:
Hi, my name is John and this is my first posting to comp.lang.c. I am
learning C. I am a high school student with interest in programming. I
have a copy of "The C programming language second edition by Brian W
Kernighan and Dennis M Ritchie". I am using gcc version 4.1 on SuSE 9.

Thank you for provding this background -- this is not strictly
necessary, of course, but helps us with the explanations and
suggestions :-)
You have a good book there, but don't miss the errata:
http://cm.bell-labs.com/cm/cs/cbook/2ediffs.html
Some stuff there is rather subtle but other is not; for example,
use
int main (void)
rather than
main ()
as suggested in your printed version.
Here is my simple question. I want to set a matrix to contain some
values in my program. I want to pass in the matrix array by address in
a function. The compiler is saying:

hello.c:15: warning: assignment from incompatible pointer type

I can see what is wrong but do not have the ability yet to fix it. Here
is the small code where the error is. I would appreciate some advice on
the syntax to use.

Please explain what _you_ think is wrong -- it is possible that
you are mistaken and tried to cure the wrong ill.
It would have been better if you provided a complete, compiling
(but for the warning/error) programme, for the same reason.
void setupmatrix(int *m[])

This is the same as
int **m
Use the latter rather than the former because it is unnecessarily
obscure.
{
int x[4][4]=
{
{ 1, 2, 3, 4},
{ 5, 6, 7, 8},
{ 9,10,11,12},
{13,14,15,16}
};

x is an array with 4 elements of type array with
4 elements of type int with automatic storage duration, i.e.
it lives only from here to the closing brace.
*m=x;

*m is a pointer to int.
&x[0][0] also is a pointer to int.
However, even if you made *m point at the address of x[0][0],
you could not use this address after you returned from the
function -- x does no longer live, so trying to access it
post mortem leads to undefined behaviour, which may be about
anything from your programme crashing, seeming to work, seeming
to work sometimes to having demons flying out your nose.

The question is: What was your aim?
That is, did you want to copy the contents of x?
Then you need not pass an int** but the start address of
either an int array sufficiently large to take the 16 ints
contained in x or an array of arrays with 4 elements of type
int sufficiently large to take at least the 4 "rows" of x.
This makes
void setupmatrix(int *m)
or
void setupmatrix(int (*m)[4])

Or do you want to set some pointer to the start of x? In this
case, you have to make sure that x lives even outside of
setupmatrix() by giving it static storage duration:
static int x[4][4]

In the former two cases, you need to copy the contents of
x to whatever m points to.
int i, j, k;
for (i=0, j=0; j<4; ++j)
for (k=0; k<4; ++k)
m[i++] = x[j][k];
or, in the second case
for (j=0; j<4; ++j)
for (k=0; k<4; ++k)
m[j][k] = x[j][k];
(easier, because m has the same layout as x)
or even using
memcpy(&m[0], &x[0][0], sizeof x);
or
memcpy(&m[0][0], &x[0][0], sizeof x);

The loops are easier to change if m has a different layout
than x, for example if m points to an object with different
number of "columns".
}

Have also a look at the comp.lang.c FAQ at
http://c-faq.com
especially the chapter about arrays and pointers.

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Sep 3 '06 #3
John Gerrard wrote:
Hi, my name is John and this is my first posting to comp.lang.c.
Welcome to the group.
I am
learning C. I am a high school student with interest in programming. I
have a copy of "The C programming language second edition by Brian W
Kernighan and Dennis M Ritchie". I am using gcc version 4.1 on SuSE 9.
The compiler and OS are not relevant to your problem, which is good
since we don't deal with compiler/OS specific issues here. If you don't
know whether something is compiler/OS specific then we will be happy to
tell you and try to point you in the correct direction.
Here is my simple question. I want to set a matrix to contain some
values in my program. I want to pass in the matrix array by address in
a function. The compiler is saying:

hello.c:15: warning: assignment from incompatible pointer type
You are correct to be concerned by that warning since it shows a serious
problem. You have others the compiler is not currently warning about.

<OT>
I suggest compiling with
gcc -ansi -pedantic -Wall -O
</OT>
I can see what is wrong but do not have the ability yet to fix it. Here
is the small code where the error is. I would appreciate some advice on
the syntax to use.

Thank you
John

void setupmatrix(int *m[])
{
int x[4][4]=
{
{ 1, 2, 3, 4},
{ 5, 6, 7, 8},
{ 9,10,11,12},
{13,14,15,16}
};
*m=x;
}
OK, now for your problems.

Firstly x is a local variable that will cease to exist as soon as the
function returns and what your code attempts to do is make a pointer to
it available outside the function.

Secondly, [] in a parameter list means pointer not array. I.e.
void foo(int i[])
means *exactly* the same as
void food(int *i)

So, in your case:
void setupmatrix(int *m[])
actually means:
void setupmatrix(int **m)
Now, if you think about it carefully, you will realise that a 2
dimensional array is fundamentally different to a pointer to a pointer.
If you don't believe me go out and get too pointers (sticks will do) and
point one at something, then point one at a piece of paper with the
number 5 written on it, then point the other pointer at the first one.
Then, on a second piece of paper draw out a grid (2 dimensional array)
and put some numbers in it. Then compare the two. You will see that the
pointer to a pointer is very different from the grid (2 dimensional array).

Then we have how I'm guessing you want to use the function. I'm guessing
you have something like:

int main(void)
int arr[4][4];
setupmatrix(arr);
return 0;
}

It would have been useful if you had provided sample usage, then I would
not have to guess.

If I am correct then you also need to understand that you cannot assign
to an array, only to elements of an array.

I suggest you go to the comp.lang.c FAQ available at http://c-faq.com/
and start off by reading section 6. Questions 6.2, 6.3, 6.4, 6.4b, 6.5,
6.6... actually, most of section 6 is relevant to things I think you
have miss-understood!

Also question 7.5a and 7.9 (since I think you have misunderstanding
there as well).

Once you have read these give it another go and post your attempt,
including a sample main function that calls it, and we will analyse it
and tell you about any problems.
--
Flash Gordon
Sep 3 '06 #4
Michael Mair wrote:
In the former two cases, you need to copy the contents of
x to whatever m points to.
int i, j, k;
for (i=0, j=0; j<4; ++j)
for (k=0; k<4; ++k)
m[i++] = x[j][k];
or, in the second case
for (j=0; j<4; ++j)
for (k=0; k<4; ++k)
m[j][k] = x[j][k];
(easier, because m has the same layout as x)
or even using
memcpy(&m[0], &x[0][0], sizeof x);
or
memcpy(&m[0][0], &x[0][0], sizeof x);

The loops are easier to change if m has a different layout
than x, for example if m points to an object with different
number of "columns".
or, rather than writing loops like that, you can define your
matrix as a struct, and have the compiler do the nasty job:

---
struct matrix { int e[4][4]; };

void
setupmatrix(struct matrix *m)
{
struct matrix x = {
{
{ 1, 2, 3, 4},
{ 5, 6, 7, 8},
{ 9,10,11,12},
{13,14,15,16}
}
};
*m=x;
}

int
main(void)
{
struct matrix m, n;
setupmatrix(&m);
n = m;
m.e[2][2] = 177;
/* .. etc .. */
return 0;
}

Sep 3 '06 #5
Okay thank you for your prompt replies everyone. I had forgotton how
painfully flow learning a new language can be (and humbleing).

I am now compiling my code with

gcc hello.c -ansi -std=c99 -pedantic -Wall -o hello

I have modified the code. It now compiles compiles but gives this
output at runtime.

jad@dhome2:~/matrix$ ./hello
setupmatrix
exit setupmatrix
printmatrix

Segmentation fault
jad@dhome2:~/matrix$
jad@dhome2:~/matrix$
I have included the COMPLETE program at the end of the posting. It
doesn't work but it does represent what I am trying to do. I sort of
know what is wrong but don't have the understanding to correct it yet.
This is what I want to do: 1) allocate memory for a n*n 2D array, 2)
fill it with numbers, 3) print it out, 4) and free up the memory at the
end of it all. I want to allocate the array size at runtime as I will
be, next month at this rate, be multiplying 2-3 matrices together.
Although I would like to say I don't want you to do this for me, I'm
really hoping you don't take that too seriously because I need
something working to see where I should be going.

Thank you all for your help in advance.
John

#include <stdio.h>
#include <stdlib.h>

/*setup a n*n matrix and fill it with 1, 2, 3, 4*/
/*==============================================*/
int** setupmatrix(int nSize)
{
printf("setupmatrix\r\n");
int nByNArraySize=nSize*nSize*sizeof(int);
int *arr=malloc(nByNArraySize);
for (int i=0;i<nByNArraySize;i++)
arr[i]=0;
printf("exit setupmatrix\r\n");
return (int **)arr;
}

/*print matrix */
/*=============*/
void printmatrix(int **mp,int nSize)
{
printf("printmatrix\r\n");
for (int i=0;i<nSize;i++)
{
printf("\r\n");
for (int j=0;i<nSize;j++)
{
printf("%3d",mp[i][j]);
}
}
printf("exit printmatrix\r\n");
}

/*return memory from matrix */
/*==========================*/
void freematrix(int **mf)
{
printf("freematrix\r\n");
free(mf);
printf("exit freematrix\r\n");
}

int main(void)
{
int ARRSIZE1=4;
int **m1=setupmatrix(ARRSIZE1);
printmatrix(m1,ARRSIZE1);
freematrix(m1);

/*
int ARRSIZE2=3;
int **m2=setupmatrix(ARRSIZE2);
printmatrix(m2,ARRSIZE2);
freematrix(m2)
*/
return 0;
}

Sep 3 '06 #6

Michael Mair wrote:
void setupmatrix(int *m)
or
void setupmatrix(int (*m)[4])
<snip>
static int x[4][4]
<snip>
or even using
memcpy(&m[0], &x[0][0], sizeof x);
or
memcpy(&m[0][0], &x[0][0], sizeof x);
Will the second memcpy fail if the argument to 'void setupmatrix(int
(*m)[4])' is 'int (*m1)[4];'? Because the structures of m and x are
different. The elements in x are stored continuously while the elements
in m are not. And I think it works if the argument is 'int m2[4][4]'.
Am I right?

Sep 3 '06 #7
John Gerrard wrote:
>
Thanks for taking the time about to write all this Michael. Your
notes just reinforce how much I don't know. I need to digest and
understand fully what you have written (rather than taking the
easy option and just posting more and more questions). I hope to
ask more advanced questions in the months ahead !
Now, as a new user, you need to learn to post correctly. Never
top-post. Your reply belongs after (or intermixed with) the
snipped material which you quote. The snipping removes anything
not germane to your reply.

See the following links.

--
Some informative links:
news:news.announce.newusers
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html

Sep 3 '06 #8
"John Gerrard" writes:

< I only address one of your questions here>
Okay thank you for your prompt replies everyone. I had forgotton how
painfully flow learning a new language can be (and humbleing).

I am now compiling my code with

gcc hello.c -ansi -std=c99 -pedantic -Wall -o hello

I have modified the code. It now compiles compiles but gives this
output at runtime.

jad@dhome2:~/matrix$ ./hello
setupmatrix
exit setupmatrix
printmatrix

Segmentation fault
jad@dhome2:~/matrix$
jad@dhome2:~/matrix$
I have included the COMPLETE program at the end of the posting. It
doesn't work but it does represent what I am trying to do. I sort of
know what is wrong but don't have the understanding to correct it yet.
This is what I want to do: 1) allocate memory for a n*n 2D array, 2)
fill it with numbers, 3) print it out, 4) and free up the memory at the
end of it all. I want to allocate the array size at runtime as I will
be, next month at this rate, be multiplying 2-3 matrices together.
Although I would like to say I don't want you to do this for me, I'm
really hoping you don't take that too seriously because I need
something working to see where I should be going.

Thank you all for your help in advance.
John

#include <stdio.h>
#include <stdlib.h>

/*setup a n*n matrix and fill it with 1, 2, 3, 4*/
/*==============================================*/
int** setupmatrix(int nSize)
{
printf("setupmatrix\r\n");
int nByNArraySize=nSize*nSize*sizeof(int);
int *arr=malloc(nByNArraySize);
for (int i=0;i<nByNArraySize;i++)
arr[i]=0;
printf("exit setupmatrix\r\n");
return (int **)arr;
}

/*print matrix */
/*=============*/
void printmatrix(int **mp,int nSize)
{
printf("printmatrix\r\n");
for (int i=0;i<nSize;i++)
{
printf("\r\n");
for (int j=0;i<nSize;j++)
{
printf("%3d",mp[i][j]);
}
}
printf("exit printmatrix\r\n");
}

/*return memory from matrix */
/*==========================*/
void freematrix(int **mf)
{
printf("freematrix\r\n");
free(mf);
printf("exit freematrix\r\n");
}

int main(void)
{
int ARRSIZE1=4;
int **m1=setupmatrix(ARRSIZE1);
printmatrix(m1,ARRSIZE1);
freematrix(m1)
You can only free things you obtained by malloc() or some other allocating
call. m1 is an "auto" (automatic) variable which is freed up automatically
when you exit a function. Since this is in main the end of the function is
also the end of the program.

Look up malloc(), free() and auto.
auto is a "storage class specifier" and if you do not provide one for a
variable, it will implicitly be treated as auto. You should try to defer
your understanding of such specifiers, they tend towards the exotic end of
the spectrum - for example, register is hardly ever used in current
programming practice.
>
/*
int ARRSIZE2=3;
int **m2=setupmatrix(ARRSIZE2);
printmatrix(m2,ARRSIZE2);
freematrix(m2)
*/
return 0;
}

Sep 3 '06 #9
John Gerrard posted:
void setupmatrix(int *m[])
{
int x[4][4]=
{
{ 1, 2, 3, 4},
{ 5, 6, 7, 8},
{ 9,10,11,12},
{13,14,15,16}
};
*m=x;
}

You can't assign one array to another (even if their dimensions are
identical), e.g.:

int arr1[4] = {0};
int arr2[4] = {0};

arr1 = arr2; /* Compiler ERROR */

There are a few ways to write your function; here's an example:

#include <string.h>

void SetupMatrix(int (*const p)[4][4])
{
int const temp[4][4] = {
{ 1, 2, 3, 4},
{ 5, 6, 7, 8},
{ 9,10,11,12},
{13,14,15,16}
};

memcpy(p,&temp,sizeof*p);
}

#include <stdio.h>

int main(void)
{
unsigned i,j;

int matrix[4][4];

SetupMatrix(&matrix);

for(i=0; i!=4; ++i)
{
for(j=0; j!=4; ++j)
{
printf("%d\n",matrix[i][j]);
}
}

system("PAUSE");
}
There are more efficient ways of achieving this.

--

Frederick Gotham
Sep 3 '06 #10
Frederick Gotham posted:
system("PAUSE");

Sorry, I meant to remove that before posting.

--

Frederick Gotham
Sep 3 '06 #11
John Gerrard wrote:
Okay thank you for your prompt replies everyone. I had forgotton how
painfully flow learning a new language can be (and humbleing).

I am now compiling my code with

gcc hello.c -ansi -std=c99 -pedantic -Wall -o hello
<OT>
Add a -O which will allow it to detect some other warnings. In this case
it does not show anything, but sometimes it will.
</OT>
I have modified the code. It now compiles compiles but gives this
output at runtime.

jad@dhome2:~/matrix$ ./hello
setupmatrix
exit setupmatrix
printmatrix

Segmentation fault
<OT>
Since you are using Linux you might want to try valgrind. It can help a
lot with problems like this.
</OT>
jad@dhome2:~/matrix$
jad@dhome2:~/matrix$
I have included the COMPLETE program at the end of the posting.
Thank you. This makes it a lot easier you show you what you are doing wrong.
It
doesn't work but it does represent what I am trying to do. I sort of
know what is wrong but don't have the understanding to correct it yet.
This is what I want to do: 1) allocate memory for a n*n 2D array,
OK, you need to read question 6.16 of the comp.lang.c FAQ at
http://c-faq.com/ since it specifically addresses this problem. It
describes in a lot of detail, including some pictures, three methods of
achieving this.
2)
fill it with numbers, 3) print it out, 4) and free up the memory at the
end of it all. I want to allocate the array size at runtime as I will
be, next month at this rate, be multiplying 2-3 matrices together.
Although I would like to say I don't want you to do this for me, I'm
really hoping you don't take that too seriously because I need
something working to see where I should be going.

Thank you all for your help in advance.
John

#include <stdio.h>
#include <stdlib.h>

/*setup a n*n matrix and fill it with 1, 2, 3, 4*/
/*==============================================*/
int** setupmatrix(int nSize)
{
printf("setupmatrix\r\n");
Why the \r? Doing a \n on its own will take you to the start of the next
line.
int nByNArraySize=nSize*nSize*sizeof(int);
int *arr=malloc(nByNArraySize);
for (int i=0;i<nByNArraySize;i++)
nByNArraySize is the number of *bytes* allocated, *not* how many ints
you have space for. It would be closer (but still not a 2D array) if you
did:
int nByNArraySize=nSize*nSize;
int *arr=malloc(nByNArraySize * sizeof *arr);
for (int i=0;i<nByNArraySize;i++)

Note the way sizeof is being used in the malloc call. No need to specify
the type there, just that it is what arr points to.
arr[i]=0;
printf("exit setupmatrix\r\n");
return (int **)arr;
Any time you are using a cast, your first thought should be that you are
doing something wrong. There are a few occasions where a cast is needed,
but far more situations where it is harmful because it stops the
compiler from telling you that you have an error. In this case you do
have a serious error and the cast just tells the compiler not to point
it out to you.

int** means pointer to pointer. I.e. if you have:
int **arr2d;
Then arr2d[0] is a *pointer* to a row. You have not set this to point
anywhere instead you have written the integer value 0. See the FAQ
question I pointed out for the correct ways to build your int** allocation.
}
<snip>

If you have problems understanding question 6.16 then tell us what you
don't understand and we will try to help you.

I also suggest you rest of section 6 and the other question I pointed
out in my previous post.
--
Flash Gordon.
Sep 3 '06 #12
On Sun, 03 Sep 2006 18:11:30 GMT, Frederick Gotham
<fg*******@SPAM.comwrote:
>John Gerrard posted:
>void setupmatrix(int *m[])
{
int x[4][4]=
{
{ 1, 2, 3, 4},
{ 5, 6, 7, 8},
{ 9,10,11,12},
{13,14,15,16}
};
*m=x;
}


You can't assign one array to another (even if their dimensions are
identical), e.g.:
Since m is an array of pointers (actually it's an int** due the way
arrays are passed to functions), *m is not an array and your
statement, while correct, is not related to this code. *m has type
int* while x in this expression evaluates to type int (*)[4], pointer
to array of four int. The two types are incompatible and there is no
implicit conversion between them. That is the syntax error in the
statement.
Remove del for email
Sep 4 '06 #13
"osmium" <r1********@comcast.netwrites:
[...]
auto is a "storage class specifier" and if you do not provide one for a
variable, it will implicitly be treated as auto.
.... if and only if the variable is declared within a function
definition.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Sep 5 '06 #14
lovecreatesbea...@gmail.com schrieb:
Michael Mair wrote:
> void setupmatrix(int *m)
or
void setupmatrix(int (*m)[4])

<snip>
> static int x[4][4]

<snip>
>>or even using
memcpy(&m[0], &x[0][0], sizeof x);
or
memcpy(&m[0][0], &x[0][0], sizeof x);

Will the second memcpy fail if the argument to 'void setupmatrix(int
(*m)[4])' is 'int (*m1)[4];'? Because the structures of m and x are
different. The elements in x are stored continuously while the elements
in m are not. And I think it works if the argument is 'int m2[4][4]'.
Am I right?
No.
With "int (*m1)[4]", you have a (hopefully valid) pointer to the
first of an yet unknown number of "arrays 4 of int" which are stored
contiguously, i.e. in memory you can expect
|(*m1)[0]|....|(*m1)[3]|(*(m1+1))[0]|....
or
|m1[0][0]|....|m1[0][3]|m1[1][0]|....

What you probably mean is "int **m1" or even an array of pointers
to arrays 4 of int, i.e. "int (**m1)[4]" or "int (*m1[4])[4]".
In these cases, m1[0] (or (*m1[0])) not necessarily points to
the same object as m1[1] (or (*m1[1])).

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Sep 12 '06 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

45
by: Market Mutant | last post by:
I just wonder job selections, job openings and salary level of PHP programer or Perl programmer comparing to Java programmers. Is Java programmer's salary has a minimal of 60K in US? Are there...
14
by: Daniel Chartier | last post by:
Hello. I work in the paper industry and we recently had someone (the original author) from within the company make a program for preventive maintenance. However, it had some bugs and we wanted...
15
by: Randall Smith | last post by:
I've been programming in Python for about 2 years. I think it offers the best combination of simplicity and power of any language I have explored. As I write more and larger and complex programs,...
12
by: Computer Whizz | last post by:
Hiya guys, I saw this (C++ Programmer's Reference by Herbert Schildt) book in the library today, and wondered what the experienced programmer thought about it before I decided to dive in and get...
29
by: jeffc | last post by:
How would you answer a question like this in an interview? I'm not interested in gathering the average of folks on this forum. I'm interested in a strategy for a) evaluating yourself objectively...
5
by: jrefactors | last post by:
when people say unix programmer, does it mean they write programs in unix environment,and those programs are run in unix platform? it is not necessary they are using unix function calls? I heard...
72
by: E. Robert Tisdale | last post by:
What makes a good C/C++ programmer? Would you be surprised if I told you that it has almost nothing to do with your knowledge of C or C++? There isn't much difference in productivity, for...
23
by: Steve Jorgensen | last post by:
Hi all, I'm working on a project through a consulting company, and I'm writing some database code for use in another programmer's project in Excel/VBA. The other programmer is working through...
13
by: BK | last post by:
Our .Net team has just inherited a junior programmer that we need to get up to speed as quickly as possible. Unfortunately, his skill set is largely Access with some VB6 and ASP classic...
65
by: Chris Carlen | last post by:
Hi: From what I've read of OOP, I don't get it. I have also found some articles profoundly critical of OOP. I tend to relate to these articles. However, those articles were no more objective...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.