C How many lines in the code segment below contain syntax er
C++: How many lines in the code segment below contain syntax errors? Please provide explanation for answer, as in which lines and why.
char*TowerofPower (char* Superman) Superman \"Kal-El\"; = return Superman; int main () char tower = \'A\', *ptr; ptr = Towe rofPower(&tower;); return 0; Answers: 0 2 3Solution
#include <cstring>
#include <iostream>
using namespace std;
char* TowerOfPower(char* Superman) //Defines a function which takes a character pointer as input, and returns a character pointer.
{
Superman = \"Kal-El\"; //This leads to an warning. Superman is a pointer variable, and a string constant cannot be assigned to this.
return Superman; //Returning a character pointer variable.
}
int main()
{
char tower = \'A\', *ptr; //Declares a character variable tower initialized with \'A\', and another character pointer variable ptr.
ptr = TowerOfPower(&tower); //Calls the function TowerOfPower() with address of character variable as input, and the returned value is stored in character pointer.
cout<<*ptr<<endl;
return 0;
}
//So, the number of errors is 0, but with a warning.
