How Does Increment Operators Work...??

This is a discussion on How Does Increment Operators Work...?? within the C Programming forums, part of the General Programming Boards category; got it guys got it thX a lot....veeeeee...

  1. #16
    Registered User
    Join Date
    Feb 2008
    Location
    PUNE
    Posts
    23
    got it guys got it thX a lot....veeeeee

  2. #17
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,635
    Quote Originally Posted by matsp View Post
    That is incorrect. I posted the correct variant in post #3. Note that the third reference to b is "b++", so it takes "b-1" derived from --b, then restores b's value.
    I also noted that we can just as well write:
    a = 7*b - 4
    Well, I was guessing. I didn't know how the actual formula was without the ++ and --.
    It was my best guess.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
    a = 2*b + (b-1) + 3*(b-1) +b
    So, instead of using --b and b++, I replace them with the value that IS correct for b in each place (assuming we think that 17 _IS_ the correct answer here - since the original expression is technically undefined, there is no "right" or "wrong" answer to that expression - it can be -46, 4118923791231, 17, 14, 19 or some other value with b = 3 to start with).

    Then we use normal algebra rules to simplify the expression, so
    2 * b + (b -1) can be made into 3 * b - 1.
    3 * (b - 1) + b can be made into 4 *b - 3
    3 * b - 1 + 4 * b - 3 can be simplified into 7 *b - 4.

    Does that make more sense to you. And by the way (appologies if you suffer from some injury or such that), but could you perhaps try to write complete words, correctly spelled (as best as you can) - it is fairly hard for someone who uses English in daily life to read "ne1" as "anyone", etc, and I don't think the people who don't even use english daily will have an EASIER task with it. It makes you look lazy and ill educated - which may be true, but if so, perhaps you can try to hide it when you are posting here

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #19
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,635
    Quote Originally Posted by matsp View Post
    2 * b + (b -1) can be made into 3 * b - 1.
    3 * (b - 1) + b can be made into 4 *b - 3
    3 * b - 1 + 4 * b - 3 can be simplified into 7 *b - 4.
    I find it easier to simply think and write it as
    2b + (b - 1) = 3b - 1
    3(b - 1) + b = 3b - 3 + b = 4b - 3
    3b - 1 + 4b - 3 = 3b + 4b - 1 - 3 = 7b - 4

    Quote Originally Posted by matsp
    so
    I think you misspelled there too
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #20
    Registered User
    Join Date
    Feb 2008
    Location
    PUNE
    Posts
    23
    Thanks a lot matsp
    you are genious....!!

  6. #21
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Elysia View Post
    I think you misspelled there too
    Using a Swedish keyboard when normally using a US/UK style layout makes them things happen sometimes...



    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #22
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,635
    Genius? It's basic algebra, something that everyone should be able to use.
    I think it is you, my friend, who simply are "ingenious"

    Quote Originally Posted by matsp View Post
    Using a Swedish keyboard when normally using a US/UK style layout makes them things happen sometimes...

    Eh, I say get rid of the UK/US keyboard and use all swedish keyboards! They are far better than US keyboards
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #23
    Registered User
    Join Date
    Feb 2008
    Location
    PUNE
    Posts
    23
    i ll check on different cases hope it ll work true in all cases

  9. #24
    Registered User
    Join Date
    Feb 2008
    Location
    PUNE
    Posts
    23
    As i m new to this so
    One day i ll surely fly

  10. #25
    Registered User
    Join Date
    Feb 2008
    Location
    PUNE
    Posts
    23
    please tell me for this expresion :
    a = (b++) + (- - b) + (b - -) + b
    here b = 4
    tell me manually ans : i am getting 15
    by applying your logic i am gettin 17
    plz check.....!!
    Last edited by ajayd; 02-06-2008 at 08:50 AM.

  11. #26
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,781
    hk_mp5kpdw already answered you in the first reply: it is undefined behaviour. You could get 15, you could get 17, or you could get your computer blown up.

    EDIT:
    Though I am assuming that you actually fix the statement to become:
    Code:
    a = (b++) + (--b) + (b--) + b;
    or at least:
    Code:
    a = (b++) + (- - b) + (b--) + b;
    Last edited by laserlight; 02-06-2008 at 08:51 AM.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #27
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,635
    Just algebra and...
    Stop using -- and ++ in complex operations!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #28
    Registered User
    Join Date
    Feb 2008
    Location
    PUNE
    Posts
    23
    plz check this is a different case in 1st case only decrement operators were used in this case both decrement as well as increment operators are used

  14. #29
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,635
    It does not matter.
    n++
    n--
    Is fine.
    n + b-- + n++
    is not.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #30
    Registered User
    Join Date
    Feb 2008
    Location
    PUNE
    Posts
    23
    if the given expression is itself in that form and asked to program on it then how to convert it
    if i convert it using algebra i am getting different answers compared to the manual answers so

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  2. Problems in getting OpenGL to work
    By zonf in forum C Programming
    Replies: 5
    Last Post: 02-13-2006, 03:48 AM
  3. Why won't my OpenGL work?
    By Raigne in forum C++ Programming
    Replies: 7
    Last Post: 11-26-2005, 10:53 AM
  4. Developers Wanted
    By Quasicom in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 08-24-2005, 12:46 AM
  5. Overloading Operators
    By Strahan in forum C++ Programming
    Replies: 4
    Last Post: 09-07-2001, 11:39 AM

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