mixed declarations and codes

早过忘川 提交于 2019-12-01 03:28:50

In K&R and ANSI c, you must always put declarations at the start of a scope block. This requirement is relaxed in c99.

So, whats a scope block? A region delimited by { and }.

So in you above example the declaration

{
   char *p=malloc(sizeof(char)*3); /* ...

is OK because it occurs immediately after a {, while

{
  char **cmainp=malloc(sizeof(char*)*1);    

  /*look*/ cmainp[0]=malloc(sizeof(char)*300); /*look*/

  int len=0;...

fails because the assigment comes between the { and the second declaration (int len=0;).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!