Thread: help! please!!!

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    2

    help! please!!!

    hello guys.. i need to write a program in C, to exchange 2 variables without using any arithmetic operators.. can any one help me please.. this is kinda urgent!!!

  2. #2
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    What have you tried so far?

    Quote Originally Posted by binduchowdary91 View Post
    hello guys.. i need to write a program in C, to exchange 2 variables without using any arithmetic operators.. can any one help me please.. this is kinda urgent!!!
    You may find some use in reading Lesson 6: Pointers.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  3. #3
    Registered User
    Join Date
    Sep 2011
    Posts
    2
    thnx 4 d help! i did it!

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > to exchange 2 variables without using any arithmetic operators
    Weird - the usual trick to this question is to swap things without using a temporary variable.

    Since you wouldn't normally use arithmetic operators to swap things anyway, perhaps all you need is
    temp = a ; a = b ; b = temp;

    See - no arithmetic there
    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