搜尋此網誌

2025年5月26日星期一

Operations in C++

In C++, the percent symbol (%) is the modulus operator, used to find the remainder of a division operation.

Bitwise operations in C++ manipulate individual bits within integer data types. These operations are useful for tasks like optimizing memory usage, performing low-level system programming, and cryptography.

&: ampersand
Sets each bit to 1 if both corresponding bits are 1

~(NOT): tilde
Inverts all bits (bitwise complement)

^(XOR): caret
Sets each bit to 1 if only one of the corresponding bits is 1

|(OR)
Sets each bit to 1 if at least one corresponding bit is 1

||: logical operator

0 means false and anything else means true.

! (exclamation sign) for NOT

In C++, the == operator is the equality operator. It is used to compare two values and returns true if they are equal, otherwise, it returns false.

int a = 9;
int* ptr = &a; // Pointer storing the address of 'a'

Pointer Declaration: int* ptr; declares a pointer to an int type.
Address-of Operator (&): Used to get the memory address of a variable.
Dereferencing in C++ refers to accessing the value stored at a memory address using a pointer. This is done using the (prefix) asterisk (*) operator, which allows us to retrieve the actual data held at the memory location a pointer is pointing to.

Microsoft Copilot

沒有留言:

發佈留言