plzzz explain me this stuff?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chaitrali1993
    New Member
    • Jun 2014
    • 2

    plzzz explain me this stuff?

    main()
    {
    void swap();
    int x=10,y=8;
    swap(&x,&y);
    printf("x=%d y=%d",x,y);
    }
    void swap(int *a, int *b)
    {
    *a ^= *b, *b ^= *a, *a ^= *b;
    }
    Answer:
    x=10 y=8
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    Can you tell me what ^= does?
    Can you tell me what the commas do in the last line of code?

    Comment

    • chaitrali1993
      New Member
      • Jun 2014
      • 2

      #3
      i am asking u same :(

      Comment

      • donbock
        Recognized Expert Top Contributor
        • Mar 2008
        • 2427

        #4
        Please refer to the rules regarding Posting Homework or Coursework Questions and Answers. I don't think I'm permitted to merely give you the answer. I can walk you through it, but you need to be actively involved.

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          What programming language is this?

          If the answer is x=10 and y = 8 and at the beginning x =10 and y=8, then this code doesn't work.

          Comment

          • donbock
            Recognized Expert Top Contributor
            • Mar 2008
            • 2427

            #6
            Perhaps you meant the printed result is "x=8, y=10".

            General problems with your code that don't actually involve its function.
            • Function main should return int. This means you need a return statement at the end of main.
            • The declaration of swap should be before the beginning of main; and it should be a function prototype that specifies the types of the arguments.
            • The printf format string should end with a newline because stdout is typically a buffered stream.

            Comment

            Working...