Macro in main function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HIRA HAMEED
    New Member
    • Jun 2007
    • 2

    Macro in main function

    hi
    if some one know the asnswer of this question then send me
    thnaks
    macros in which swap two number without using 3rd variable and then call
    Macro in main function
  • DeMan
    Top Contributor
    • Nov 2006
    • 1799

    #2
    Hi HIRA HAMEED,
    Welcome to thescripts. I'm sure you will find a wealth of information available here. At this stage, I am not sure how best to classify your question, so I will pass it to the "Miscellane ous Question" forum. The experts there may have a better idea of what direction to point you in.

    In future, you can access a whole host of forums by selecting from theoptions on the blue bar near the top of the screen.

    I hope the experts can help you out!

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Are you looking for a C/C++ macro? Or is this a macro for an application such as MS Word?

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        Code:
        a = a + b;
        b = a - b;
        a = a - b;

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Check out the XOR Swap Trick.

          Comment

          • Motoma
            Recognized Expert Specialist
            • Jan 2007
            • 3236

            #6
            Originally posted by pbmods
            Check out the XOR Swap Trick.
            You are right, the XOR is much better suited as it will never cause an overflow:
            Code:
            a = a ^ b
            b = a ^ b
            a = a ^ b

            Comment

            • Savage
              Recognized Expert Top Contributor
              • Feb 2007
              • 1759

              #7
              Originally posted by Motoma
              You are right, the XOR is much better suited as it will never cause an overflow:
              Code:
              a = a ^ b
              b = a ^ b
              a = a ^ b
              This will also not cause a overflow.See this thread

              Savage

              Comment

              • Motoma
                Recognized Expert Specialist
                • Jan 2007
                • 3236

                #8
                Originally posted by Savage
                This will also not cause a overflow.See this thread

                Savage
                Well, it does overflow, but in C and C++ that overflow does not matter. However, in other languages you may have an exception thrown causing your program to end prematurely. With an XOR this will not happen.

                Comment

                • Savage
                  Recognized Expert Top Contributor
                  • Feb 2007
                  • 1759

                  #9
                  Originally posted by Motoma
                  Well, it does overflow, but in C and C++ that overflow does not matter. However, in other languages you may have an exception thrown causing your program to end prematurely. With an XOR this will not happen.
                  Well,this is a C/C++ forum after all..

                  :P

                  Savage

                  Comment

                  • Motoma
                    Recognized Expert Specialist
                    • Jan 2007
                    • 3236

                    #10
                    Originally posted by Savage
                    Well,this is a C/C++ forum after all..

                    :P

                    Savage
                    Check again baby, we're in the Miscellaneous forum.

                    Comment

                    • Savage
                      Recognized Expert Top Contributor
                      • Feb 2007
                      • 1759

                      #11
                      Originally posted by Motoma
                      Check again baby, we're in the Miscellaneous forum.
                      Duh!

                      Why did I thought this is C/C++ forum?

                      LOL

                      Comment

                      • Motoma
                        Recognized Expert Specialist
                        • Jan 2007
                        • 3236

                        #12
                        Originally posted by Savage
                        Duh!

                        Why did I thought this is C/C++ forum?

                        LOL
                        Like I have previously stated: you're crazy!

                        Comment

                        • pbmods
                          Recognized Expert Expert
                          • Apr 2007
                          • 5821

                          #13
                          Originally posted by Savage
                          Why did I thought this is C/C++ forum?
                          Because we still don't know what language the original poster is using (hint, hint, HIRA HAMEED...).

                          Comment

                          • Savage
                            Recognized Expert Top Contributor
                            • Feb 2007
                            • 1759

                            #14
                            Originally posted by pbmods
                            Because we still don't know what language the original poster is using (hint, hint, HIRA HAMEED...).
                            Aha,he posted this in C/C++ forum,now I remember.

                            Savage

                            Comment

                            • Motoma
                              Recognized Expert Specialist
                              • Jan 2007
                              • 3236

                              #15
                              Originally posted by Savage
                              Aha,he posted this in C/C++ forum,now I remember.

                              Savage
                              You sure do have all the answers, don't you Savage?

                              Comment

                              Working...