Class 7 Exam  >  Class 7 Tests  >  Test: C++ References - Class 7 MCQ

Test: C++ References - Class 7 MCQ


Test Description

15 Questions MCQ Test - Test: C++ References

Test: C++ References for Class 7 2024 is part of Class 7 preparation. The Test: C++ References questions and answers have been prepared according to the Class 7 exam syllabus.The Test: C++ References MCQs are made for Class 7 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: C++ References below.
Solutions of Test: C++ References questions in English are available as part of our course for Class 7 & Test: C++ References solutions in Hindi for Class 7 course. Download more important topics, notes, lectures and mock test series for Class 7 Exam by signing up for free. Attempt Test: C++ References | 15 questions in 15 minutes | Mock test for Class 7 preparation | Free important questions MCQ to study for Class 7 Exam | Download free PDF with solutions
Test: C++ References - Question 1

What will be the output of the following C++ code?

#include <iostream>
#include <string>
#include <cstdlib>
 
using namespace std;
 
int main(int argc, char const *argv[])
{
    int &q = 5;
    cout<<q;
    return 0;
}

Detailed Solution for Test: C++ References - Question 1

References require are other names for variables not for a constant literal. No such assignment are allowed in C++.

Test: C++ References - Question 2

Identify the incorrect statement.

Detailed Solution for Test: C++ References - Question 2

Reference is a thing which points to the valid memory address, so it can’t be redesigned.

1 Crore+ students have signed up on EduRev. Have you? Download the App
Test: C++ References - Question 3

What will be the output of the following C++ code?

#include <iostream>
#include <string>
#include <cstdlib>
 
using namespace std;
 
int main(int argc, char const *argv[])
{
    int a = 5;
    int &p = a;
    cout<<p;
    return 0;
}

Detailed Solution for Test: C++ References - Question 3

In this program, every thing is correct so the program runs perfectly and prints the 5 as output.

Test: C++ References - Question 4

Which of the following is incorrect?

Detailed Solution for Test: C++ References - Question 4

C++ allows references to refer to a constant value by making constant references. For example:
const int a = 5;
const int &ref = a;
is an example of that.

Test: C++ References - Question 5

What will be the output of the following C++ code?

    #include <iostream>
    using namespace std;
    void swap(int &a, int &b);
    int main()
    {
        int a = 5, b = 10;
        swap(a, b);
        cout << "In main " << a << b;
        return 0;
    }
    void swap(int &a, int &b)
    {
        int temp;
        temp = a;
        a = b;
        b = temp;
        cout << "In swap " << a << b;
    }

Detailed Solution for Test: C++ References - Question 5

 As the function is called by reference i.e. all the changes are done directly into the memories of a and b. Therefore changes made to a and b in swap function is reflected back to main function. Hence the values of a and b in swap as well as in main function is changed.
Output:
$ g++ ref.cpp
$ a.out
In swap 105 In main 105

Test: C++ References - Question 6

What will be the output of the following C++ code?

#include<iostream>
using namespace std;
 
int &fun()
{
    static int x = 10;
    return x;
}
int main()
{
    fun() = 30;
    cout << fun();
    return 0;
}

Detailed Solution for Test: C++ References - Question 6

A function returning value by reference can be used as lvalue i.e. it can be used on the left side of an expression. Here when we are doing fun() = 30 then we are changing the value of x(i.e. value returning) to and as x is static therefore it will not be initialized again so the value of x becomes 30 hence the output is 30.

Test: C++ References - Question 7

What will be the output of the following C++ code?

#include <iostream>
#include <string>
#include <cstdlib>
 
using namespace std;
 
int main(int argc, char const *argv[])
{
    int a = 5;
    int *p = &a;
    int *(&q) = p;
    cout<<q;
    return 0;
}

Detailed Solution for Test: C++ References - Question 7

The program is correct so the the program runs perfectly. It is way to assign pointers to references. The program prints the address of a because it is an alias for pointer p and pointer p stores the address of a therefore answer is address of a.

Test: C++ References - Question 8

What will be the output of the following C++ code?

    #include <iostream>
    using namespace std;
    int main()
    {
        int a = 9;
        int & aref = a;
        a++;
        cout << "The value of a is " << aref;
        return 0;
    }

Detailed Solution for Test: C++ References - Question 8

The value is declared and it isincrementedrement, so it’s value is 10.
$ g++ ref1.cpp
$ a.out
10

Test: C++ References - Question 9

What will be the output of the following C++ code?

#include<iostream>
using namespace std;
 
int main()
{
   int x = 10;
   int& ref = x;
   ref = 20;
   cout << x << endl ;
   x = 30;
   cout << ref << endl;
   return 0;
}

Detailed Solution for Test: C++ References - Question 9

As we know references are alias for a variable so the value of a variable can be changed using alias hence both ref and x are same therefore changing the value of one effects the value of other.

Test: C++ References - Question 10

Pick the correct statement about references in C++.

Detailed Solution for Test: C++ References - Question 10

References and variable it is referring to shares the same address. References do not consume extra address. References do not store the address of other variables. No dereferencing operator required while using references. References are not available in C++.

Test: C++ References - Question 11

Identify the correct sentence regarding inequality between reference and pointer.

Detailed Solution for Test: C++ References - Question 11

It is not allowed in C++ to make an array of references. To test check following array:
int &arr[] = {&a, &b, &c};
This will give an error.

Test: C++ References - Question 12

Which of the following statement(s) is/are correct?

Detailed Solution for Test: C++ References - Question 12

A variable can have multiple references as references are nothing just another name for a variable hence a variable can more than one references.

Test: C++ References - Question 13

What are the references in C++?

Detailed Solution for Test: C++ References - Question 13

References are an alternative name for an already defined variable. They are different from pointers.

Test: C++ References - Question 14

Which value can we not assign to reference?

Detailed Solution for Test: C++ References - Question 14

If it can be assigned with a null value means, it is a copy of the pointer.

Test: C++ References - Question 15

What will be the output of the following C++ code?

#include <iostream>  
using namespace std;
int f(int &x, int c) 
{
   c  = c - 1;
   if (c == 0) return 1;
   x = x + 1;
   return f(x, c) * x;

int main(int argc, char const *argv[])
{
    int a = 4;
    cout<<f(a,a);
    return 0;
}

Detailed Solution for Test: C++ References - Question 15

In this program as one parametere is passed by value and other is passed by reference so after 4 calls when c == 0, then the value of x = 7 and as x is passed by reference so all the changes will be reflected back in all the previous calls hence the answer 1*7*7*7 = 343.

Information about Test: C++ References Page
In this test you can find the Exam questions for Test: C++ References solved & explained in the simplest way possible. Besides giving Questions and answers for Test: C++ References, EduRev gives you an ample number of Online tests for practice

Top Courses for Class 7

Download as PDF

Top Courses for Class 7