C Functions and Blocks
C Functions and Blocks
1 #include <stdio.h>
2 int main()
3 {
4 int var=100;
5 {
6 int var=200;
7 printf("%d...",var);
8 }
9 printf("%d",var);
10 return 0;
11 }
1. ERROR
2. 200...200
3. 100...100
4. 200...100
Answer
1 #include <stdio.h>
2 char* fun1(void)
3 {
4 char str[]="Hello";
5 return str;
6 }
7
8 char* fun2(void)
9 {
10 char *str="Hello";
11 return str;
12 }
13 int main()
14 {
15 printf("%s,%s",fun1(),fun2());
16 return 0;
17 }
1. ERROR
2. Hello,Hello
3. Hello,Garbage
4. Garbage,Hello
Answer
1 #include <stdio.h> /
2
3 int fooo(void)
4 {
5 static int num=0;
6 num++;
7 return num;
8 }
9 int main()
10 {
11 int val;
12 val=fooo();
13 printf("step1: %d\n",val);
14 val=fooo();
15 printf("step2: %d\n",val);
16 val=fooo();
17 printf("step3: %d\n",val);
18 return 0;
19 }
1. step1: 1
step2: 1
step3: 1
2. step1: 1
step2: 2
step3: 3
3. step1: 0
step2: 0
step3: 0
4. ERROR
Answer
1 #include <stdio.h>
2
3 int main()
4 {
5 int anyVar=10;
6 printf("%d",10);
7 return 0;
8 }
9 extern int anyVar;
Answer