![]() |
The Address Operator in C is a special unary operator that returns the address of a variable. It is denoted as the Ampersand Symbol ( & ). This operator returns an integer value which is the address of its operand in the memory. We can use the address operator (&) with any kind of variables, array, strings, functions, and even pointers. SyntaxThe address operator is generally used as a prefix to its operand: &operand where operand can be a variable, array, function, pointer, etc. ![]() Address Operator in C Examples of Address OperatorsExample 1:Simple C example to demonstrate how to use the address operator in our program. C
Output
The address of x is 0x7fffe8f5591c Explanation A variable x was defined and initialized with the value 100 in the program above. We retrieved the address of this variable x by using the address operator (&) as the prefix and printed it using printf() function.
Generally, the value returned by the address operator is stored in the pointer variable and then the pointer is dereferenced to get the value stored in that address. Example 2:Using a pointer to store the address returned by the address operator and then dereferencing it. C
Output
Value of x: 1 Example 3:Some standard functions like scanf() also require the address of the variable. In these cases, we use the address operator. C
Output Enter any number: 10 Address Operator Incompitable Entities in CThere are some entities in C for which we cannot use the address operator i.e. we cannot get the address of those entities in C. Some of them are:
Applications of Address Operator (&):The address operator (&) is widely used in C programs to get the addresses of different entities. Some of the major and most common applications are:
|
Reffered: https://www.geeksforgeeks.org
C++ |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 15 |