Static Keyword in C

In C, static variables can only be initialized using constant literals. For example, following program fails in compilation. See this for more details.
#include<stdio.h>
int initializer(void)
{
    return 50;
}
  
int main()
{
    static int i = initializer();
    printf(" value of i = %d", i);
    getchar();
    return 0;
}
Output
 In function 'main':
9:5: error: initializer element is not constant
     static int i = initializer();
     ^

Comments

Popular posts from this blog

BYTE STUFFING PROGRAM USING C

Rotate a matrix 270 degree AntiClockWise

Finding the length of connected cells of 1's (regions) in an matrix of 1's and 0's