Click here to Skip to main content
12,954,403 members (64,809 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 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 4-Aug-12 0:39am
but what is different between
int* & x,int *y
Christian Graus 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.
ebousha 4-Aug-12 0:49am
thanks alot
_Amy 4-Aug-12 12:04pm
Nicely explained. +5!
CIDev 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 6-Aug-12 9:21am
Nice references, +5
Volynsky Alex 6-Aug-12 9:56am
Thanks CIDev!
Amarnath S 7-Aug-12 7:34am
Is there a way to bookmark your solution? I'd like to bookmark it.
CIDev 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 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
Top Experts
Last 24hrsThis month
OriginalGriff 6,524
CHill60 3,490
Maciej Los 3,123
ppolymorphe 2,030
Jochen Arndt 1,975

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 4 Aug 2012
Copyright © CodeProject, 1999-2017
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