increment and decrements ! help required :| with full explanation..12 7 how????????

This is a discussion on increment and decrements ! help required :| with full explanation..12 7 how???????? within the C Programming forums, part of the General Programming Boards category; insert Code: #include<stdio.h> int main() { int a = 5, b=6; a-= (--a) - (a--); a = (--a) - (a--); ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    1

    Exclamation increment and decrements ! help required :| with full explanation..12 7 how????????

    insert
    Code:
    #include<stdio.h>
    
    int main()
    {
     int a =  5, b=6;
     a-= (--a) - (a--);
     a = (--a) - (a--);
     a = (++a) + (++a);
     a = ++a + a-- + ++b;
     printf ("a = %d  and b = %d\n" , a,b);
    }

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,616
    From the C Language standard, section 6.5:
    ----------
    2. Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. 72) Furthermore, the prior value shall be read only to determine the value to be stored. 73)

    ...

    72) A floating-point status flag is not an object and can be set more than once within an expression.

    73) This paragraph renders undefined statement expressions such as

    i = ++i + 1;
    a[i++] = i;

    while allowing

    i = i + 1;
    a[i] = i;
    -------------
    Exactly how a particular result is produced will vary from platform to platform, and may depend on everything from the surrounding code to compiler options.
    Devoted my life to programming...

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    It's worse than "it depends", it's totally undefined.
    Question 3.2

    Abandon hope all ye who enter here - there be dragons!
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Nov 2011
    Location
    Douala, Cameroon
    Posts
    187
    some are pre and post incrementation and decrementation and all of them have values depending on the preceding values

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Post Increment an Pre Increment operators in c++
    By anil_ in forum C++ Programming
    Replies: 4
    Last Post: 11-12-2011, 07:27 PM
  2. full size of the window, full screen mode
    By nerio in forum C Programming
    Replies: 4
    Last Post: 07-20-2011, 05:25 PM
  3. Lvalue required as increment operand
    By .C-Man. in forum C Programming
    Replies: 4
    Last Post: 10-13-2010, 02:41 PM
  4. lvalue required as increment operand compile error
    By canadatom in forum C Programming
    Replies: 8
    Last Post: 06-13-2009, 11:49 AM
  5. Explanation required (Why?)
    By pritin in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2007, 08:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21