Review Questions

1:What's wrong with this attempted declaration of a character string?
int main(void)
{
   char name[] = {'F', 'e', 's', 's' };
   ...
}
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;
}
3:What will this program print?
#include <stdio.h>
#include <string.h>
int main(void)
{
   char food[] = "Yummy";
   char *ptr;

   ptr = food + strlen(food);
   while (--ptr >= food)
        puts(ptr);
   return 0;
}
4:What will the following program print?
 #include <stdio.h> #include <string.h> int main(void) { char goldwyn[40] = "art of it all "; char samuel[40] = "I read p"; char *quote = "the way through."; ...

Get C Primer Plus, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.