Why's initializing a global variable with return value of a function failing at declaration,but works fine at file scope?

后端 未结 5 2137
名媛妹妹
名媛妹妹 2020-12-19 04:51

An 80k reputation contributor R.. told me on SO that we can\'t initialize global variables with the return value of a function as that\'s not c

5条回答
  •  独厮守ぢ
    2020-12-19 05:22

    we could not call any function from outer of the function.Not like shell script.function only allow to called from inside of function body.

    In c first execution begins from main(), compiler don't know the function calling if that stands on outer of function it may taken as prototype if arg and return types provided.

    we can putting return value of function by calling from main or others function block, to the variable,the function called then (that global) variable modified.

    but we can use macro in global variable as needs. as:

    #define max() 12 
    int glob=max();
    main()
    {
    
    }
    

提交回复
热议问题