-2

Is it possible to add two numbers without using any arithmetic or logical operators?

If so, how do I do it?

Solution:

main(){ 
  int x=10,y=21; 
  char *p=x; 
  printf("%d" , &p[y]); 
}

Atleast do not downvote this question as u didnt get the answer.

behinddwalls
  • 644
  • 14
  • 39
  • 4
    Is this out of personal interest, or something like an interview question? Anyways, I'm tired at the moment, and all I can think of is inline assembly. – chris May 02 '12 at 06:18
  • i dont know...some1 asked me ..& i think its solution exists...but i dont know...wat it is – behinddwalls May 02 '12 at 06:19
  • Sounds like homework or interview question ... if so, please tag it that way. – vdbuilder May 02 '12 at 06:21
  • 2
    This type of questions has been posed many times. Please use the search tool before posting. Possible duplicate of [How to add two numbers without using ++ or + or another arithmetic operator](http://stackoverflow.com/questions/1149929/how-to-add-two-numbers-without-using-or-or-another-arithmetic-operator) – Jens Gustedt May 02 '12 at 06:22
  • @JensGustedt Not a dupe. This one also forbids logical operators. – Mysticial May 02 '12 at 06:23
  • @Mysticial, I don't have the impression that the question is as precisely posed as you suggest. In the contrary, I don't think that he has looked much around before posing it. – Jens Gustedt May 02 '12 at 06:25
  • guys .. wait.. this is valid question & for better answer dis1 ... i think i have searched everywhere but didn't got the answer for this one.. and it doesn't allow u to use logical operator as well – behinddwalls May 02 '12 at 06:29
  • i got 1 more answer for this.. `main(){ int x=10,y=21; char *p=x; printf("%d" , &p[y]); }` – behinddwalls May 02 '12 at 06:39

1 Answers1

5
int add(int x, int y) {
    std::vector<int> v(x);
    std::vector<int> u(y);
    for(auto& n : u) {
        v.push_back(n);
    }
    return v.size();
}
R. Martinho Fernandes
  • 228,013
  • 71
  • 433
  • 510