Skip to main content

Section 20.4 Practice Your Strings!

Activity 20.4.

Take a look at the code and then hit the Run button. Is that the output you expected? What is going on with the code here?

Compile and run the code below in your own C environment.

#include <stdio.h>
#include <string.h>

int main(void) {
   char firstName[10];
   char lastName[30];
   
   strcpy(firstName, "Petra The Chocolate Eater");
   strcpy(lastName, "Bonfert-Taylor");
   printf("My name is %s %s.\n", firstName, lastName);
   return 0;
}
Record your answer below.