C++Introduction to C++Learn C++

What Does & (the ampersand) Mean In A C++ App?

What Does the ampersand Mean In A C++ App

In most cases, an ampersand symbol (&) is used as an ‘AND’ logic symbol. In a C or C++ app, we use the & operand as an ‘AND’ logic in bitwise operations. We also use the double ampersand && operand as an ‘AND’ symbol in other logical operations. So, how we can use ampersands in C++? What does the & ampersand mean in a C++ app? Let’s learn this.

Here are the most common usages of & operand.

How to declare a reference to a type with & in a C++ app?

We can use the & symbol when we declare a variable, at the left-hand side of a variable declaration. That means that address of this reference type is same as the declared type. Any types can be used in any type of declarations, local variables, class members, method parameters etc. For example,

Here is a full example of this usage,

If you wonder about the difference between C++ pointers and references here is your guide,

How can we get the address of a variable with & in a C++ app?

In a C++ app the & symbol is used as an address operator. When using this operand on the right-hand side of a variable, we point the address of this variable, not itself. This is generally useful with pointers. For example, you can set address of a string definition to a new pointer string.

If you are looking more about pointers and memory address of a variable here is your guide,

How can we use the & ampersand as a bit-wise operator in a C++ app?

Use & as a Bitwise AND Operator

The & (bitwise AND) in C or C++ takes two numbers as operands and does AND on every bit of two numbers. The result of AND is 1 only if both bits are 1.

Here is a full example to this usage

If you wonder about other bitwise operators you can check this post,

How do I use “&&” in a conditional expression in a C++ app?

We can use && together as an AND operator as we mentioned before,

In both the C & C++ programming language,

  • && is used as AND,
  • || is used as OR,
  • ! symbol is used as NOT.

An example to this Logical operator is given as below,

This means if(a>40) is true AND if(b<60) is true logically result is true. Thus, this example if clause works like if(true) { }. This is how && operand works here.

Here is the full example,

If you wonder about all operators in your C++ app please check here,

C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.

There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise versions of C++ Builder and there is a trial version you can download from here.

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++17Language FeatureLearn C++

How To Use Skia Shader SkSL Shading Language Code in C++ Builder?

Artificial Intelligence TechC++C++17C++20Learn C++

How To Create Simple Generative AI Code In C++

C++C++17Language FeatureLearn C++

How To Use The SVG Image Format With Skia In C++ Builder

C++C++17Language FeatureLearn C++

How To Use Skia Images in C++ Builder?