Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5
Static variables are initialized to their default values, as per the standard. There is no need to initialize them explicitly with a default value to prevent getting a junk value. For int, the default value is assumed as 0, and so the variable i stores 0. Now in the function fun, q points to a pointer pointing to i, and so double dereferencing it returns the value of i, or 0. As for why this happens, kindly refer to: https://stackoverflow.com/questions/2091499/why-are-global-and-static-variables-initialized-to-their-default-values To display another value, simply assign 'i' with a new value: static int i = 5; // or: i = 14; // or: *((int*)vptr) = 67; // after assigning vptr **(q) = 72; // inside 'fun'
16th Aug 2019, 2:46 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar