Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of the '&' symbol in C++ [duplicate]

Tags:

c++

I realize this is probably a dumb question but I couldn't find the answer anywhere... What is the purpose of the '&' symbol in C++ functions? Such as

vec2& operator+(vec2& left, const vec2& right)
{
    return left.add(right);
}

I'm following a youtube series that's a little over my head, but I'm doing fine because all the code is there. However that 'and' symbol keeps popping up and I'd really like to know what it is... Does it have something to do with classes?

Here's exactly what I'm watching: https://www.youtube.com/watch?v=-peYVLeK0WU Guy from a channel called "TheChernoProject" making a simple game engine. Also, this is Visual Studio 2013 C++, if that changes anything.

like image 915
Gector Avatar asked Jan 24 '16 06:01

Gector


People also ask

What is the uses of the?

English has two articles: the and a/an. The is used to refer to specific or particular nouns; a/an is used to modify non-specific or non-particular nouns. We call the the definite article and a/an the indefinite article. For example, if I say, "Let's read the book," I mean a specific book.

What are the rules of using the?

“The” is typically used in accompaniment with any noun with a specific meaning, or a noun referring to a single thing. The important distinction is between countable and non-countable nouns: if the noun is something that can't be counted or something singular, then use “the”, if it can be counted, then us “a” or “an”.

Where do we use the article the?

Articles are used before nouns or noun equivalents and are a type of adjective. The definite article (the) is used before a noun to indicate that the identity of the noun is known to the reader. The indefinite article (a, an) is used before a noun that is general or when its identity is not known.

How we use the in sentence?

Use "the" with any noun when the meaning is specific; for example, when the noun names the only one (or one) of a kind. Adam was the first man (the only 'first man'). New York is the largest city in the United States (only one city can be 'the largest'). We live on the earth (the only Earth we know).


Video Answer


1 Answers

"&" can mean several different things, depending on the context.

The example you gave above is the C++ "reference operator":

Need help understanding reference operator(C++) in specific functions

The reference operator is specific to C++. "&" can also be used as the "address of" operator, used in both C and C++:

What are the differences between a pointer variable and a reference variable in C++?

Finally, "&" can also be the bitwise "AND" operator:

http://www.cprogramming.com/tutorial/bitwise_operators.html

like image 52
paulsm4 Avatar answered Oct 06 '22 00:10

paulsm4