+ 2
what is output of given code void func(int x) { x+=6; } int main() { static int x; func(x); cout<<x; return 0; } // zero output explanation given below
10 Respuestas
+ 5
it is 0 not because both variables are named x but because the copy of the value is being passed to the function. The original value of static int x is 0 after calling the function. If u want to change its original value pass it by reference put void func (int& x)
+ 2
The Code Playground in SoloLearn outputs 0.
+ 2
address of both variable named x are different
and if we r declearing any variable using static key word it automatically initialized as 0 so value of x in main function is zero so the output is zero
+ 1
maybe it will be something like "undefined behaviour"
+ 1
nothing as it is not returning any value to main
+ 1
you're returning 0; all the other code is irrelevant in this context.
0
m not sure but if value of x is 0 then output is 6 (correct me programmers of m @fault) explain please
0
output 0
0
Static keyword specifies the value assigned to the variable is remains unchanged with in the scope of block.
Static variable's default value is 0.
Hence output is 0
- 1
correct ans is 0