
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
What is the use of the '&' symbol in C++?
The & symbol is used as an operator in C++. It is used in 2 different places, one as a bitwise and operator and one as a pointer address of operator.
Bitwise AND
The bitwise AND operator (&) compares each bit of the first operand to that bit of the second operand. If both bits are 1, the bit is set to 1. Otherwise, the bit is set to 0. Both operands to the bitwise AND operator must be of integral types.
Example
#include <iostream> using namespace std; int main() { unsigned short a = 0x5555; // pattern 0101 ... unsigned short b = 0xAAAA; // pattern 1010 ... cout << hex << ( a & b ) << endl; }
Output
This gives the output −
0
Address Of operator
C++ provides two-pointer operators, which are Address of Operator (&) and Indirection Operator (*).
A pointer is a variable that contains the address of another variable or you can say that a variable that contains the address of another variable is said to "point to" the other variable. A variable can be any data type including an object, structure or again pointer itself.
The address of Operator (&), and it is the complement of *. It is a unary operator that returns the address of the variable(r-value) specified by its operand. For example,
Example
#include <iostream> using namespace std; int main () { int var; int *ptr; int val; var = 3000; // take the address of var ptr = &var; // take the value available at ptr val = *ptr; cout << "Value of var :" << var << endl; cout << "Value of ptr :" << ptr << endl; cout << "Value of val :" << val << endl; return 0; }
Output
When the above code is compiled and executed, it produces the following result −
Value of var :3000 Value of ptr :0xbff64494 Value of val :3000
- Related Articles
- What is the use of the @ symbol in PHP?
- What is the symbol of mercury?
- What is the symbol of battery?
- What is the symbol of alcohol?
- What is the symbol of the element helium?
- What is the Symbol Table?
- What is the usage of “@” symbol in MySQL stored procedure?
- What Information is Stored in the Symbol Table?
- What is the significance of Hyderabad metro rail symbol?
- What is representation of fixed-length and variablelength array representation in the symbol table?
- What is the symbol for baking soda?
- Can we use the “.” symbol in MongoDB collection name?
- What are the Elements, Compounds, and Symbol?
- What is two array representations in the symbol table?
- The symbol of cadmium is CaCuCmCd
