Answered Questions

  • Unary Postfix Operator Overloading

    Which of the following statements accurately describe unary postfix operator++ overloading in C++?A. It can be overloaded with no parameters when the operator function is a class member.B. It can only be overloaded if the operator function is a class member.C. It can be overloaded with one parameter when the operator function is free standing function (not a class member).D. To overload it at least...

    preethi

    • Sep 14th, 2013

    D

    ajrobb

    • Sep 22nd, 2010

    DA. It can be overloaded with no parameters when the operator function is a class member.No. As a class member it must have one dummy parameter:class A { A operator++(int); }; B. It can only be over...

  • Register Relation

    Why p++ is faster than p+1?

    Star Read Best Answer

    Editorial / Best Answer

    sahasranaman  

    • Member Since Jul-2009 | Jul 1st, 2009


    p++ is faster because on compilation, it gets translated to three machine instructions, where as p=p+1 needs four machine instructions. All machine instructions take the same time.

    For p++, the instructions are:
    mov ax,
    inc ax
    mov,
    ax

    For p = p+ 1, the instructions would be,
    mov ax,
    mov bx, 1
    add bx
    mov,
    ax

    This is why p++ is faster than p+1