Reference operator (&)
It gets the address of an identifier (variable)
For example, you declare
int *pInteger;
If you call pInteger, you are refering to the pointer itself;
if you call *pInteger, you are getting the value stored at the address that pInteger indicates;
And finally if you call &pInteger, you are getting the address where pInteger is stored.
2007-11-15 03:36:56
·
answer #1
·
answered by halen_shezar 2
·
2⤊
0⤋
The ampersand (&) is to get the address of a variable. Maybe you're already fully familiar with this usage.
int a;
int *p = &a; // p points to a
When its used as a part of a function prototype or definition, it means that its a reference. A reference variable acts like the variable that was passed to the function, but under the hood, its a pointer.
class bigclass; // as an example, its some big complex object
void func1( bigclass & ref ) {
ref.memberFunction(); // use ref like an object
}
void func2() {
bigclass obj; // make an object
func1( obj ); // pass it by reference to the function
}
2007-11-15 11:43:37
·
answer #2
·
answered by Neebler 5
·
3⤊
0⤋
Suppose you have 2 functions
void add3(int i)
{
i+=3;
}
void add3(int& i)
{
i+=3;
}
The top function passes i by value, so when the function returns, the value of i in the calling function is not changed.
In the second function, i is passed from the calling function by reference, so when i gets 3 added to it and the function returns, the value of i in the calling function has had 3 added to it.
2007-11-15 11:44:34
·
answer #3
·
answered by Tom 3
·
0⤊
0⤋
when u start c program u use syntax
#include (#preprocessordirective.stdio.h headerfile)
#include
main()
{ (starting of c program)
int n; here we r declaring a integer type character)
printf("enter firset number?");
scanf("%d",&n); (&is adress operator)
getch();
} (enfin braces of c program)
i hope i answer u correctly adress operator & id very necesssary bcuz whn u declare a interger dan in printf u ask to enter first number n whn u will run prohram in output u will ask to enter any number frm keyborad...in scanf u give the compiler the adress of operator ...it is very necessary & bcuz dats the main syntax..n if u dun write it dan u will get errors in ur program...
STRUCTURE IF C PROGRAM
* preprocessor directives
*the main() function
* c statement
2007-11-15 11:46:47
·
answer #4
·
answered by Amara 2
·
1⤊
0⤋