Point out the error line in the following program.1. #include<stdio.h>2. #include<string.h>3. int main()4. {5. static char str1[] = "Welcome";6. static char str2[20];7. static char str3[] = "Sir";8. str2 = strcpy(str3, str1);9. printf("%s\n", str2);10. return 0;11. }Select one:Line number 8Line number 6None of these.Line number 7
Question
Point out the error line in the following program.1. #include<stdio.h>2. #include<string.h>3. int main()4. {5. static char str1[] = "Welcome";6. static char str2[20];7. static char str3[] = "Sir";8. str2 = strcpy(str3, str1);9. printf("%s\n", str2);10. return 0;11. }Select one:Line number 8Line number 6None of these.Line number 7
Solution
The error is in line number 8. In C, you cannot assign arrays directly. The strcpy function already copies the source string into the destination string, so the assignment is not needed. The corrected line should be:
strcpy(str2, str1);
Similar Questions
When the following code is executed an error is encountered and the program crashes. On which line do you think the error is encountered?You may assume that all required classes have been defined elsewhere.
When a program runs, but does not do what you expect, it means that your progam contains…?Logical ErrorSyntax error
Point out the error line in the following program.1 #include <iostream>2 using namespace std;3 void main()4 {5 long int num = 10; 6 long int *ptr; 7 cout<<"num's address :"<< &num<<"\n"; 8 ptr = #9 cout<<"pointer's address :"<< &ptr<<"\n"; 10 cout<<"pointer's size bytes "<< sizeof(ptr)<<"\n"; 11 cout<<"pointer's value: "<< ptr<<"\n"; 12 cout<<"value pointed to: "<< *ptr<<"\n"; 13 return 0;14 }Select one:Line number 5Line number 12Line number 3Line number 10
What will be the output of the C program? ACompilation errorB1C5DRuntime error
What is an error that occurs during the execution of code?1 pointError messagesExceptionException handlingFinally
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.