Click here to Skip to main content
12,348,995 members (70,760 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C++
#include<iostream>
#include<conio.h>
using namespace std;
 
void AAA (int* & x,int *y)
{
    cout<<y<<endl;
    cout<<x<<endl;
}
    void main()
{
    int x=5;
    int *y=&x;
 
    AAA(y,y);
    getch();
 
}

what is mean both of { int* & x,int *y }
Posted 3-Aug-12 18:09pm
Comments
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.
--SA
Rate this: bad
 
good
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++
  Permalink  
Comments
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.
_Amy 4-Aug-12 12:04pm
   
Nicely explained. +5!
ebousha 4-Aug-12 0:49am
   
thanks alot
CIDev 6-Aug-12 9:21am
   
Good explanation, +5
Rate this: bad
 
good
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:
http://stackoverflow.com/questions/5789806/meaning-of-and-in-c[^]
http://stackoverflow.com/questions/4185776/what-does-mean-in-a-function-parameter[^]
http://stackoverflow.com/questions/57483/what-are-the-differences-between-pointer-variable-and-reference-variable-in-c[^]
  Permalink  
Comments
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


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