What will be the output of the following code segment?
void fun()
{
static int i=10;
print ("%d", ++i);
}
int main ()
{
fun ();
fun();
From the above code we can observe that there is an operator which is initiated i=10. And when fun() is getting call first time then it will print the value of I but here ++I will firstly increment the value by 1 meand it will print 11.
Now when it will be called second time then it will firstly do the increment and then it will print the value. So, it will print 12 in the second call.
#include<stdio.h>
void fun(){
static int i=10;
printf("%d \n",++i);
}
int main(){
fun();
fun();
return 0;
}
Comments
Leave a comment