edited by
5,454 views

4 Answers

Best answer
11 votes
11 votes
#include<stdio.h>
int tmp=20;
main()
{
printf("%d", tmp); ----------------------------- Line:1
func();----------------------------------------- Line:2
printf("%d", tmp);------------------------------ Line:3
}
func().......................................... Line:4
{
static int tmp=10;------------------------------- Line:5
printf("%d", tmp);------------------------------  Line:6
}

Since tmp is a global variable. So, line: 1 will print 20.

then on calling the function "func() " in Line:2, control of program will go to Line 4 then under which new local variable  "tmp=10" is defined statically, So, on executing line:6 gives output 10

On executing Line: 3, again global variable comes into the picture, Since C language follows static scoping so free variable refers to global variable. so it prints value:20

so final output will be : 20 10 20

option B will be correct...

selected by
1 votes
1 votes
if the same code goes for the languages for PERL , LOGO , etc type languages the answer would be different

since we're using C, which uses static scoping the scope of the variable ends as it defining function ends , that's why the answer is 20 10 20
0 votes
0 votes
B) 20 10 20

static int tmp is only for the function func();
Answer:

Related questions

8 votes
8 votes
5 answers
1
sh!va asked May 7, 2017
8,617 views
What will be the output of the following C code?#include <stdio.h main() { int i; for(i=0;i<5;i++) { int i=10; printf("%d" , i); i++; } return 0; }10 11 12 13 1410 10 10 ...
5 votes
5 votes
3 answers
2
sh!va asked May 7, 2017
7,084 views
We use malloc and calloc for:Dynamic memory allocationStatic memory allocationBoth dynamic memory allocation and static memory allocationNone of these
15 votes
15 votes
1 answer
3