+1

what is the output put of the following program? int main () { int x=5; static int y =x; prinf("%d", y) ; }

what is ans..

9/10/2019 5:17:57 PM

Vaibhav Karma

4 Answers

New Answer

+3

Type the code in codeplayground and run it to see the output yourself. Always ask why the output is what it is, not what is the output. If possible also mention your understanding of some concept, so that if you are wrong someone can correct you. There is illegal initialization here if you compile it as C but this will work fine if compiled as C++ and I assume "prinf" instead of printf is a typing mistake.

+3

It will give compile time error..bcoz dynamic initialization is not available in C language.. And as ~ swim ~ said try understanding yourself first..and I guess this is basics of C language so you might want to revise your C tutorial..

+2

I think error ...illegal initialization

+2

Error because static variables are created at the time of loading while the local variables are created when the scope comes inside curly braces. So firstly static variable y is created and till now there us no variable named x. So its raise an compile time error