Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +917541905230, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Sunday, November 29, 2020

What is address of operator and it's need?

Address of operator (&): is used to access the address of any variable by prepending the ampersand sign (&) with a variable name.

Address of Operator | welcome2protec.com

Address of operator (&) is used to access the address of any variable by prepending the ampersand sign (&) with a variable name. You can see at below example to understand it better. 


What is address or memory location of a variable?

In C language, every variable gets a memory location (Address of variable) somewhere in the RAM when it is declared, which help us to access the value of that variable. This memory location has a unique address in hexadecimal format something like 0xbffd8b3c. Simply you can say, A memory location where data is stored is called address of variables.

Address of variable | welcome2protec.com
Address or memory location of variables | welcome2protec.com

Let’s consider a scenario: In a computer network every computer has a unique IP address if you need data from that computer we need to access that computer by using IP address. The same way if we need to access the value of variable ‘x’ we need to access memory location of that variable by using address of (&) Operator with format specifier either %p, %x or %u.


How to access address or memory location of a variable?

Address of  operator (&) is used to specifying the address location of the Variable in C Language.

For Example:

/*while Taking The Input form user */
scanf("%d", &x); 
/*Here address of operator (&) Points to the Memory Location of variable x */

Let's say the address assign to variable x is 0xbffd8b3c, which means whatever value will be assigned to x should be stored at the location 0xbffd8b3c. As you can see in the above diagram 

As I mentioned at the beginning of this tutorial, Address of operator (&) is used to access the address of any variable by prepending the ampersand sign (&) with a variable name. Now let's see the below example how to access the address of x?

/*Program to print both value and address of variable x */.
int main()
{
 int x = 10;
 /*Printing the value of variable x*/
 printf("Value of x = %d\n" , x);
 
 /*Printing the address of variable x */
 printf("Address of x = %u" , &x);
 return 0;
}
/* Here address of x will be displayed on the screen.*/ 

Output:

When the above code is compiled and executed, it produces the following result −

Value of x = 10  
Address of x = 0xbffd8b3c

Address of (&) operator also used in passing the reference in the function arguments.

//Pass By Reference  
void check(int * ,int *); //Function Declaration 
// Check is a function taking 2 Arguments pointer to integer. 
 
check(&a,&b); // Function Call 
 //Here The Passing The Address of a and b to the Function Call.

Points to remember:

  • '&' is known as Address of operator or ampersand.
  • It is an unary operator.
  • '&' is also known as referencing operator.
  • Operand must be the name of variable.
  • '&' Address of operator returns address of a variable.


Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Help others by sharing this page.

Ahmad Irshad

Author & Editor

I love blogging, teaching, learning computer science and sharing it to others. I've written and develped this site so that students may learn computer science related tutorials eaisly. MCA / MCITP

0 Comments:

Post a Comment

Please don't enter any spam link in the comment box.


Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec
Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec
Contact Us