Thread: post increment gives trouble !

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    32

    post increment gives trouble !

    the following thing works normal swapping: but
    if change function call to

    swap(a++,b++);
    it dos'nt work why?

    Code:
    #include<stdio.h>
    #include<conio.h>
    void swap(int&, int&);
    int main()
    {
    int a = 10,b=20;
    swap(++a,++b);
    printf("\n%d\t%d\t",a, b);
    getch();
    return 0;
    
    }
    void swap(int& x, int& y)
    {
    x+=2;
    y+=3;
    }
    thanx!!

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Think about it, when is post increment done compared to pre increment?

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    And just so you know, you code in C++ with C headers, references does not exist in C.
    STL Util a small headers-only library with various utility functions. Mainly for fun but feedback is welcome.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,662
    Well I must say this "fall asleep on the keyboard" and compile it approach you seem to have to learning C (or is it C++ - do let us know which it is) isn't working out too well.

    Whatever (or whoever) you're learning from is an idiot. There is no logic to any of your questions, just queries about how the latest bit of undefined behaviour is confusing you. You might think this will make you a programmer, but from where I'm sitting, you're heading in the wrong direction. Sure you might spoof your way through a few simple aptitude tests, but when it comes to writing real programs, you'll be out of luck.
    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. need help with HTTP POST
    By Anddos in forum Networking/Device Communication
    Replies: 5
    Last Post: 03-22-2009, 08:41 AM
  2. Post your Best Text Adventure
    By Joe100 in forum Game Programming
    Replies: 3
    Last Post: 08-15-2003, 05:47 PM
  3. Post increment and pre increment help
    By noob2c in forum C++ Programming
    Replies: 5
    Last Post: 08-05-2003, 03:03 AM
  4. Auto POST
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 06-07-2003, 10:42 AM