Good interview Questions

This is a discussion on Good interview Questions within the C Programming forums, part of the General Programming Boards category; Code: int main() { int x=5; printf("%d,%d,%dn",x,x< <2,x>>2); } Answer: 5,20,1 For the above code i complied and the answer ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    4

    Good interview Questions

    Code:
    int main()
    {
            int x=5;
    
             printf("%d,%d,%dn",x,x< <2,x>>2);
    
    }
    Answer: 5,20,1


    For the above code i complied and the answer also given

    MY Expected output was :5,5,1

    But after compling the output was :5,20,1

    I didn't understand the logic for that output obtained

    Can anybody give the reason for that output

    Thanking You,
    V.Rupendra Naidu

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,968
    I would expect a compile error, but it is probably due to a typographical error on your part (x< <2 should be x << 2). Why do you think the second integer to be printed should be 5 instead of 20?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    4

    Thanks for reply

    Hi,
    i saw the solution that was given by you, i understand the logic .

    Thanks for spending your valuable time with me

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Good Programming schools are they out there???
    By jbarby in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 05-12-2009, 06:31 PM
  2. Any good tutorials?
    By kimmag in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2008, 06:44 AM
  3. What are some good books on C?
    By php111 in forum C Programming
    Replies: 9
    Last Post: 10-01-2008, 06:16 AM
  4. linked list recursive function spaghetti
    By ... in forum C++ Programming
    Replies: 4
    Last Post: 09-02-2003, 02:53 PM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21