2 2 votes Programming in C + – Kaluti 1.2k views answer comment Share Follow Print See all 7 Comments 7 7 Comments reply Kaluti commented Jan 14, 2018 reply Follow flag plz tell its output according to me output should be 15 20 15 20 0 0 replyShare MiNiPanda commented Jan 14, 2018 reply Follow flag 15 20 15 15 1 1 replyShare MiNiPanda commented Jan 14, 2018 reply Follow flag 2nd time call to print2() overwrites the value of static variable x to 10 from 15. 0 0 replyShare Kaluti commented Jan 14, 2018 reply Follow flag but static variables retain their value during function call 0 0 replyShare MiNiPanda commented Jan 14, 2018 reply Follow flag yes they do that is why print1() prints 20 in the 2nd case. But the implementation in the print2 is different. You are explicitly inserting 10 into x. So each time the print2 is getting invoked, the value of x=15 stays as it is until it encounters the line "x=10". 0 0 replyShare MiNiPanda commented Jan 14, 2018 reply Follow flag Static variables are initialized only for once in it's lifetime. ref: https://www.geeksforgeeks.org/static-variables-in-c/ x=10 is not initialization. It is called definition. So this can be executed for more than once. initialization example: int x=10; definition example : x=10; declaration example : int x; ref: https://www.quora.com/What-is-the-difference-between-definition-and-initialization-in-C-language 0 0 replyShare Kaluti commented Jan 14, 2018 reply Follow flag okk thanks 0 0 replyShare Please log in or register to add a comment.