473,397 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

what is meaning of ~ operator?

what is the meaning of ~
for ex
~a=?
Mar 8 '13 #1
3 1763
weaknessforcats
9,208 Expert Mod 8TB
The ~ operator is overloaded. In C it is the complement operator. In C++ it is either the complement operator or it identifies a member function as a destructor.

You haven't posted enough code for me to see what you are after.
Mar 8 '13 #2
Hi ! ~ it is called Complement. it is Bitwise Operator in c. The compl. operator is the text equivalent of ~. There are two ways to access the compl operator in your programs: include the header file iso646.h, or compile with /Za.

Example :

Expand|Select|Wrap|Line Numbers
  1. // expre_One_Complement_Operator.cpp
  2. // compile with: /EHsc
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main () {
  8.    unsigned short y = 0xFFFF;
  9.    cout << hex << y << endl;
  10.    y = ~y;   // Take one's complement
  11.    cout << hex << y << endl;
  12. }
In my example the new value assigned to y is the one's complement of the unsigned value 0xFFFF, or 0x0000.
Mar 8 '13 #3
simum
4
This operator is also used as a destructor..
for ex:
Expand|Select|Wrap|Line Numbers
  1. using system
  2. class xyz()
  3. {
  4. public xyz()
  5. {
  6. console.writeline("created");
  7. }
  8. ~xyz()
  9. {
  10. console.writeline("destroyed");
  11. }
  12. }
  13. or in other cases it can be used as a bitwise operator :)
Mar 12 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Jonny Iversen | last post by:
My VC++ documentation state that this is the one complements operator ~0 = 0xFFFF aka all bits set (swapping all 0's to 1) This means that the bit is: 0 = 0000 0000 0000 0000 0000 0000...
4
by: PengYu.UT | last post by:
I'm confused with the following small program. I looked at the <complex> header file (gcc-3.3). operator* is defined in namespace std. I'm wondering why the operator * can be used in the following...
2
by: Shark | last post by:
Hi, if we need to change the behavior of operator new, it is called overriding or overloading? My other question is, if we change the behavior of operator new, do we use malloc to do that or we use...
10
by: Thierry Lam | last post by:
What does the following macro mean, especially the << sign: #define hello(x) (( int64 ) floor( (double) x ) << 32) Thanks Thierry
2
by: dirk | last post by:
Why doesn't the standard allow to overload operator new/delete in my namespace, e.g. namespace Foo { void* operator new( std::size_t sz ); void operator delete( void* address ); } On the...
12
by: Jack.Thomson.v3 | last post by:
Why does the following program works, and what is ^+ operator ? int main() { int a = 10; int b = 20; int c; c = a ^+ b;
12
by: ujjc001 | last post by:
Here's one for ya. I want to create a relational operator from a string object, i.e. I want to somehow be able to say: string opString = ">="; int i1 = "20"; int i2 = "10"; if (i1...
5
by: cmrhema | last post by:
Hi, I have the following example enum MaterialColors { Blue=1,Red=2,Yellow=4, Purple=Blue|Red,Green=Yellow|Blue,Orange=Red|Yellow, } class Program { static...
1
by: nachinachi | last post by:
what is operator overloading and function overloading?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.