CPP (or) C++ QUIZ

Correct Answer : Option (D) :   All of the above


Explanation : Any of the above signature can be used while using command line arguments in C++ programs

  Show Answer

Correct Answer : Option (A) :   argv[0]


Explanation : The first string in the list of command line arguments represents the name of the program which can be accessed by using argv[0].

  Show Answer

Correct Answer : Option (C) :   Number of command line arguments


Explanation : The first argument of the main() function represents the number of command line arguments that are passed.

  Show Answer

Correct Answer : Option (D) :   Arguments passed to main() function


Explanation :

The most important function of C/C++ is main() function. It is mostly defined with a return type of int and without parameters :
 
int main() { /* ... */ } 
 
We can also give command-line arguments in C and C++. Command-line arguments are given after the name of the program in command-line shell of Operating Systems.

To pass command line arguments, we typically define main() with two arguments : first argument is the number of command line arguments and second is list of command-line arguments.
 
int main(int argc, char *argv[]) { /* ... */ }
or
int main(int argc, char **argv) { /* ... */ }

  Show Answer
5 .
What will be the output of the following C++ code?
 
#include<iostream>
using namespace std;
int main()
{
	int a = 5;
	auto check = [&]() 
        {
		a = 25;
	};
	check();
	cout<<"Value of a: "<<a<<endl;
	return 0;
}

Correct Answer : Option (D) :   Value of a: 25


Explaination : As this lambda expression is capturing the extrenal variable by reference therefore the change in value of a will be reflected back outside the expression therefore the value of a will now be 25 and 25 is printed.

  Show Answer

Correct Answer : Option (C) :   [&X, Y]


Explanation : In order to capture a variable by reference we use & operator whereas when we capture a single variable by value then we just write the name of that variable without any operator preceding it, So the correct way of capturing the variables X and Y, in this case, is [&X, Y].

  Show Answer

Correct Answer : Option (B) :   A technique of C++ that allows us to write inline functions without a name


Explanation : Lambda expression is a technique available in C++ that helps the programmer to write inline functions that will be used once in a program and so there is no need of providing names top them. Hence they are a type of inline functions without names.

  Show Answer

Correct Answer : Option (A) :   Difference


Explanation : The default operation is to calculate the difference, but some other operation can be specified as binary operator instead.

  Show Answer

Correct Answer : Option (B) :   Returns the result of accumulating all the values in the range


Explanation : Returns the result of accumulating all the values in the range from first to last.

  Show Answer

Correct Answer : Option (D) :   vmath


Explanation : vmath is set of C++ classes for Vector and Matrix algebra used in the programs.

  Show Answer