function assign to variable in C -


why following code return error when variable declared global.

int add(int x, int y) {     return x+y; }   int ab = add(10, 20); int main(void) {      printf("%d", ab); } 

but if call this:

int add(int x, int y) {     return x+y; }   int main(void) {     int ab = add(10, 20);  // variable declare inside main     printf("%d", ab); } 

then executes without error.

initializers global variables must constant, can't arbitrary expression.


Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -