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

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -