Thread: increment operator

  1. #1
    Registered User
    Join Date
    Nov 2019
    Posts
    66

    increment operator

    What's the main difference between two operators in the codes

    Code:
    #include<stdio.h>
    
    int main ()
    {
       int A = 1;
        A++;
       
       printf(" A = %d ", A);
    
    
        return 0;	
    }
    Output : A = 2

    Code:
    #include<stdio.h>
    
    int main ()
    {
       int A = 1;
        ++A;
       
       printf(" A = %d ", A);
    
    
        return 0;	
    }
    Output : A = 2

    Both operators gives same output

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,941
    In this context, i.e., when they are used standalone, there is effectively no difference. The differences only matter when they are used as part of a larger expression.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Increment operator
    By ssharish2005 in forum C Programming
    Replies: 8
    Last Post: 06-06-2011, 04:32 PM
  2. Increment Operator
    By theunderdog118 in forum C Programming
    Replies: 4
    Last Post: 05-31-2010, 11:00 AM
  3. Increment Operator
    By anirban in forum C Programming
    Replies: 5
    Last Post: 11-25-2008, 08:25 AM
  4. Help with increment operator
    By capvirgo in forum C Programming
    Replies: 2
    Last Post: 02-18-2008, 11:06 PM
  5. Help with increment operator, please
    By capvirgo in forum C Programming
    Replies: 4
    Last Post: 02-18-2008, 07:06 PM

Tags for this Thread