what is difference between ++i and i+=1 from any point of view

前端 未结 7 570
一个人的身影
一个人的身影 2021-01-03 06:10

This is a question from kn king\'s c programming : a modern approach. I can\'t understand the solution given by him:-

The expression ++i is equivalent to (i          


        
7条回答
  •  我在风中等你
    2021-01-03 06:32

    i = 10
    printf("%d", i++);
    

    will print 10, where as

    printf("%d", ++i);
    

    will print 11

    X = i++ can be thought as this

    X = i
    i = i + 1
    

    where as X = ++i is

    i = i + 1
    X = i
    

    so,

    printf ("%d", ++i); 
    

    is same as

    printf ("%d", i += 1);
    

    but not

    printf ("%d", i++);
    

    although value of i after any of these three statements will be the same.

提交回复
热议问题