ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage   interview questions urls   External Links  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C++  >>  C++ General
 
 


 

 
 STL interview questions  STL Interview Questions
 OOPS interview questions  OOPS Interview Questions
 C++ General interview questions  C++ General Interview Questions
Question
int f() { 
    int I = 12; 
    int &r = I; 
    r += r / 4; 
    int *p = &r; 
    *p += r; 
    return I; 
}  
Referring to the sample code above, what is the return value
of the function "f()"?  
a) 12  
b) 15  
c) 24  
d) 17  
e) 30  
 Question Submitted By :: Ramesh.chaluvadi
I also faced this Question!!     Rank Answer Posted By  
 
  Re: int f() { int I = 12; int &r = I; r += r / 4; int *p = &r; *p += r; return I; } Referring to the sample code above, what is the return value of the function "f()"? a) 12 b) 15 c) 24 d) 17 e) 30
Answer
# 1
ans: 30 i.e 'e'
 
Is This Answer Correct ?    0 Yes 0 No
Guest
 
  Re: int f() { int I = 12; int &r = I; r += r / 4; int *p = &r; *p += r; return I; } Referring to the sample code above, what is the return value of the function "f()"? a) 12 b) 15 c) 24 d) 17 e) 30
Answer
# 2
int I=12;
int &r=I;
here r is a reference to I
 r+=r/4;
=>r=r+r/4;
=>r=12+12/4;[r=I=12]
=>r=12+3
=>r=15
=>I=15

int *p=&r;
so, p is a pointer to r(i.e.,to I)

*p +=r;
=>*p = *p+r
=>*p=15+15
=>*p=30
=>I=30

so the return value of the f() is 30
 
Is This Answer Correct ?    1 Yes 0 No
Uma Sankar Pradhan
 
 
 

 
 
 
Other C++ General Interview Questions
 
  Question Asked @ Answers
 
if i want cin 12345678910 and cout abcdefghij. so how can i create the program?. example : if i key in 8910 so the answer is ghij.  3
what is static function Patni2
What is the difference between operator new and the new operator? Wipro1
What are the differences between public, private, and protected access? Wipro3
Definition of class?  10
implement stack using stack.h headerfile functions Subex1
How to reduce a final size of executable?  1
class Alpha { public: char data[10000]; Alpha(); ~Alpha(); }; class Beta { public: Beta() { n = 0; } void FillData(Alpha a); private: int n; }; How do you make the above sample code more efficient? a) If possible, make the constructor for Beta private to reduce the overhead of public constructors. b) Change the return type in FillData to int to negate the implicit return conversion from "int" to "void". c) Make the destructor for Alpha virtual. d) Make the constructor for Alpha virtual. e) Pass a const reference to Alpha in FillData Quark1
what is importance of data sturture in a programming language? L&T10
Write the program for fibonacci in c++?  3
Brief explaination about #include<iostream.h>, cin and cout  3
Explain the ISA and HASA class relationships. How would you implement each in a class design?  2
const char * char * const What is the differnce between the above two? TCS7
How do you know that your class needs a virtual destructor? Lucent3
Why would you make a destructor virtual? Lehman-Brothers3
What is Memory Alignment? TCS1
Difference between static global and global? Symphony8
What and all can a compiler provides by default? HP3
What are the differences between a struct and a class in C++? Wipro4
class professor {}; class teacher : public virtual professor {}; class researcher : public virtual professor {}; class myprofessor : public teacher, public researcher {}; Referring to the sample code above, if an object of class "myprofessor" were created, how many instances of professor will it contain? a) 0 b) 1 c) 2 d) 3 e) 4 Quark1
 
For more C++ General Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com