473,807 Members | 2,763 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4638
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************ **********@k70g 2000cwa.googleg roups.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. "Declaratio n" is correct no matter where
it is placed.

Sep 16 '06 #8
=?utf-8?B?SGFyYWxkIHZ hbiBExLNr?= 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. "Declaratio n" 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?SGFyYWxkIHZ hbiBExLNr?= 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. "Declaratio n" 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

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

Similar topics

12
3308
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. Such things happen. The whole subsystem is going through radical changes. I don't really want to say what I think of the code just yet. That would influence the opinions of others, and I really want to know how other people view these things,...
16
6790
by: RS | last post by:
Hi, What is the difference between new() and malloc()? RS
2
3670
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
3424
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
2969
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 reading several old posts/threads on the subject, and they never end with a conclusion (people keep correcting each other and disagreeing).
83
15637
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 <stdio.h> #include <string.h> void main() { char *str1="abcd";
0
266
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
1989
by: Vols | last post by:
class A{ public: int x; }; class B : public A{ public: int y; }; void foo()
10
3447
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
9719
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9599
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10624
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10371
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9193
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5684
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4330
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3853
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3010
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.