125k views
1 vote
Consider the following declaration: char str[15];. Which of the following statements stores "Blue Sky" into str?

a. strcpy("Blue Sky");
b. str[15] = "Blue Sky";
c. strcpy(str, "Blue Sky");
d. str = "Blue Sky";

User Bhilstrom
by
8.3k points

1 Answer

6 votes

Final answer:

The correct statement that stores "Blue Sky" into str is strcpy(str, "Blue Sky");.

Step-by-step explanation:

The correct statement that stores "Blue Sky" into str is c. strcpy(str, "Blue Sky");.

The strcpy function is used to copy a string into another string. In this case, we want to copy the string "Blue Sky" into the character array str.

Option a. strcpy("Blue Sky"); is incorrect because it is missing the target string (str) as the first argument. Option b. str[15] = "Blue Sky"; is incorrect because it tries to assign a string to an individual character of the array instead of copying the entire string. Option d. str = "Blue Sky"; is incorrect because you cannot assign a string to a character array using the assignment operator (=).

User Wayne Bloss
by
8.6k points