Assignment #2 Strings PDF
Assignment #2 Strings PDF
Answer:
Explanation:
Answer:
Output: It runs but there is no output
Explanation:
The code should have been like this:
#include <stdio.h>
#include <string.h>
int main() {
char str1[] = "United";
char str2[] = "Front";
char str3[20];
printf("%s\n", str3);
return 0;
}
Where we declare arrays of strings to store the string United and Front, and declare another
array of string to append the overall strings. Where in the line ‘strcpy(str3,
str1);’ the string at ‘str1’ array is being copied by array ‘str3’ and appended
‘str2’ to the end of ‘str3’, which will then print ‘str3’ which is ‘United
Front’.
3. If the string "Alice in wonder land" is fed to the following scanf( ) statement,
what will be the contents of the arrays str1, str2, str3, and str4?
scanf( "%s%s%s%s", str1, str2, str3, str4 );
Answer:
str1: "Alice"
str2: "in"
str3: "wonder"
str4: "land"