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

what is the difference between deference operator and pointer

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?

Sep 15 '06 #1
11 4567
sa*************@gmail.com wrote:
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.
Sep 15 '06 #2
sa*************@gmail.com wrote:
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."

Sep 15 '06 #3
sa*************@gmail.com wrote:
>
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++.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
--
Posted via a free Usenet account from http://www.teranews.com

Sep 15 '06 #4

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 mi************@microfocus.com

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_
Sep 15 '06 #5
In article <11**********************@k70g2000cwa.googlegroups .com>,
Nick Keighley <ni******************@hotmail.comwrote:
>sa*************@gmail.com wrote:
>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
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.

Sep 16 '06 #6
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).

--

Frederick Gotham
Sep 16 '06 #7
Frederick Gotham wrote:
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).
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.

Sep 16 '06 #8
=?utf-8?B?SGFyYWxkIHZhbiBExLNr?= posted:
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).

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;

--

Frederick Gotham
Sep 16 '06 #9
Frederick Gotham said:
=?utf-8?B?SGFyYWxkIHZhbiBExLNr?= posted:
> 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).

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;
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.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 16 '06 #10
Richard Heathfield posted:
> int cout;

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;
}

--

Frederick Gotham
Sep 16 '06 #11
Frederick Gotham <fg*******@SPAM.comwrites:
Richard Heathfield posted:
>> int cout;

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:
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.

--
"You call this a *C* question? What the hell are you smoking?" --Kaz
Sep 16 '06 #12

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

Similar topics

12
by: Steven T. Hatton | last post by:
This is something I've been looking at because it is central to a currently broken part of the KDevelop new application wizard. I'm not complaining about it being broken, It's a CVS images. ...
16
by: RS | last post by:
Hi, What is the difference between new() and malloc()? RS
2
by: diadia | last post by:
string s = "hello"; const char *p = s.begin(); cout << p << endl; // print hello s = ""; char *p2= s.begin(); cout << p2 << endl; // print hello why?????
11
by: J Wang | last post by:
dear, I debug the program recently as follows. #include <sys/stat.h> int main(int argc, char *argv) { struct stat buf;
24
by: Romeo Colacitti | last post by:
Hi, Does anyone here have a strong understanding for the meanings of the terms "lvalue" and "rvalue" as it pertains to C, objects, and different contexts? If so please share. I've been...
83
by: rahul8143 | last post by:
hello, what is difference between sizeof("abcd") and strlen("abcd")? why both functions gives different output when applied to same string "abcd". I tried following example for that. #include...
0
by: satyspiceoflife | last post by:
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;
5
by: Vols | last post by:
class A{ public: int x; }; class B : public A{ public: int y; }; void foo()
10
by: Ahmad Humayun | last post by:
Whats the difference between: char str1 = "wxyz"; char* str2 = "abcd"; I can do this: str2 = str1 but I can't do this: str1 = str2
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.