int n=0x34
scanf("%d\n"&n);
and
scanf("%d\n"*n); ????
Bill
They're equally incorrect; both are syntax errors.
One of the two statements could be made reasonably correct with a
small change. The other, with an equivalent change, is no longer
a syntax error, but is still incorrect, as your compiler will be
glad to tell you if you take the time to try it.
Something to think about: if the unary "*" and unary "&" didn't do
two very different things, only one of them would need to exist.
--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
My mistake. They're not syntax errors, they're constraint
violations. In this case, the distinction is merely that they're
a subtly different kind of nonsense.
>> Something to think about: if the unary "*" and unary "&" didn't do
>> two very different things, only one of them would need to exist.
Ok I see there is a comma missing between the parameters. & as I
understand is the address of certain information pointed to by a pointer. *
as I understand it returns the value or data at that address ? Am I way off
base again?
Bill
& gives the address of whatever you use it with.
Consider:
int i;
int *p = &i;
From that point on, *p will give you i, p will give you the address
of i, and &p will give you the address of /p/.
So you are correct on what * does, but wrong about &.
--
Andrew Poelstra
http://www.wpsoftware.net/andrew
Given:
int n = 0x34;
Then
&n is a pointer.
&n is the address of (n).
*&n equals n.
*n doesn't mean anything, because n isn't a pointer.
--
pete
As usual you understand wrong and 3 seconds with a debugger and printing
out the values of addresses, pointers etc would show you that.
Hmm... However, C does have both "." and "->" though having only one
of them could suffice.
Yes, but they do different things. The OP presented two expressions
which, if he has written them correctly, differed *only* in the use of
"*" vs. "&", and asked whether they were equivalent.
So & and * are opposites.
So is there no way that * could be used instead of & ?
In this example or any? I know that scanf takes & But I have seen from
reading source code that in different situations * is used sometimes & and
in the FILE struct
(fp=FILE) niether * or & are used.
Bill
No debugger. And printing out values and addresses myself is my next
step. I want to undestand what I'm going to get.
>
> "Malcolm McLean" <malcolm...@btinternet.com> wrote in message
> news:d0e35bf9-15e1-4c97...@t41g2000yqt.googlegroups.com...
> On Feb 26, 11:06 pm, "Bill Cunningham" <nos...@nspam.invalid> wrote:
>> Ok are these two statements equal?
>>
>> int n=0x34
>> scanf("%d\n"&n);
>> and
>> scanf("%d\n"*n); ????
>>
> You need commas.
> * gets what a pointer points to
> & gets the address of a variable (ie the pointer that points to that
> variable).
>
> So & and * are opposites.
>
> So is there no way that * could be used instead of & ?
Yes, there is.
Think about it, Bill.
If
something
is a pointer, then
*something
gets the thing that
something
points at.
If scanf() requires pointers, then you have to give it pointers.
How could *something result in a pointer?
Only if
something
pointed /at/ a pointer.
Thus,
something
has to be declared as
type **something;
That is,
something
points to a pointer to a typed value.
char **SomeThing;
makes
SomeThing
a pointer to a pointer to a char, and
*SomeThing
a pointer to a char.
int **SomeThing;
makes
SomeThing
a pointer to a pointer to an int, and
*SomeThing
a pointer to an int
So, if you have
int **SomeThing;
(and both SomeThing and *Something are proper values) then
scanf("%d",*SomeThing);
will work.
> In this example or any? I know that scanf takes & But I have seen from
> reading source code that in different situations * is used sometimes & and
> in the FILE struct
> (fp=FILE) niether * or & are used.
>
> Bill
>
>
--
Lew Pitcher
Master Codewright & JOAT-in-training | Registered Linux User #112576
Me: http://pitcher.digitalfreehold.ca/ | Just Linux: http://justlinux.ca/
---------- Slackware - Because I know what I'm doing. ------
Bill, either stop using Outlook Express or find out how to get it to
quote properly.
[snip]
> Bill, either stop using Outlook Express or find out how to get it to
> quote properly.
I thought for sure that I have it down correct manually.
Bill
Did you know that you can see even what *you* have posted? Amazing, but
true. Look at the message containing your answer to Malcolm. It does not
distinguish between what Malcolm said and what you said. See the problem?
Malcolm posted via Google, that's the origin of the problem. Use the
Quotefix "version" of OE when responding to people who post via Google.
> Did you know that you can see even what *you* have posted? Amazing, but
> true. Look at the message containing your answer to Malcolm. It does not
> distinguish between what Malcolm said and what you said. See the problem?
>
> Malcolm posted via Google, that's the origin of the problem. Use the
> Quotefix "version" of OE when responding to people who post via Google.
Ok then google was the problem then. I think I'm going to look for a
windows version of a unix news client.
Bill
Perhaps you could consider going back to using Thunderbird, as you did
for two articles you posted here on January 8. Here's one of them:
| On 1/8/2010 2:36 PM, Bill Cunningham wrote:
| > "Keith Thompson"<ks...@mib.org> wrote in message
| > news:ln7hrss...@nuthaus.mib.org...
| >
| >
| >> Bill, please fix your newsreader so it quotes properly (google
| >> "OE-Quotefix"), or find a different one; there are plenty of free ones
| >> out there.
| >>
| > I slipped up again. I can for the most part seem to cut these messages
| > and trim correctly. But this time I wanted to leave everything that was said
| > intact. I must not be doing that correctly manually. Does this quotefix
| > affect emails? I just want something that helps trim usenet posts.
| >
| > Bill
| >
| >
| >
| Ok is this right? I have posted this with Thunderbird.