run this code OK. How do I modify it so I don't have to use the t veriable.
Code:int mat[N][N]={{2,4,6,8},{24,8,3,10},{22,1,8,12},20,18,16,14}}; int t, *d; t=mat[0][1]-mat[0][0]; d=&t;
run this code OK. How do I modify it so I don't have to use the t veriable.
Code:int mat[N][N]={{2,4,6,8},{24,8,3,10},{22,1,8,12},20,18,16,14}}; int t, *d; t=mat[0][1]-mat[0][0]; d=&t;
You want the address of a variable, but you don't want this variable? Impossible. Be more specific.Originally Posted by ronenk
Emmanuel Delahaye
"C is a sharp tool"
You can't. t is an integer, which is storing the result of two integers being subtracted. Thus, it give you an integer. If you want a pointer to an integer, you have to have at least one integer to point to. What your code does, in effect is this:
You have to have an integer for your pointer to point at. In short, all pointers must have something to point at.Code:int t, *d; t = 4 - 2; /* make t store something, doesn't matter what */ d = &t; /* make d point to t */
[edit]Curses, foiled again.[/edit]
Quzah.
Hope is the first step on the road to disappointment.
to make myself clearer: what I wanted was somthing like this:
what might replace this type of thing? is there?Code:int mat[N][N]={{2,4,6,8},{24,8,3,10},{22,1,8,12},20,18,16,14}}; int *d; d=mat[0][1]-mat[0][0];
How about instead of saying what you want with really bad code, you say what you want to do in words.
mabey
Code:int *d; d = malloc(sizeof(int)); *d = 4 - 2; /* :) */
Help populate a c/c++ help irc channel
server: irc://irc.efnet.net
channel: #c
>>mat[0][1]-mat[0][0];
That evaluates to an r-value, or basically _a number_, meaning it isn't stored at any particular memory location that you can point at with a pointer. It's like saying:
int* d = &2;
The only solution I can see is something along the lines of what chrismiceli posted, although that is messier and harder to use than the method involving the 'int t;'. In fact, it does pretty much the same thing, except that the variable is allocated on the heap instead of the stack, and d points to the heap-variable which you then have to free() after you're done with it.
Last edited by Hunter2; 08-08-2004 at 04:24 PM.
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
Thank you.
BTW: why can't I find your website? is it down or is it my side problem?
After a long time of hanging I get "Gateway Timeout".
It seems to be down That happens once in a while (very annoying), but it usually goes back up in a day or two. Sorry!
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.