Thread: A lil confused

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    14

    A lil confused

    Need to know how the following code would function...

    Code:
    #include<stdio.h>
    int main()
    {
    int i=7;
    printf("%d",i++*i++);
    }
    for the above mentioned the output is 56
    if i were to change it to
    Code:
    printf("%d",i++*i)
    still the same output
    Code:
    printf("%d",++i*i++)
    outputs it as 64

    Cant figure out how its going about executing the statement, would appreciate help on this.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    http://c-faq.com/expr/index.html
    It's undefined.

    In short, if you modify the same variable twice, or modify and read the variable, then all bets are OFF as to what actually happens.

    Follow that link to further read up on something called "Sequence Points".
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Confused about Memory
    By gL_nEwB in forum C++ Programming
    Replies: 22
    Last Post: 06-20-2006, 07:32 PM
  2. Confused
    By (TNT) in forum C# Programming
    Replies: 1
    Last Post: 11-23-2005, 04:49 PM
  3. why wont this compile?!? :confused:
    By jdude in forum C++ Programming
    Replies: 5
    Last Post: 11-25-2004, 01:13 AM
  4. confused.. in selecting my line of deapth
    By jawwadalam in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 05-04-2003, 01:21 PM
  5. Extern Question, really confused
    By SourceCode in forum C Programming
    Replies: 10
    Last Post: 03-26-2003, 11:11 PM