Question from the C++ test

What is the output of the following code? #include <iostream> #include <string> using namespace std; int main() { int a = 10; int b = 20; int c = a + b; cout << c; return 0; }

Hard

What is the output of the following code:

int main(int argc, char *argv[])
{
        	
        	try
        	{
     	           	char* ptr;
     	  
     	           	strcpy(ptr, "C++ world");
     	  
     	           	ptr++;
     	  
     	           	std::cout<<ptr<<std::endl;
        	}
        	catch(...)
        	{
  	              	std::cout<<"caught some unhandled exception"<<std::endl;
        	}
        	return 0;
}

Author: Abha AgrawaStatus: PublishedQuestion passed 422 times
Edit
0
Community Evaluations
developer avatar
Sandra
29/05/2024
This is deprecated and probably won't even compile (str is uninitialized and strcpy_s should be used rather than strcpy)