CCNA Certificate Program Online Training by Top US Institute. Flexi Timings, Personalized Support.

CoolInterview.com - World's Largest Collection of Interview Questions GET FREE MAGAZINE FROM SAP NOW!
Home| Ask Questions| About Us| Feedback| Contact Us|
 Interview Questions  
 Our Services  

Get 9,000 Interview Questions & Answers in an eBook.


  • 9500+ Pages
  • 9000 Question & Answers
  • All Tech. Categories
  • 14 MB Content

    Get it now !!



    Send your Resume to 6000 Companies

  • COOLINTERVIEW.COM DATABASE DETAILS



    Question :
    void main()
    {
    int x=5;
    printf("%d,%d,%d
    ",x,x<<2,x<<2);
    }
    what is the ans. of this question and how?
    please explain it.


     Posted by: deepak pareek    Date: 8/18/2008

    Contact Author  Contact Author


    Answer :
    The answer would be

    5 20 20

    as x = 5 so first %d gives 5

    second %d will take value of x after left shifting it twice, and shifting is done after converting the values to binary, binary value of 5 (000101)will be left shifted twice to make it binary 20(0010100), so x<<2 is 20

    and as left shifting does not effect the original value of x its still 5 so third %d will also show 20.

    Thanks

     Posted by: Vishwas Rathi    

    Contact Author  Contact Author
    Look..........
    Inside printf function the expression are evaluated Right to Left.
    Hence first rightmost x<<2 will be executed
    then x<<2 in middle
    and
    at last x.
    << is the left shift operator which shifts bits of a number to left.
    So value of x<<2 when x=5 will be
    20; value of x changes to 20
    Again x<< 2 , when x=20 makes x=80;
    So values will be pinted in output screen as:
    80,80,20

     Posted by: Pranjal Gururani    

    Contact Author  Contact Author
    answer is
    5,20,20

    Since << is a left shift operator, and left shifting by one bit multiplies the number by 2, left shifting by 2 bits multiplies the number by four. However the original number is not assigned withe the new value.

    Hence 5<<2 = 20
    However teh value of x doesnt not change..
    Hence the expression is like,
    print("%d,%d,%d",5,5<<2,5<<2)
    which will display 5,20,20

     Posted by: ram    

    Contact Author  Contact Author
    5 is 101
    5<<1 left shift by 1 1010 i.e 10
    5<<2 left shift by 2 10100 i.e 20

     Posted by: sivaji    

    Contact Author  Contact Author
    ans:5,20,20
    because the << operator gives the product of the left integer(i.e x=5) and the maximum number of possible binary numbers that can be obtained for the given right integer.(i.e 2)

    using two binary bits we can create four different combinations.If the given number is 3 then the number of possible combinations is 2^3=8.
    so the expression x<<2 gives X*2^2.

    lly The expression x<<3 gives x*2^3.

    In the same way the expression x>>2 gives x/2^2


     Posted by: Mugilvannan    

    Contact Author  Contact Author

    © CoolInterview.com
    Today's Special: Get Free Magazine from SAP now!

    A D V E R T I S E M E N T






    If you have the better answer, then send it to us. We will display your answer after the approval.
    Name :*
    Email Id :*
    Answer :*
    Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
    Process Verification  Enter the above shown code:*
    Inform me about updated answers to this question

       


    Rate the above answer. Help us to know about the answer.
    Category Database Interview Questions
    Rating (5.0) By 2 users
    Added 8/18/2008
    Views 183
    Rate it!
    Free Offers 300 Free Magazines for you. No credit card required. No Shipping Charges. Absolutely Free for 1 Year.

    Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.

    Notify me when better answer is posted!
    Email:

    View ALL Database Interview Questions


    Sponsored Links  




    Latest 10 Questions
     Which language has better scope Java or asp.net or c# why?
     I want to create a project named 'To run sql create command through asp.net with graphical view' how to work for that?
     What is type integration? And what is integer type integration?
     The University authority wants to process employees? information using stack data structure. Define a suitable data type for the employee and all possible stack primitives using dynamic implantation. Also write necessary test driver codes to test all the primitives?
     Define a suitable data type for the PGD students. Define the two queue operations using dynamic implementation: one to add student and the other to remove student from the queue. Write necessary test driver codes to test the above two operations?
     Define a class to represent a bank account. In the class, include the following members: Data members: name of the depositor, account number, type of account, and balance amount in the account. Member functions: to assign initial values, to deposit an amount, to withdrawal an amount after checking the balance, and to display the name and balance. Write main() code to test your class?
     Define a class named cord, a point in Cartesian coordinate system where each point has two int type values x and y. Your class must contain necessary constructors and arithmetic operator functions. Write necessary codes to test your class?
     What does inheritance means in C++? What are the different forms of inheritance? Give an example for each.
     Can we have more than one constructor in a class? If yes, explain the need for such a situation.
     What is Intel 8085?enumerate the different instruction format of 8085 with suitable examples .

    Google Search

    Google

    CoolInterview.com is a part of Vyom Network.
    Copyright ©2003-2008 Vyom Technosoft Pvt. Ltd., All Rights Reserved. Privacy Policy
    Page URL: http://www.coolinterview.com/interview/15837/Default.asp?cachecommand=bypass


    Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial

    1.05