Link to home
Start Free TrialLog in
Avatar of prebek
prebek

asked on

const qualifier in structure

I want to know why the const qualifier in front of the array at the start of this program, supposedly makes the program more reliable and readable. I think it's because the specifiers in the printf statements have an easier time accessing the contents of an array if the array itself is constant. Is that correct?
#include <stdio.h> #define LEN 20 
const char * msgs[5] =
{ 
     "    Thank you,", 
     "You prove that a ",
     "is a special guy. We must meet over a "
     "at"  
     "and laugh"
}
 
struct names {
char first[LEN];
char last[LEN];
};
 
struct guy {
      struct names handle
       char favfood[LEN];
      char job[LEN] 
      float income;
};
 
int main(void)
{
struct guy fellow = {
      {"Thomas", "Villard"},
     "grilled salmon",
      "life coach",
      58112.00
};
 
 
 
     printf("Dear %s, \n\n", fellow.handle.first); 
     printf("%s%s.\n", msgs[0], fellow.handle.first);
     printf("%s%s\n", msgs[1], fellow.job);
     printf("%s\n", msgs[2]);
     printf("%s%s%s", msgs[3], fellow.favfood, msgs[4]);
     if (fellow.income > 150000.0) 
         puts("!!"); 
      else if (fellow.income > 75,000)
         puts("!");
      else
               puts(".");
      printf("See you soon.\n");
 
return 0;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of mrjoltcola
mrjoltcola
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of prebek
prebek

ASKER

thanks, i get it now