Click to See Complete Forum and Search --> : def. of *


Nickolaus
03-13-2000, 04:09 PM
What does the * do in C++? Where is it properly used and for
what reasons. Thanks.

Dan
03-13-2000, 04:32 PM
OK i'll tell you what it does and what it means to ME. I might get yelled
at by all the other C++ guru's here but hey my definition works for me.

the asterik (*) does a few things declarees a pointer

int* p_int; //The asterik means it is a pointer

Now you might or might not know what a pointer is... but lets just say right
now it is a variable that points to a memory address. So when we refer to
the variable again, such as this

cout << p_int;

We are not getting the value stored at the address. We are getting the address,
you may or may not want this. This is where the asterik (*) comes into play.


cout << *p_int;

That will give you the value stored at the pointers address. The asterik(*)
is a dereference operator, as far as i know it deals with pointers only.
OH AND WE CANT FORGET IT IS ALSO MULTIPLICATION. However pertaining to
pointers, it returns the value stored at the address.

cout << *p_int; //Value at address
cout << p_int; //Actual memory address

Hope that helps somewhat.

"Nickolaus" <watts.77@osu.edu> wrote:
>
>What does the * do in C++? Where is it properly used and for
>what reasons. Thanks.

Bill Heffner
03-13-2000, 09:00 PM
Not too shabby for a self-professed beginner, Dan.

Another way of looking at the asterisk when applied to a pointer is that
in that useage it is the "contents of" operator. That is (as you said, but
in slightly different words):

int* p_int; // declares a pointer to an int

cout << p_int; // outputs the address
cout << *p_int; // outputs the "contents of" that address

Another related operator, Nickolaus, (if you don't know it) is the "address
of" operator: &

int foo; // declares an int variable
cout << &foo; // outputs the address of that variable
cout << foo; // outputs the contents of the variable

"Dan" <daniel_143@hotmail.com> wrote:
>
>OK i'll tell you what it does and what it means to ME. I might get yelled
>at by all the other C++ guru's here but hey my definition works for me.
>
>the asterik (*) does a few things declarees a pointer
>
>int* p_int; //The asterik means it is a pointer
>
>Now you might or might not know what a pointer is... but lets just say right
>now it is a variable that points to a memory address. So when we refer
to
>the variable again, such as this
>
>cout << p_int;
>
>We are not getting the value stored at the address. We are getting the
address,
>you may or may not want this. This is where the asterik (*) comes into
play.
>
>
>cout << *p_int;
>
>That will give you the value stored at the pointers address. The asterik(*)
>is a dereference operator, as far as i know it deals with pointers only.
> OH AND WE CANT FORGET IT IS ALSO MULTIPLICATION. However pertaining to
>pointers, it returns the value stored at the address.
>
>cout << *p_int; //Value at address
>cout << p_int; //Actual memory address
>
>Hope that helps somewhat.
>
>"Nickolaus" <watts.77@osu.edu> wrote:
>>
>>What does the * do in C++? Where is it properly used and for
>>what reasons. Thanks.
>

Danny Kalev
03-13-2000, 09:41 PM
....and the ampersand is also a two-fold operator: it can be the address
of operator, as you said, but it's also the bitwise and operator. Good
old Brian Kernighan and Dennis Ritchie (the creators of C) weren't
fonder of keywords, were they?

Danny Kalev

"The ANSI/ISO C++ Professional Programmer's Handbook"
http://www1.fatbrain.com/asp/bookinfo/bookinfo.asp?theisbn=0789720221




Bill Heffner wrote:
>
> Not too shabby for a self-professed beginner, Dan.
>
> Another way of looking at the asterisk when applied to a pointer is that
> in that useage it is the "contents of" operator. That is (as you said, but
> in slightly different words):
>
> int* p_int; // declares a pointer to an int
>
> cout << p_int; // outputs the address
> cout << *p_int; // outputs the "contents of" that address
>
> Another related operator, Nickolaus, (if you don't know it) is the "address
> of" operator: &
>
> int foo; // declares an int variable
> cout << &foo; // outputs the address of that variable
> cout << foo; // outputs the contents of the variable
>
> "Dan" <daniel_143@hotmail.com> wrote:
> >
> >OK i'll tell you what it does and what it means to ME. I might get yelled
> >at by all the other C++ guru's here but hey my definition works for me.
> >
> >the asterik (*) does a few things declarees a pointer
> >
> >int* p_int; //The asterik means it is a pointer
> >
> >Now you might or might not know what a pointer is... but lets just say right
> >now it is a variable that points to a memory address. So when we refer
> to
> >the variable again, such as this
> >
> >cout << p_int;
> >
> >We are not getting the value stored at the address. We are getting the
> address,
> >you may or may not want this. This is where the asterik (*) comes into
> play.
> >
> >
> >cout << *p_int;
> >
> >That will give you the value stored at the pointers address. The asterik(*)
> >is a dereference operator, as far as i know it deals with pointers only.
> > OH AND WE CANT FORGET IT IS ALSO MULTIPLICATION. However pertaining to
> >pointers, it returns the value stored at the address.
> >
> >cout << *p_int; //Value at address
> >cout << p_int; //Actual memory address
> >
> >Hope that helps somewhat.
> >
> >"Nickolaus" <watts.77@osu.edu> wrote:
> >>
> >>What does the * do in C++? Where is it properly used and for
> >>what reasons. Thanks.
> >

Nickolaus
03-14-2000, 12:38 AM
Well I thank you guys. That clears it up a little. I think it's a little
past me at this point. I just came
across it in this Visual C++ book and it didn't explain it (I assume because
it's more advanced than that
point in the book) so I just wanted to know. I'm fairly new to C++ and I'm
starting the drudgery of wading
my way through MFC and Visual C++ programming.

-Nickolaus

Danny Kalev <dannykk@inter.net.il> wrote:
>....and the ampersand is also a two-fold operator: it can be the address
>of operator, as you said, but it's also the bitwise and operator. Good
>old Brian Kernighan and Dennis Ritchie (the creators of C) weren't
>fonder of keywords, were they?
>
>Danny Kalev
>
>"The ANSI/ISO C++ Professional Programmer's Handbook"
>http://www1.fatbrain.com/asp/bookinfo/bookinfo.asp?theisbn=0789720221
>
>
>
>
>Bill Heffner wrote:
>>
>> Not too shabby for a self-professed beginner, Dan.
>>
>> Another way of looking at the asterisk when applied to a pointer is that
>> in that useage it is the "contents of" operator. That is (as you said,
but
>> in slightly different words):
>>
>> int* p_int; // declares a pointer to an int
>>
>> cout << p_int; // outputs the address
>> cout << *p_int; // outputs the "contents of" that address
>>
>> Another related operator, Nickolaus, (if you don't know it) is the "address
>> of" operator: &
>>
>> int foo; // declares an int variable
>> cout << &foo; // outputs the address of that variable
>> cout << foo; // outputs the contents of the variable
>>
>> "Dan" <daniel_143@hotmail.com> wrote:
>> >
>> >OK i'll tell you what it does and what it means to ME. I might get yelled
>> >at by all the other C++ guru's here but hey my definition works for me.
>> >
>> >the asterik (*) does a few things declarees a pointer
>> >
>> >int* p_int; //The asterik means it is a pointer
>> >
>> >Now you might or might not know what a pointer is... but lets just say
right
>> >now it is a variable that points to a memory address. So when we refer
>> to
>> >the variable again, such as this
>> >
>> >cout << p_int;
>> >
>> >We are not getting the value stored at the address. We are getting the
>> address,
>> >you may or may not want this. This is where the asterik (*) comes into
>> play.
>> >
>> >
>> >cout << *p_int;
>> >
>> >That will give you the value stored at the pointers address. The asterik(*)
>> >is a dereference operator, as far as i know it deals with pointers only.
>> > OH AND WE CANT FORGET IT IS ALSO MULTIPLICATION. However pertaining
to
>> >pointers, it returns the value stored at the address.
>> >
>> >cout << *p_int; //Value at address
>> >cout << p_int; //Actual memory address
>> >
>> >Hope that helps somewhat.
>> >
>> >"Nickolaus" <watts.77@osu.edu> wrote:
>> >>
>> >>What does the * do in C++? Where is it properly used and for
>> >>what reasons. Thanks.
>> >

James Curran
03-14-2000, 12:59 PM
Just in the spirit of completeness, we should point out that in C++ (as
well as just about any other computer language), the * is also used for
multiplication......

int a,b,c;
a = b * c;


--
Truth,
James Curran
http://www.NJTheater.com
http://www.NJTheater.com/JamesCurran



"Nickolaus" <watts.77@osu.edu> wrote in message
news:38cd4b0d$1@news.devx.com...
>
> What does the * do in C++? Where is it properly used and for
> what reasons. Thanks.

Dan
03-14-2000, 01:28 PM
Yup, i had that in my reply.

"James Curran" <jamescurran@mvps.org> wrote:
> Just in the spirit of completeness, we should point out that in C++
(as
>well as just about any other computer language), the * is also used for
>multiplication......
>
> int a,b,c;
> a = b * c;
>
>
>--
>Truth,
>James Curran
>http://www.NJTheater.com
>http://www.NJTheater.com/JamesCurran
>
>
>
>"Nickolaus" <watts.77@osu.edu> wrote in message
>news:38cd4b0d$1@news.devx.com...
>>
>> What does the * do in C++? Where is it properly used and for
>> what reasons. Thanks.
>
>