Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the "^" symbol in C++?

Has a new symbol joined the C++ language specification while I was sleeping under a rock?

I just encountered the following question:

Restrict Text Box to only accept 10 digit number

Which suggests that the '^' symbol is somehow part of C++ (not in the legacy meaning of a bitwise-XOR)

Is this so?

If so, what does it mean? (I tried to google the question but Google didn't come up with satisfactory answers)

like image 942
Android Eve Avatar asked Sep 01 '10 20:09

Android Eve


People also ask

What is %s in C called?

%s is for string %d is for decimal (or int) %c is for character.

What is the purpose of #sign in C?

The #define symbol is a constant and macro that the preprocessor expands before compilation. No storage is allocated for these symbols. They have no type, and the debugger cannot reference them.

Is special character in C?

Use of Character Set in C These are known as the characters in C. They include digits, alphabets, special symbols, etc.


1 Answers

In C++ the “^” symbol is the bitwise exclusive or (xor) operator. For a single bit you have 0 ^ 0 = 1 ^ 1 = 0 and 0 ^ 1 = 1 ^ 0 = 1.

However, in the question you are refering to it is part of Microsoft special syntax for C++ development on the .NET platform known as C++/CLI or It Just Works.

Memory on .NET is garbage collected and references to objects will have to be tracked. This makes it impossible to reference these objects using a normal C++ pointer. Microsoft has decided to reuse the “^” symbol to declare a variable somewhat similar to a pointer that can reference an object on the managed heap.

^ (Handle to Object on Managed Heap)

like image 121
Martin Liversage Avatar answered Sep 20 '22 17:09

Martin Liversage