My Report

C++ Programming Practice Test 2


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

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 a = 5;
	int *p = &a;
	int &q = a;
	cout<<*p<<endl;
	cout<<*q<<endl;
	return 0;
}

2. Which function is used to check whether a character is punctuation mark?

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

    #include <iostream>
    using namespace std;
    void square (int *x)
    {
	*x = (*x + 1) * (*x);
    }
    int main ( )
    {
	int num = 10;
        square(&num);
	cout << num;
	return 0;
    } 

4. The switch statement is also called as?

5. ______________ have the return type void.

6. which of the following is used to terminate the function declaration?

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

    #include <iostream>
    using namespace std;
    struct Time 
    {
        int hours;
        int minutes;
        int seconds;
    };
    int toSeconds(Time now);
    int main()
    {
        Time t;
        t.hours = 5;
        t.minutes = 30;
        t.seconds = 45;
        cout << "Total seconds: " << toSeconds(t) << endl;
        return 0;
    }
    int toSeconds(Time now)
    {
        return 3600 * now.hours + 60 * now.minutes + now.seconds;
    } 

8. Which of the following is illegal?

9. Which function is used to check whether a character is tab or space or whitespace control code(\n,\r,etc.)?

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

  
   #include <iostream>
   using namespace std;
   int main ()
   {
       int numbers[5];
       int * p;
       p = numbers;  *p = 10;
       p++;  *p = 20;
       p = &numbers[2];  *p = 30;
       p = numbers + 3;  *p = 40;
       p = numbers;  *(p + 4) = 50;
       for (int n = 0; n < 5; n++)
           cout << numbers[n] << ",";
       return 0;
   }

 

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.