what is the difference between deference operator and pointer

S

satyspiceoflife

int x,a;
a=10
x=&a;
cout<<*x; //using dereference operator
this will print value 10

the other case is
int *x; //x is a pointer variable
int a=10;
x=&a;
cout<<*x; //printing value 10

what is the difference between these two cases?
 
C

Clever Monkey

int x,a;
a=10
x=&a;
cout<<*x; //using dereference operator
this will print value 10

the other case is
int *x; //x is a pointer variable
int a=10;
x=&a;
cout<<*x; //printing value 10

what is the difference between these two cases?
1. Don't post multiple times. We heard you the first time.

2. Try a C++ newsgroup. C is a different language than what you posted
here.
 
N

Nick Keighley

int x,a;
a=10
x=&a;

this is an error you can't store a pointer value in an int.
Didn't your compiler complain?
cout<<*x; //using dereference operator

this isn't C
this will print value 10

no it won't
the other case is
int *x; //x is a pointer variable
int a=10;
x=&a;
cout<<*x; //printing value 10

what is the difference between these two cases?

one gives a diagnostic the other doesn't

--
Nick Keighley

Dan Pop: "When was the last time you've implemented a real life
application as a strictly conforming program?"
Richard Heathfield: "About 20 minutes ago. It was a new, heavily
optimised pig-launching routine, which gets us a 70% range increase
on previous porcine aeronautic programs."
 
C

CBFalconer

int x,a;
a=10
x=&a;
cout<<*x; //using dereference operator
this will print value 10

the other case is
int *x; //x is a pointer variable
int a=10;
x=&a;
cout<<*x; //printing value 10

what is the difference between these two cases?

Don't post the same article more than once.

Both are undefined. cout is undeclared. Even if it was, left
shifting it by 10 and discarding the result is meaningless.
Assigning an address to an int is also undefined. Executable code
outside of a function body is not allowed.

Maybe you are thinking of some other language than C? C++ comes to
mind, and questions about it are better aimed at comp.lang.c++.
 
M

Michael Wojcik

The "deference operator" does not exist in C, and is rarely used in
comp.lang.c.

It does exist in INTERCAL, where it is one of the most useful features
of the language. Of course, since that language is INTERCAL, that's
not saying much.

HTH. HAND.

--
Michael Wojcik (e-mail address removed)

I said, 'I need to put my soul into my work and it is well known that
computers haven't got a soul.' My father said, 'The Americans are working
on it.' -- Sue Townsend, _The Secret Diary of Adrian Mole, Aged 13 3/4_
 
K

Kenny McCormack

this is an error you can't store a pointer value in an int.
Didn't your compiler complain?


this isn't C

Actually, it can be legal C.

My program contains this declaration:

int cout, *x = &cout;

Without such a declaration, I would assume that OP's program, like most
of those posted here, wouldn't compile.
 
F

Frederick Gotham

Kenny McCormack posted:
My program contains this declaration:

int cout, *x = &cout;


Yes, that is a declaration, although it would be better described as a
"definition", because it actually creates an object(s).
 
G

Guest

Frederick said:
Kenny McCormack posted:



Yes, that is a declaration, although it would be better described as a
"definition", because it actually creates an object(s).

It is a definition of x, but (at least in C99) it is only a definition
of cout if it has block scope. "Declaration" is correct no matter where
it is placed.
 
F

Frederick Gotham

=?utf-8?B?SGFyYWxkIHZhbiBExLNr?= posted:
It is a definition of x, but (at least in C99) it is only a definition
of cout if it has block scope. "Declaration" is correct no matter where
it is placed.


I don't understand, please elaborate on that. My current understanding is
that the following is _always_ a definition, regardless of where it's places:

int cout;

The only way that it could be a declaration is if it were:

extern int cout;
 
R

Richard Heathfield

Frederick Gotham said:
=?utf-8?B?SGFyYWxkIHZhbiBExLNr?= posted:



I don't understand, please elaborate on that. My current understanding is
that the following is _always_ a definition, regardless of where it's
places:

int cout;

That's only a tentative definition, not a "proper" definition, unless it's
within a function.

The only way that it could be a declaration

All definitions are declarations, by definition, but I declare that not all
declarations are definitions.
 
F

Frederick Gotham

Richard Heathfield posted:
That's only a tentative definition, not a "proper" definition, unless
it's within a function.


I'm not quite sure what you mean. The following compiles for me without error
or warning, which would lead me to believe that it's a fully-fledged
definition:

int cout;

int main(void)
{
cout = 7;
return 0;
}
 
B

Ben Pfaff

Frederick Gotham said:
Richard Heathfield posted:



I'm not quite sure what you mean. The following compiles for me without error
or warning, which would lead me to believe that it's a fully-fledged
definition:

From C99 (6.9.2):

If a translation unit contains one or more tentative
definitions for an identifier, and the translation unit
contains no external definition for that identifier, then
the behavior is exactly as if the translation unit contains
a file scope declaration of that identifier, with the
composite type as of the end of the translation unit, with
an initializer equal to 0.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top