Monday, 20 September 2021

C++ TEST ANSWER (Spoken Tutorials)

 

CPP - test

 01. Which format specifier will be used to provide precision of 4 digits after decimal point?

Ans : %.4f

02. Which of  the following variable can store the address of a variable?

Ans : Pointer variable

03. Which of he following accesses the 7th element stored in array?

Ans : array[6];

04. Which of the following mode opens file for reading?

Ans : r

05. What is the format specifier for "double" data-type?

Ans : %lf

06. what will be the output of the following program?

       #include <iostream>

       using namespace std;

       int main()

           {

            int x, y;

            x = 5;

            y = x++ * ++x;

            cout << x <<" " << y;

            return 0;

           }

Ans : 7 35

07. Which of the following is the correct postfix form?

Ans : a++

08. Which of the following is a logical operator in C++?

Ans : ||

 09 : Which of the following statements initializes the pointer to the address of x variable?

Ans : int *ptr=&x;

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

      #include <iostream>

      using namespace std;

      int main()

          {

             char *ptr;

             char Str[] = "abcdefg";

             ptr = Str;

             ptr += 4;

             cout << ptr;

             return 0;

           }

Ans : efg

11. How many times is a constructor called in the life-time of an object?

Ans : Only once

12. What is the index number of the last element of an array with 9 elements?

Ans : 8

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

      #include <iostream>

      using namespace std;

      int main ()

         {

          int array[] = {0, 2, 4, 6, 7, 5, 3};

          int n, result = 0;

          for (n = 0 ;n < 5 ;n++)

            {

             result += billy[n];

             }

          cout << result;

          return 0;

          }

Ans : Compilation error

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

      #include <iostream>

      using namespace std;

          int main()

              {

                  int x = -1;

                  int y = -3.3;

              if(x > y)

                 {

                      cout << "x is greater";

                 }

              else

                {

                     cout << "y is greater";

               }

        }

Ans : x is greater

15. Which of the following is used to make a variable of one type behave like another type.

Ans : Typecasting

16. Which of the following is used to accept a character from a file?

Ans : getchar

17. How many times is a constructor called in the life-time of an object?

Ans : Only once

18. What is the result of a relational operator?

Ans : either true or false

19. If a function does not have return type, it is declared as _____________.

Ans : void

20. Which of the following is the correct postfix form?

Ans : a++

21. Which format specifier will be used to provide precision of 4 digits after decimal point?

Ans : %.4f

22. Which function must not use a return statement?

Ans : void

23. Which of the following variables is enclosed in single quotes?

Ans : character variable

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

#include <iostream>

using namespace std;

int main()

    {

     int a = 8;

     cout << "Integer 'a' with 'true' :" << a && true;

     return 0;

    }

Ans : Integer 'a' with 'true' :8

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

#include <iostream>

using namespace std;

int array1[] = {1200, 200, 2300, 1230, 1543};

int array2[] = {12, 14, 16, 18, 20};

int temp, result = 0;

int main()

   {

    for (temp = 0; temp < 4; temp++)

    {

     result += array1[temp];

    }

    for (temp = 0; temp < 5; temp++)

    {

     result += array2[temp];

    }

    cout << result;

    return 0;

   }

Ans : 5010

26. Which of the following statement is correct?

Ans :-

1. Constructor has the same name as that of the class.

2. Destructor has the same name as that of the class with a tilde symbol at the beginning.

27. In C++ language, which of the following is not an integer value?

Ans :-

'22'

'A'

28. Select the missing code lines from the dropdown provided.

The  C++ code given below should swap two numbers entered by user.

But, line numbers 8 and 16 are missing.

 

1  #include <iostream>

2  using namespace std;

3  int swap(int &x, int &y)

4  {

5    int t;

6    t = x;

7    x = y;   

8    ---------------Missing code -------------------

9   } 

10  int main ()

11  {

12   int a,b;

13   cout<< "Enter values of a and b\n";

14   cin>> a>>b;

15   cout << "Before swapping a and b : " <<a <<" and " <<b <<"\n";

16   ---------------Missing code -------------------

17   cout << "After swapping a and b : " << a <<" and " <<b <<"\n";

18   return 0;

19  }

Ans :-

Line 8 :-   y = t;

Line 16 :-  swap(a, b);

29. What is the break statement used for?

Ans : To interrupt the normal flow of control of a program

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

#include <iostream>

using namespace std;

int main()

   {

    int i = 3;

    int l = i / -2;

    int k = i % -2;

    cout << l  << " "  << k;

    return 0;

   }

Ans :  -1 1

31. Which of the following marks the end of executable statements?

Ans : return 0;

32. Which of the following signifies new line?

Ans : \n

33. Which of the following accesses the 7th element stored in array?

Ans : array[6];

34. Point out the error line in the following program.

1        #include <iostream>

2        using namespace std;

3        int main()

4        {

5            int array[] = (10, 20, 30);

6            cout << -array[2];

7            return 0;

8        }

Ans : Line number 5


CPP - TEST | BY :- NISHANT KUMAR

 

 

No comments:

ARDUINO - TEST (Spoken Tutorial) ANSWER