1,253 views
0 votes
0 votes

Is it static declaration or static assignment?

int main()
{
    int x=20;
    static int y=x;
    if(x==y)
    printf("Equal");
    else
    printf("Not Equal");
    return 0;
}

What is output?and why?

1 Answer

0 votes
0 votes
this will give error.

Reason: X is an auto variable.. So it will get memory in run time.

where as Y is a static variable hence it will get memory in compile time. but in compile time value of X is not known. Hence we can not initialize Y with such a value that is unknown at the time of Y's initialization.. So it will generate compile error.

Related questions

1 votes
1 votes
3 answers
1
jverma asked May 23, 2022
1,029 views
#include <stdio.h>int f(int n){ static int r = 0; if (n <= 0) return 1; r=n; return f(n-1) + r;}int main() { printf("output is %d", f(5)); return 0;}Ou...
2 votes
2 votes
2 answers
3
Ravi prakash pandey asked Nov 14, 2017
344 views
i think it would be static local variable
2 votes
2 votes
1 answer
4