19 Matching Annotations
  1. Last 7 days
    1. removing .clear() stops resetting the fail state, so even after printing first print 2nd and rest of iteration doesnt even attempt to read the new input since its still in failed state and prints failed.. immediately

    2. part 3 of q5:

      failed.. failed.. failed.. //this one is due to us reaching eof and theres nothing left to read

      Looping continues forever since we never actually exit the error condition. there is a continue but no break or return continues forever and we keep trying to read input

      .clear() resets the eof and failure flags, however we're still at end of file and theres nothing left to ignore and loop continues forever

    3. question 5 understanding : while (1) & while(true) mean the same-> keep looping forever until something inside it stops it such as break(Immediately exits)or return.

      here as soon as a = 1 printed, the break in the next line terminates the loop immediately and 2,3 never get read

      continue -> Skips the rest of the current iteration and starts the next one

  2. Nov 2026
    1. We define a copy constructor when the default copy behaviour provided by C++ is not sufficient or when you need to control how objects are copied.

      A copy constructor creates a NEW object from an existing object. Eg Fraction b(a); no need to define copy constructor for this provided by default.

      Usually we need while managing dynamically allocated memory, files and custom behavior

    2. REMEMBER ! If you do not declare ANY constructor yourself, C++ implicitly provides a default constructor.

      But if you declare your own constructor, C++ does NOT automatically provide a default constructor.

      For eg here constructor Fraction(int num, int denm) (Parametrized constrcutor) is defined using args specifically so we cant use Fraction() to create any objects and it will give an error as C++ will no longer generate a default constructor

  3. Oct 2026
    1. 1st return *this from increment_x returns a COPY of a after incrementing x by 1 making a =(3,3), then increment_y() returns copy of (3,4) after ++y

      original a got modified by increment_x() so it is (3,3).

      Point increment_x(); means return a point by value(make a copy)

    2. q4->

      making second_ptr point to a different thing without freeing it first will cause a memory leak

      all 3 things first_ptr, second_ptr and *p_ptr are pointing to the same int =4 on the heap. calling delete multiple times on the same memory address will cause undefined behavior

    3. q3->

      when r=p is assigned, p is still pointing to null, so r receives a copy of the value stored in p, ie nullptr. When p - new int & dereferenced , only p points to value 5 in heap memory WHERAS r continues to point to null

    1. individual source file will fail to compile because including the header file multiple times without a header guard will result in duplicate definitions

    1. A stream is an abstraction that represents a continuous flow of data between a program (data flows out from a source to a program, then from program to a destination like monitor console) and an input/output (I/O) device, such as a keyboard, screen, file, or network.

  4. Sep 2026
    1. C++ automatically generates an implicit default constructor and an implicit default destructor if you do not define your own.

      (does not need to be defined explicitly for function to work).

      same for deconstructors (however these do not free dynamically allocated memory)

    1. Initially -> p is a pointer storing address of x in STACK;

      After allocating memory dynamically by assigning p =new int; p points to the HEAP memory where the integer is stored;

      *p=20 dereferences p to change value stored in HEAP memory;

      using delete p; we need to put the address we wanna free which is p here, variable storing address on heap;

      however not setting it to a NULL will lead to undefined behaviour when accessed as pointer p continues to point to the same address BUT there is no usable memory, leading to it being a dangling pointer;

      set it to NULL to resolve dangling pointer issue AFTER freeing memory

  5. Mar 2026