O'Reilly logo

C Primer Plus, Fourth Edition by Stephen Prata

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 11

1: What's wrong with this attempted declaration of a character string?
int main(void)
{
   char name[] = {'F', 'e', 's', 's' };
   ...
}
A1: The initialization should include a '/0' if you want the result to be a string. Of course, the alternative syntax adds the null character automatically:
char name[] = "Fess";
2: What will this program print?
#include <stdio.h>
int main(void)
{
   char note[] = "See you at the snack bar.";
   char *ptr;

   ptr = note;
   puts(ptr);
   puts(++ptr);
   note[7] = '\0';
   puts(note);
   puts(++ptr);
   return 0;
}
A2:
See you at the snack bar.
ee you at the snack bar.
See you
e you
3: What will this program print?
 #include <stdio.h> #include <string.h> int main(void) { char food[] = "Yummy"; char *ptr; ptr = food + strlen(food); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required