Tuesday, 31 March 2015

Limitations of Increment and Decrement Operators

The prefix notation causes a variable to be updated before its value is used in the expression, whereas the postfix notation causes it to be updated after its value is used. However the statements

X1 = A++; and X2 = ++A has exactly the same effect;

When ++ and – operator are overloaded, there is no distinction between the prefix and postfix overloaded operator function.

This problem is avoided in the implementation of C++, which provides addition syntax to express and distinguish between prefix and postfix overloaded operator function. The syntax for overloaded operator function is

Return_type operator++(int)

Sample Program

#include <iostream.h>
class post
{
int val;
public:
post(void)
{
val = 1;
}
int operator++(void)
{
return (++val);
}
int operator++(int)
{
return(val++);
}
};
void main()
{
int x1, x2;
post A;
x1 = A++;
x2 = ++A;
cout<<”x1 is “<<x1<<endl;
cout<<”x2 is “<<x2<<endl;
}

5 comments:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai.

    ReplyDelete
  2. I found your blog while searching for the updates, I am happy to be here. Very useful content and also easily understandable providing..
    Believe me I did wrote an post about tutorials for beginners with reference of your blog. 




    Selenium training in bangalore
    Selenium training in Chennai
    Selenium training in Bangalore
    Selenium training in Pune
    Selenium Online training

    ReplyDelete
  3. Whoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.thanks lot!!

    android training in chennai

    android online training in chennai

    android training in bangalore

    android training in hyderabad

    android Training in coimbatore

    android training

    android online training

    ReplyDelete
  4. I just loved your article on the beginners guide to starting a blog.If somebody take this blog article seriously in their life, he/she can earn his living by doing blogging.thank you for thizs article.

    web designing training in chennai

    web designing training in velachery

    digital marketing training in chennai

    digital marketing training in velachery

    rpa training in chennai

    rpa training in velachery

    tally training in chennai

    tally training in velachery

    ReplyDelete