C++ Programming Multiple Choice Questions - References

This section focuses on the "References" in C++ programming langauge. These Multiple Choice Questions (MCQ) should be practiced to improve the C++ programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

1. Reference is like a?

A. Pointer
B. Structure
C. Array
D. None of the above

View Answer


2. A References is :

A. A variable that holds memory address.
B. A Alias to an existing variable.
C. Alias to an existing variable and holds memory address.
D. None of the above

View Answer


3. A variable can be declared as reference by putting _______ in the declaration.

A. #
B. $
C. &
D. *

View Answer


4. If a function receives a reference to a variable, can it modify the value of the variable?

A. Yes
B. No
C. We can not pass reference to a variable.
D. Reference can not contain function.

View Answer


5. Through references we can avoid?

A. wastage of memory
B. wastage of CPU time
C. Both A and B
D. None of the above

View Answer


6. References can be NULL?

A. References has constant value 0.
B. References has constant value .
C. Yes.
D. No.

View Answer


7. How many objects reference can refer during its lifetime?

A. 1
B. 2
C. 3
D. 4

View Answer


8. Dereference operator is also called as

A. pointer
B. Reference operator
C. Offset operator
D. Deoffset operator

View Answer


9. Which operator is used to de-references to an object?

A. #
B. &
C. *
D. None of the above

View Answer


10. Which of the following is an advantage of reference?

A. Safer
B. Easier to use
C. Time consuming
D. Both A and B

View Answer


11. What is the return value of f(p, p) if the value of p is initialized to 5 before the call? Note that the first parameter is passed by reference, whereas the second parameter is passed by value.

#include <iostream>
using namespace std;

int LFC(int &x, int c)
{
    c  = c - 1;
    if (c == 0) return 1;
    x = x + 1;
    return LFC(x, c) * x;
}
int main()
{
    int p = 5;
    printf("%d", LFC(p, p));
}

A. 3024
B. 6561
C. 55440
D. 161051

View Answer


12. What is the output of this program?

#include <iostream>
using namespace std;

int &LFC()
{
    static int p = 10;
    return p;
}
int main()
{
    LFC() = 30;
    cout << LFC();
    return 0;
}

A. Compiler Error: Function cannot be used as lvalue
B. 10
C. 30
D. 20

View Answer


13. What is the output of this program?

#include <iostream>
using namespace std;

int &LFC()
{
    int p = 10;
    return p;
}
int main()
{
    LFC() = 30;
    cout << LFC();
    return 0;
}

A. May cause runtime error
B. May cause compiler error
C. Always works fine
D. 0

View Answer


14. Which of the following statement is correct about the program given below?

#include <iostream>
using namespace std;

int main()
{
  int p = 10;
  int& q = p;
  q = 20;
  cout << "p = " << p << endl ;
  p = 30;
  cout << "q = " << q << endl;
  return 0;
} 

A. p=20 q=30
B. p=20 q=20
C. p=10 q=30
D. p=30 q=30

View Answer


15. Which of the following is true about the following program

#include <iostream>
using namespace std;

int main()
{
    int p = 45; 
    int &q = p;
    p++;
    cout << p << " " << --q;
    return 0;
}  

A. The program will print the output 45 45.
B. The program will print the output 46 40.
C. The program will print the output 46 46.
D. It will result in a compile time error. View Answer

View Answer


16. What will be the output of this program?

#include <iostream>
using namespace std;

int main()
{
    int p = 45; 
    int q& = p;
    p++;
    cout << p << " " << --q;
    return 0;
}

A. The program will print the output 45 45.
B. The program will print the output 46 40.
C. The program will print the output 46 46.
D. It will result in a compile time error.

View Answer


17. What will be the output of this program?

#include <iostream>
using namespace std;

int main()
{
    int p = 10, q = 20;
    int *ptr = & p;
    int &ref = q;

    *ptr++;
     ref++;    

    cout<< p << " " << q;
    return 0; 
}

A. The program will print the output 10 20.
B. The program will print the output 10 21.
C. The program will print the output 11 20.
D. The program will print the output 11 21.

View Answer


18. What will be the output of the following program?

#include <iostream>
using namespace std;

enum find
{
    a, b, c
};
int main() 
{
    int x = a, y = b, z = c;
    int &p = x, &q = y, &r = z;
    p = ++x;
    q = ++y;
    r = ++c;
    cout<< p << q << r;
    return 0;
}  

A. The program will print the output 1 2 3.
B. The program will print the output 2 3 4.
C. The program will print the output 0 1 2.
D. It will result in a compile time error.

View Answer


19. What will be the output of the following program?

#include <iostream>
using namespace std;


class LFC
{
    int x, y; 
    public:
    void SetValue(int &xx, int &yy)
    {
        x =  xx++;
        y =  yy; 
        cout<< xx << " " << yy;
    }
};
int main()
{
    int x = 10;
    int &y = x;
    LFC obj;
    obj.SetValue(x , y);
    return 0; 
}  

A. The program will print the output 10 10.
B. The program will print the output 10 11.
C. The program will print the output 11 10.
D. The program will print the output 11 11.

View Answer


20. What will be the output of the following program?

#include <iostream>
using namespace std;
   class course
{
    int x, y; 
    public:
    course(int xx = 0, int yy = 0)
    {
        x = xx; 
        y = yy;
    }
    void Display()
    {
        cout<< x << " " << y;
    }
    course operator +(course z)
    {
        course temp;
        temp.x = x + z.x;
        temp.y = y + z.y;
        return temp; 
    }
};
int main()
{
    course obj(90, 80); 
    course obj2(10, 20); 
    course objSum; 
    course &ref = objSum; 
    ref = obj + obj2; 
    ref.Display(); 
    return 0; 
}

A. It will result in a runtime error.
B. It will result in a compile time error.
C. The program will print the output 9 4.
D. The program will print the output 100 100.

View Answer


21. Which value can we not assign to reference?

A. Integer
B. Floating
C. Unsigned
D. Null

View Answer


22. The terms lvalue and rvalue is referred to the things that appears on

A. The left side of assignments
B. The right side of assignments
C. The end of program
D. Both A and B

View Answer


23. Which of the following statements is correct? i) Once a reference variable has been defined to refer to a particular variable it can refer to any other variable. ii) A reference is not a constant pointer.

A. Only 1 is correct.
B. Only 2 is correct.
C. Both 1 and 2 are correct.
D. Both 1 and 2 are incorrect.

View Answer


24. Which of the following statements is correct? i) Change a reference changes the referent. ii) We can create an array of references.

A. Only 1 is correct.
B. Only 2 is correct.
C. Both 1 and 2 are correct.
D. Both 1 and 2 are incorrect.

View Answer


25. Which of the following statement is correct?

A. A referenced has to be de-referenced to access a value.
B. A referenced does not need to be de-referenced to access a value.
C. A referenced has to be double de-referenced to access a value.
D. Whether a reference should be de-referenced or not depends on the type of the reference.

View Answer





Also check :


Discussion



* You must be logged in to add comment.