What is the output of the below program?
void main() { int var1 = 10; static int var2 = var1; if(var1 == var2) { Printf("Both Reached same level"); } else { Printf("They can never reach same level"); } }
------------------------------------------
The above code tests two scenarios:
1. static storage class
2. if condition check
------------------------------------------
When a variable is declared with the storage class static, the local variable shall still be existence even though the program has exited the current function.
Coming to the current code, static storage class has been declared for integer variable var2 and var2 was assigned another variable var1. For a static variable, only constant value can be assigned and not variable value.Hence, compiler throws an error.
0 Comments