Sample Questions Best site for GRE, LSAT, SAT, GMAT, TOEFL, CCNA, CCSA and interview sample questions  

Technical Sample Questions : C |  C++ |  Oracle |  Java | Unix |  Operating Systems |  Data Structure

Sample Technical Questions

C++ and OOPS Sample Question

  1. class complex{
    	double re;
    	double im;
    public:
    	complex() : re(1),im(0.5) {}
    	bool operator==(complex &rhs);
    	operator int(){}
    };
    
    bool complex::operator == (complex &rhs){
    	if((this->re == rhs.re) && (this->im == rhs.im))
    		return true;
    	else
    		return false;
    }
    
    int main(){
    	complex  c1;
    	cout«  c1;
    }

    Answer :

    Garbage value

    Explanation :

    The programmer wishes to print the complex object using output re-direction operator,which he has not defined for his lass.But the compiler instead of giving an error sees the conversion function and converts the user defined object to standard object and prints some garbage value.
  2. class complex{
    	double re;
    	double im;
    public:
    	complex() : re(0),im(0) {}
    	complex(double n) { re=n,im=n;};
    	complex(int m,int n) { re=m,im=n;}
    	void print() { cout«re; cout«im;}	
    };
    
    void main(){
    	complex c3;
    	double i=5;
    	c3 = i;
    	c3.print();
    }

    Answer :

    5,5

    Explanation :

    Though no operator= function taking complex, double is defined, the double on the rhs is converted into a temporary object using the single argument constructor taking double and assigned to the lvalue.
  3. void main()
    {
    	int a, *pa, &ra;
    	pa = &a;
    	ra = a;
    	cout «"a="«a «"*pa="«*pa «"ra"«ra ;
    }

    Answer :

    Compiler Error: 'ra',reference must be initialized

    Explanation :

    Pointers are different from references. One of the main differences is that the pointers can be both initialized and assigned, whereas references can only be initialized. So this code issues an error.

    « Previous || Next »

    C++ Sample Question number : 1-3 | 4-7 | 8-10 | 11-13 | 14-21 | 22-28 | 29-35 | 36-42 | 43-49 | 50-54 | 55-58 | 59-66 | 67-73 | 74-80
Sample Test Questions
GRE Sample Questions
CAT Sample Questions
GMAT Sample Questions
TOEFL Sample Questions
ACT Sample Questions
SAT Sample Questions
LSAT Sample Questions
PSAT Sample Questions
MCAT Sample Questions
PMP Sample Questions
GED Sample Questions
ECDL Sample Questions
DMV Sample Questions
CCNA Sample Questions
MCSE Sample Questions
Network+ Sample Questions
A+ Sample Questions
Technical Sample Questions
WASL Sample Questions
CISA Sample Questions

Other Sample Questions
Sample Interview Questions
Sample Teacher Interview Questions
Sample Citizenship Questions
Accuplacer Sample Questions
Science Bowl sample Questions
Driving Test Sample Questions
Sample Survey Questions Sample Essay Questions
Sample Behavioral Interview Questions

Copyright © 2004-2013, Best BSQ. All Rights Reserved.