LakshyaEducation.in

VEDIC MATHS Video Series
  • Home
  • Video Series
    • Vedic Maths Videos
    • Quantitative Aptitude Videos
    • Class 8 Maths Videos
    • Class 9 Maths Videos
    • Class 10 Maths Videos
  • Quiz & Solutions
  • Blog
  • Store
  • Login
  • Contact Us
  • Home
  • Topic
  • C++ Programming
  • Subscripting

C++ Programming

SUBSCRIPTING MCQs

Total Questions : 9

Question 1.

What do we need to use when we have multiple subscripts?


  1.    operator()
  2.    operator[]
  3.    operator
  4.    None of the mentioned
 Discuss Question
Answer is Option A. -> operator()

The reason is that operator[] always takes exactly one parameter, but operator() can take any 

number of parameters.

Question 2.

What do we need to do to pointer for overloading the subscript operator?


  1.    reference pointer
  2.    dereference pointer
  3.    store it in heap
  4.    None of the mentioned
 Discuss Question
Answer is Option B. -> dereference pointer

If you have a pointer to an object of some class type that overloads the subscript operator, you 

have to dereference that pointer in order to free the memory.

Question 3.


What is the output of this program?



1.
#include
2.
using namespace std;
3.
class sample
4.
{
5.
private:
6.
int* i;
7.
int j;
8.
public:
9.
sample (int j);
10.
~sample ();
11.
int& operator [] (int n);
12.
};
13.
int& sample::operator [] (int n)
14.
{
15.
return i[n];
16.
}
17.
sample::sample (int j)
18.
{
19.
i = new int [j];
20.
j = j;
21.
}
22.
sample::~sample ()
23.
{
24.
delete [] i;
25.
}
26.
int main ()
27.
{
28.
sample m (5);
29.
m [0] = 25;
30.
m [1] = 20;
31.
m [2] = 15;
32.
m [3] = 10;
33.
m [4] = 5;
34.
for (int n = 0; n < 5; ++ n)
35.
cout
  1.    252015105
  2.    510152025
  3.    51015
  4.    None of the mentioned
 Discuss Question
Answer is Option A. -> 252015105

In this program, we are printing the array in the reverse order by using subscript operator.
Output:
$ g++ sub4.cpp
$ a.out
252015105

Question 4.


What is the output of this program?



1.
#include
2.
using namespace std;
3.
const int limit = 4;
4.
class safearray
5.
{
6.
private:
7.
int arr[limit];
8.
public:
9.
int& operator [](int n)
10.
{
11.
if (n == limit - 1)
12.
{
13.
int temp;
14.
for (int i = 0; i < limit; i++)
15.
{
16.
if (arr[n + 1] > arr[n])
17.
{
18.
temp = arr[n];
19.
arr[n] = arr[n + 1];
20.
arr[n + 1] = temp;
21.
}
22.
}
23.
}
24.
return arr[n];
25.
}
26.
};
27.
int main()
28.
{
29.
safearray sa1;
30.
for(int j = 0; j < limit; j++)
31.
sa1[j] = j*10;
32.
for(int j = 0; j < limit; j++)
33.
{
34.
int temp = sa1[j];
35.
cout
  1.    0102030
  2.    1020300
  3.    3020100
  4.    error
 Discuss Question
Answer is Option A. -> 0102030

In this program, we are returning the array element by the multiple of 10.
Output:
$ g++ sub2.cpp
$ a.out
0102030

Question 5.


What is the output of this program?



1.
#include
2.
using namespace std;
3.
class A
4.
{
5.
public:
6.
int x;
7.
A(int n = 0) : x(n) {};
8.
int& operator[](int n)
9.
{
10.
cout
  1.    110
  2.    111
  3.    011
  4.    001
 Discuss Question
Answer is Option D. -> 001

In this program, we overloading the operator[] by using subscript operator.
Output:
$ g++ sub3.cpp
$ a.out
001

Question 6.


What is the output of this program?



1.
#include
2.
using namespace std;
3.
class numbers
4.
{
5.
private:
6.
int m_nValues[10];
7.
public:
8.
int& operator[] (const int nValue);
9.
};
10.
int& numbers::operator[](const int nValue)
11.
{
12.
return m_nValues[nValue];
13.
}
14.
int main()
15.
{
16.
numbers N;
17.
N[5] = 4;
18.
cout
  1.    5
  2.    4
  3.    3
  4.    6
 Discuss Question
Answer is Option B. -> 4

In this program, We are getting the values and returning it by overloading the subscript operator.
Output:
$ g++ sub1.cpp
$ a.out
4

Question 7.

Pick out the correct statement.


  1.    subscript operator has a higher precedence than the assignment operator.
  2.    subscript operator has a lower precedence than the assignment operator.
  3.    subscript operator is used with string elements.
  4.    None of the mentioned
 Discuss Question
Answer is Option A. -> subscript operator has a higher precedence than the assignment operator.

None.

Question 8.

 subscript operator is used to access which elements?


  1.    string
  2.    char
  3.    array
  4.    all of the mentioned
 Discuss Question
Answer is Option C. -> array

None.

Question 9.

How many arguments will the subscript operator will take for overloading?


  1.    1
  2.    2
  3.    0
  4.    as many as possible
 Discuss Question
Answer is Option A. -> 1

The subscript operator overload takes only one argument,
but it can be of any type.

  • Share on Facebook!
  • Share on Pinterest!

Sub Topics

  • Abstract Classes
  • Access Control
  • Argument Passing
  • Arrays
  • Booleans
  • C++ Concepts
  • Catching Exceptions
  • Character Types
  • Class Hierarchies And Abstract Classes
  • Class Hierarchies Introduction
  • Classes
  • Comments And Indentation
  • Complex Number Type
  • Constants
  • Constructors And Destructors
  • Container Design
  • Conversion Operators
  • Declaration
  • Default Arguments
  • Dereferencing
  • Derivation And Templates
  • Derived Classes
  • Design Of Class Hierarchies
  • Enumerations
  • Error Handling
  • Error Handling Alternatives
  • Essential Operators
  • Exception Specifications
  • Exceptions
  • Exceptions And Efficiency
  • Exceptions That Are Not Errors
  • Floating Point Types
  • Free Store
  • Friends
  • Function Call
  • Function Declarations
  • Function Templates
  • Functions
  • Grouping Of Exceptions
  • Header Files Usage
  • Increment And Decrement
  • Integer Types
  • Large Objects
  • Linkage
  • Macros
  • Modularization And Interfaces
  • Multiple Inheritance
  • Namespaces
  • Objects
  • Objects And Classes
  • Oops Concepts
  • Operator Functions
  • Operators
  • Overloaded Function Names
  • Pointer To Function
  • Pointer To Void
  • Pointers
  • Pointers Into Arrays
  • Pointers To Members
  • References
  • Resource Management
  • Run Time Type Information
  • Sequence Adapters
  • Sequences
  • Simple String Template
  • Sizes
  • Specialization
  • Standard Exceptions
  • Standard Library Design
  • Statements
  • String Class
  • Structures
  • Subscripting
  • Template Arguments To Specify Policy Usage
  • Types
  • Uncaught Exceptions
  • Unspecified Number Of Arguments
  • User Defined Types
  • Value Return
  • Vector
  • Void

Topics

  • Computer Aptitude
  • SAIL Junior Officer (E-0)
  • 10th Grade
  • 11th Grade
  • 12th Grade
  • 4th Grade
  • 5th Grade
  • 6th Grade
  • 7th Grade
  • 8th Grade
  • 9th Grade
  • NCERT
  • Cat
  • Commerce
  • Computer Science
  • Engineering
  • English
  • General Knowledge
  • Ias
  • Management
  • Quantitative Aptitude
  • Reasoning Aptitude
  • General Studies (Finance And Economics)
  • Analytical Instrumentation
  • Biochemistry
  • Bioinformatics
  • Biology
  • Biotechnology
  • Bitsat
  • Business Statistics
  • C Programming
  • C++ Programming
  • Cell Biology
  • Chemistry
  • Cost Accounting
  • Drug And Pharmaceutical Biotechnology
  • Electrical Measurement And Instrumentation
  • Environment Management
  • Environmental Biotechnology
  • Enzyme Technology
  • Financial Management And Financial Markets
  • Gate
  • General Science
  • Geography
  • Heat Transfer
  • History And National Movements
  • Human Anatomy And Physiology
  • Human And Cultural Diversity
  • Human Resource Management
  • Indian Economy
  • Indian Geography
  • Indian History
  • Indian Polity
  • Instrumentation Transducers
  • International Relations
  • Life Sciences
  • Marketing And Marketing Management
  • Mass Transfer
  • Mechanics Of Materials
  • Microbiology
  • Neet
  • Professional Communication
  • Renewable Energy
  • Sociology
  • Surveying
  • Total Quality Management
  • Uidai Aadhaar Supervisor Certification
  • Virology

Recent Questions

Q.   Apache Bigtop Uses ___________ For Continuous Integration T....

Q.   Corporates Have Benefited Tremendously 1)/ From The Governme....

Q.   A Little Gush Of Gratitude

Q.   Among The Following Which Layer Is Directly Apposed To The C....

Q.   Metal Chloride That Is Hydrated Is

Q.   A Steel Member Used In The Furnace Construction To Take The ....

Q.   Which Of The Following Is not Among The Advantages Of H....

Q.   He Killed The Enemy By His Sword.

Q.   Main Circuit Board In A Computer Is...

Q.   The Interpreter Of Indian Constitution Is-

Q.   Rectify

Q.   How Many 4d Orbitals Are There In An Atom?

Q.   If You Increase The Mass On An Object, Its Acceleration

Q.   Which Of The Following Is Capable Of Oxidizing Sulfur To Sul....

Q.   An....

Q.   India's First Private Sector Rocket Vikram-S, Was Developed ....

Q.   Rover Weighs Less Than Fido. Rover Weighs More Than Boomer. ....

Q.   A Cross Shaped (+) Or A Ring Involving Four Chromosomes May ....

Q.   Priming Is Needed In A __________ Pump.

Q.   Dynamic Similarity Is Said To Exist Between The Model And Th....

LakshyaEducation.in
Lakshya Education
Bhilai,Chattisgarh,India
Email: admin@lakshyaeducation.in Phone: 07893519977 (WhatsApp)

Quick Links

  • Vedic Maths
  • Quantitative Aptitude
  • Class – IX Maths
  • Class – X Maths
  • YouTube Channel
  • Maths Fast Trick
  • Blog

Our Services

  • About us
  • Privacy
  • TOS
  • Refund / Cancellation
  • Contact
  • Affiliate Program
  • Copyright © 2022 All Right Reserved | Lakshya Education     ( )
    Login / Register

    Your Account will be created automatically when you click the below Google or Facebook Login Button.
    •   Login With Facebook
    •  Login With Google
     Login With Email/Password