# What does the tilde (~) mean in C++?

Page 1 of 1

## 2 Replies - 16522 Views - Last Post: 20 June 2010 - 06:28 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=178478&amp;s=cc3b135afe47da819838b074173dd19b&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 heyoman1

Reputation: 64
• Posts: 735
• Joined: 30-November 09

# What does the tilde (~) mean in C++?

Posted 20 June 2010 - 06:19 PM

What does the tilde(~) mean in c++. and could you give an example also?
Is This A Good Question/Topic? 0

## Replies To: What does the tilde (~) mean in C++?

### #2 KYA

• yay verily

Reputation: 3155
• Posts: 19,200
• Joined: 14-September 07

## Re: What does the tilde (~) mean in C++?

Posted 20 June 2010 - 06:25 PM

It's the bitwise NOT

Quote

The bitwise NOT, or complement, is a unary operation that performs logical negation on each bit, forming the ones' complement of the given binary value. Digits which were 0 become 1, and vice versa. For example:

NOT 0111 (decimal 7)
= 1000 (decimal 8)

### #3 Locke

• Sarcasm Extraordinaire!

Reputation: 526
• Posts: 5,604
• Joined: 20-March 08

## Re: What does the tilde (~) mean in C++?

Posted 20 June 2010 - 06:28 PM

Or potentially a the beginning of a destructor.

```class MyClass
{
public:
MyClass();
~MyClass();

// ...
};
```

The constructor initializes instances of MyClass, while the destructor takes care of anything that needs to happen when the object is no longer needed. Essentially, they're the opposite. One creates, one destroys.