Click here to Skip to main content
11,633,494 members (77,085 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C++
using namespace std;
void AAA (int* & x,int *y)
    void main()
    int x=5;
    int *y=&x;

what is mean both of { int* & x,int *y }
Posted 3-Aug-12 18:09pm
Sergey Alexandrovich Kryukov at 17-Oct-12 15:51pm
This is not a productive way of asking questions. Better develop your own code based on reading manuals, show it if you stuck.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

int * is a pointer to a memory address that contains an int. int * y = &x means x and y are both the SAME int instance only one int is created here. However, its also the one pointer being passed twice, because you pass y twice, the x and y in AAA are both the y in your main, because that's what you passed in.

main always returns int in valid C++
ebousha at 4-Aug-12 0:39am
but what is different between
int* & x,int *y
Christian Graus at 4-Aug-12 0:43am
&x means, the address of x. If x is an int, &x is an int *. int * y = &x means, declare a pointer to an int, called y, and set it's value to be the address of the int, x. You should probably talk to your teacher if you're confused, we're happy to help, but if you're not getting my answers, your teacher can help better.
_Amy at 4-Aug-12 12:04pm
Nicely explained. +5!
ebousha at 4-Aug-12 0:49am
thanks alot
CIDev at 6-Aug-12 9:21am
Good explanation, +5
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Pointer declarations are better off to be read from right to left for better understanding!!
int* & x is a reference to a pointer to an int
int *y is a pointer to an int

To learn more, please look here:[^][^][^]
CIDev at 6-Aug-12 9:21am
Nice references, +5
Volynsky Alex at 6-Aug-12 9:56am
Thanks CIDev!
Amarnath S at 7-Aug-12 7:34am
Is there a way to bookmark your solution? I'd like to bookmark it.
CIDev at 7-Aug-12 9:31am
@Amarnath, To bookmark a solution click the icon that looks like a star with a plus sign at the bottom right of the solution.
Amarnath S at 8-Aug-12 12:29pm
@CIDev, thanks. Somehow, I missed that star icon amidst all the contents of this page. I was looking for it at the top, and it is in the bottom.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 8,618
1 Sergey Alexandrovich Kryukov 8,189
2 Mika Wendelius 6,415
3 F-ES Sitecore 2,321
4 Suvendu Shekhar Giri 2,075

Advertise | Privacy | Mobile
Web01 | 2.8.150728.1 | Last Updated 4 Aug 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100