C Identify the lines containing syntax errors in the followi

C++: Identify the lines containing syntax errors in the following code. Assume all libraries have been included already. Select all that apply. Please provide explanation for answer.

A char first [6]; B char last[7] \"Parker\", name [13]; c getline (cin, first); D strcpy (name, first, 5) E strcat (name, \'\'); F strcat (name, last); Answers: A

Solution

Here is the explanation for you:

#include <cstring>
#include <iostream>
using namespace std;
int f(int a, int b)
{
return a;
}
int main()
{
char first[6]; //Declares a character array first of size 6.
char last[7] = \"Parker\", name[13]; //Initializes the character array last, and declares the character array name.
getline(cin, first);   //Improper parameters are passed for this function call. There are various ways to call getline() method, but this way is wrong.
strcpy(name, first, 5); //This line leads to error. strcpy() is a function which is expecting only 2 parameters as input, but you passed 3 here, and therefore will lead to error.
strcat(name, \' \'); //This line also leads to error. strcat() is a function which is expecting 2 character pointers as input, but you passed a character literal as the second parameter, and therefore will lead to error.
strcat(name, last); //This works fine, the string Parker is appended to the string name.
}
//So, the errors include in lines, C, D, and E.

C++: Identify the lines containing syntax errors in the following code. Assume all libraries have been included already. Select all that apply. Please provide e

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site