const 作用1

const char * const months[12]  = 

{

         " January ","February","March","April","May","June","July","August","September","October","November","December"

};

   在上述范例中,第一个const防止字符串被修改,第二个const确保数组中每个指针始终指向它最初指向的字符串。




     在c++中,const 限定符对默认存储类型稍有影响。在默认情况下全局变量的链接性为外部的,但const全局变量的链接性为内部的。也就是说,在c++看来,全局const定义就像使用了static说明符一样。

     const  int fingers = 10;  //same as static const int fingers

    int main (void)

   {

       .....  

   }   

你可能感兴趣的:(c,存储)