C Questions and Answers Part-25

1. What will be the output of the following C code?
#include < stdio.h >
int main()
{
foo();
foo();
}
void foo()
{
int i = 11;
printf("%d ", i);
static int j = 12;
j = j + 1;
printf("%d\n", j);
}
a) 11 12 11 12
b) 11 13 11 14
c) 11 12 11 13
d) Compile time error

Answer: b

2. Assignment statements assigning value to local static variables are executed only once.
a) true
b) false
c) Depends on the code
d) None of the mentioned

Answer: b

3. What is the format identifier for “static a = 20.5;”?
a) %s
b) %d
c) %f
d) Illegal declaration due to absence of data type

Answer: b

4. Which of the following is true for the static variable?
a) It can be called from another function
b) It exists even after the function ends
c) It can be modified in another function by sending it as a parameter
d) All of the mentioned

Answer: b

5. What will be the output of the following C code?
#include < stdio.h >
void func();
int main()
{
static int b = 20;
func();
}
void func()
{
static int b;
printf("%d", b);
}
a) Output will be 0
b) Output will be 20
c) Output will be a garbage value
d) Compile time error due to redeclaration of static variable

Answer: a

6. What will be the output of the following C code?
#include < stdio.h >
int main()
{
register int i = 10;
int *p = &i;
*p = 11;
printf("%d %d\n", i, *p);
}
a) Depends on whether i is actually stored in machine register
b) 10 10
c) 11 11
d) Compile time error

Answer: d

7. register keyword mandates compiler to place it in machine register.
a) true
b) false
c) Depends on the standard
d) None of the mentioned

Answer: b

8. What will be the output of the following C code?
#include < stdio.h >
int main()
{
register static int i = 10;
i = 11;
printf("%d\n", i);
}
a) 10
b) Compile time error
c) Undefined behaviour
d) 11

Answer: b

9. What will be the output of the following C code?
#include < stdio.h >
int main()
{
register auto int i = 10;
i = 11;
printf("%d\n", i);
}
a) 10
b) Compile time error
c) Undefined behaviour
d) 11

Answer: b

10. What will be the output of the following C code?
#include < stdio.h >
int main()
{
register const int i = 10;
i = 11;
printf("%d\n", i);
}
a) 10
b) Compile time error
c) Undefined behaviour
d) 11

Answer: b