Skip to content

Instantly share code, notes, and snippets.

@its-prithvi-raj
Last active January 28, 2025 14:10
Show Gist options
  • Select an option

  • Save its-prithvi-raj/2f1cf413b64cad6f64131e041fd0ce34 to your computer and use it in GitHub Desktop.

Select an option

Save its-prithvi-raj/2f1cf413b64cad6f64131e041fd0ce34 to your computer and use it in GitHub Desktop.
C++ Important Stuff Brush-up

Pointers Cheatsheet

int a = 100;
int* ptr = &a;

// Value of a.
std::cout << "(Value of) a: " << a << "\n";

// Pointer to a OR value of a.
std::cout << "(Pointer to a OR Value of a) *ptr: " << *ptr << "\n";

// Address of OR reference to a.
std::cout << "(Address of OR reference to) &a: " << &a << "\n";

// Address of pointer to a OR &(&a).
std::cout << "(Address of a OR reference to a) ptr: " << ptr << "\n";

// Address of address of a OR address of the pointer to a.
std::cout << "(Address of a OR reference to a) &ptr: " << &ptr << "\n";

// Pointer to reference to a OR address of a, which is address of pointer to a.
std::cout << "(Pointer to reference to a) *(&ptr): " << *(&ptr) << "\n";

// Pointer to pointer to a, which is same as value of a.
std::cout << "(Pointer to pointer to a) *(*(&ptr)): " << *(*(&ptr)) << "\n";

The rule of five

class Integer {
	  int *m_pInt;
    
  public:
    //Default constructor
    Integer();

    //Parameterized constructor
    Integer(int value);

    //Copy constructor
    Integer(const Integer &obj);
    
    //Copy assignment
    Integer & operator=(const Integer &obj);

    //Move constructor
    Integer(Integer &&obj);

    //Move assignment
    Integer & operator=(Integer && obj) ;

    int GetValue()const;
    void SetValue(int value);
    
    ~Integer();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment