AceTheInterview
Jobs in Pune | Work better in teams | Socialize with friends | Submit Q&A | Tell a friend
Search site for 

Top 100 Interview Questions & Answers in a convenient and easy to read book!

“I bought this guide a few days ago to prepare for my interview with Oracle. Many of the questions they asked me were from this guide. I found this book absolutely great!”

– Ravi, California

Read more comments...

Interview Questions And Answers RSS Feed

Answers »

  1. Submitted By: JV — October 6, 2006
    -8 votes
      + -

    a=a+b;
    b=a-b;
    a=a-b;

  2. Submitted By: DeVyle — October 6, 2006
    -8 votes
      + -

    assume variables are a and b

    a becomes (a XOR b)
    b becomes (b XOR a)
    a becomes (a XOR b)

  3. Submitted By: ruch24 — October 6, 2006
    -5 votes
      + -

    do :
    a=a+b-a
    b=b+a-b

  4. Submitted By: christothes — October 6, 2006
    +0 votes
      + -

    the previous answer is incorrect.
    Consider this:

    a = 2, b = 3

    a = a + b - a;
    3 2 3 2

    b = b + a - b;
    3 3 3 3

    result
    a = 3, b=3

  5. Submitted By: deep — October 6, 2006
    -1 votes
      + -

    a=a+b
    b=a-b
    a=a-b

    will do it withoutextra memory

  6. Submitted By: baboon — October 6, 2006
    +0 votes
      + -

    a = 8; b = 9;

    a = a + b; 17 = 8 + 9;
    b = a - b; 8 = 17 - 9;
    a = a - b; 9 = 17 - 8;

  7. Submitted By: topaz22 — October 6, 2006
    -3 votes
      + -

    NONONONO..
    there’s a very easy way to do this…

    a^=b^=a^=b

    which is
    a = a xor b
    b = b xor a
    a = a xor b

  8. Submitted By: zanic — October 6, 2006
    -2 votes
      + -

    Why does not the following code report integer overflow?

    #include <stdio.h>
    #include <limits.h>

    void main() {
    int a = 1, b = INT_MAX;
    a = a + b; // <— ?
    b = a - b;
    a = a - b;
    printf(”a = %d, b = %d”, a, b);
    }

  9. Submitted By: yzh — October 6, 2006
    -2 votes
      + -

    i believe those answer are not what they expected , the question actually ask you to use bitwise operator such as ^,&, to swap these two integer, think about it, i will give the answer later

  10. Submitted By: Hotshot — October 6, 2006
    -2 votes
      + -

    int main (void)
    {
    int a = 5;
    int b = 7;

    a = a + b - (b = a + b - b);

    cout << “a = ” << a << endl;
    cout << “b = ” << b << endl;

    return 0;
    }

  11. Submitted By: bvreddy — October 6, 2006
    -2 votes
      + -

    This is one more solution 4 it.
    a = a * b;
    b = a / b;
    a = a / b;

    or u can write this in one line as
    a=a*b/(b=a);

  12. Submitted By: JackAss — October 6, 2006
    -2 votes
      + -

    bvreddy - what if b=0???

  13. Submitted By: tranm — October 15, 2006
    +28 votes
      + -

    The question asks how to multiply a variable by 16. I would just shift it left 4 times.

    x = x

  14. Submitted By: tranm — October 15, 2006
    -1 votes
      + -

    Where did the shift operator go? Let me try it again.
    x = x &lt<4;

  15. Submitted By: Victor — October 15, 2006
    +4 votes
      + -

    Assume the Variable is X = 5 and has to be multiplied by Variable Y = 16 [ The will always be the same for any scenario ]

    int main (void)
    {
    int x = 5;
    int y = 16;
    int answer = 0;

    for (int i = 0; i

  16. Submitted By: Victor — October 15, 2006
    +0 votes
      + -

    int main (void)
    { int x = 5; int y = 16; int answer = 0;

    for (int i = 0; i

  17. Submitted By: Ben Hanna — October 16, 2006
    +9 votes
      + -

    Shift its bits 4 to the left.

  18. Submitted By: Kavita — October 20, 2006
    +0 votes
      + -

    Add the variable to itself 16 times. The result would be same as var*16.

  19. Submitted By: Manoj — October 26, 2006
    +2 votes
      + -

    Hey that’s simple,

    Just left shift the variable 4 times are you will get the answer!

    int a = 5;
    printf(”%d”, a

  20. Submitted By: ch — November 17, 2006
    -2 votes
      + -

    just we add the variable 16 times to itself using loop
    that is
    int a=5;
    int b=16;
    for(int i=1;i

  21. Submitted By: Dumb — December 2, 2006
    +10 votes
      + -

    I think that the shift operator suits best here.

    just do 4 left shifts

    if x is the number then

    x in binary x = 00000011

    Doing one left shif
    x = 00000110 …which is 6
    second left shift x = 00001100….which is 12
    third left shift x = 00011000….which is 24
    fourth (and last) left shift x = 00110000 which is 48

    48 is the result..which equal to (x * 16) = (3 * 16)

    Regards

  22. Submitted By: Dumb — December 2, 2006
    not yet rated
      + -

    this editor is dumb too :D

    x = 3, before doing anything

  23. Submitted By: Anand — December 21, 2006
    +4 votes
      + -

    Just shift 4 bits to left.
    Or divide by 0.0625.

  24. Submitted By: bose O — January 4, 2007
    +0 votes
      + -

    assume the variable is a
    int main(void)
    {
    int a = 6; //anyvalue can be used
    int sum = 0;
    for (i =0; i

  25. Submitted By: psp — January 6, 2007
    not yet rated
      + -

    There is a very simple trick in C:
    // a is the int. to be multiplied x16
    // a16 will hold the result
    int a16 = 4

  26. Submitted By: nadster — April 9, 2007
    +1 votes
      + -

    just do bit shifts…

    x= x

  27. Submitted By: nadster — April 9, 2007
    not yet rated
      + -

    sorry…my previous post has something wrong in it..

    it’s “x=x

  28. Submitted By: xyz — May 6, 2007
    +2 votes
      + -

    ROFL, you’re all horrible programmers. only like two people got this question. the answer has to do with bit shifting, as its clearly hinted by the base2 multiplication number (16)

    no one will hire you if you give that silly +- thing

  29. Submitted By: FC — May 16, 2007
    +3 votes
      + -

    Do a left shift 4 times, i.e. x

  30. Submitted By: ram — May 23, 2007
    +1 votes
      + -

    Guys! Why don’t you think simple..

    Just divide the variable by 1/16

    a / (1/16)

    a/0.0625

    :-)

  31. Submitted By: johnson — July 23, 2007
    not yet rated
      + -

    binary format of 5 is

    x in binary x = 00000101

    And it is not 00000011.

  32. Submitted By: Vishal — August 1, 2007
    not yet rated
      + -

    Hey Guys! Understand the problem as it is. Do not think much. Do simply:

    somevariable = x;
    x

  33. Submitted By: saurabh rai — August 26, 2007
    +1 votes
      + -

    suppose variable is A

    now to multiply it by 16 do the following

    for(i=0;i

  34. Submitted By: Indian_analyst — October 17, 2007
    +1 votes
      + -

    Left Shift the variable 4 times.

  35. Submitted By: Ankur — December 7, 2007
    not yet rated
      + -

    #include

    int main(void)
    {
    int n,i;
    int mul=0;

    printf(”\nEnter the number to be multiplied by 16: “);
    scanf(”%d”, &n);

    for(i=0;i

  36. Submitted By: Ankit — January 14, 2008
    not yet rated
      + -

    If I need to multiply a small integer value by 16 in C/C++

    answer = var

  37. Submitted By: JDB — February 8, 2008
    +1 votes
      + -

    Divide by 1/16.

    Answer = Varibale / (1/16)

  38. Submitted By: Anjali — February 17, 2008
    +1 votes
      + -

    Shift it left by 4 bits
    Or
    Add the number 16 times

  39. Submitted By: harry — March 6, 2008
    +1 votes
      + -

    main()
    {
    long int i;
    printf ( “\n Enter the number ” ) ;
    scanf( “%ld”,&i);

    i=i

  40. Submitted By: TIRED — March 25, 2008
    not yet rated
      + -

    int x,i;
    int a=0;

    for i = 1 to 16
    {
    a=x+a;
    }
    print a;

  41. Leave an Answer/Comment

    To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
    Click to hear an audio file of the anti-spam word

Our Sponsors
Our Sponsors
Contact Us | FAQ | Sitemap | Terms of Use | Privacy Policy | Tell a Friend

Copyright © 1999-2006 Jeeve Technologies LLC. All rights reserved.