Computer Science - Object Oriented Programming Using C++ - Discussion

Discussion Forum : Object Oriented Programming Using C++ - Section 8 (Q.No. 36)
36.
You can use the C++ _____ function to assign a value to a String variable
assign
copy
string
strcopy
strcpy
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
2 comments Page 1 of 1.

Ayesha said:   3 years ago
@All.

strcpy() is a standard library function in C/C++ and is used to copy one string to another. s

Syntax:
char* strcpy(char* dest, const char* src);
Paramters: This method accepts following paramters:

dest: Pointer to the destination array where the content is to be copied.
src: string which will be copied.
int main ()
{
char str1[]="Hello Geeks!";
char str2[] = "GeeksforGeeks";
char str3[40];
char str4[40];
char str5[] = "GfG";

strcpy(str2, str1);
strcpy(str3, "Copy successful");
strcpy(str4, str5);
printf ("str1: %s\nstr2: %s\nstr3: %s\nstr4: %s\n", str1, str2, str3, str4);
return 0;
}

Output:

str1: Hello Geeks!
str2: Hello Geeks!
str3: copy successful
str4: GfG

So, the Answer: Option E.

Omar Othman said:   1 decade ago
strcpy() operates on char* not string. The correct answer is C (the constructor).

Post your comments here:

Your comments will be displayed after verification.