Static variable Flashcards

1
Q

On infinite function calls , what happens?

A

Stack size is over / Stack overflow error(runtime error mostly due to logical mistakes)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

if(10.5)

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

if(-11)

A

true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

if(‘A’)

A

true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

if(0.0)

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

if(null)

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

if(0)

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

if(‘\o’)

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

a=5
POSTFIX: x=a–
OR
PREFIX: x=–a

A

POSTFIX: x=5
PREFIX: x=4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What happens if we use static keyword for a local variable for instance,
static int a=5;

A

It is local but will be stored in static area and compiler will assign it memory during compile time. No matter how many times the function is called static memory is only allocated once.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Even in multiple calls of the same function in which a static variable is declared, how many times is that variable allocated memory?

A

Only once in static area, all function calls share the same value of the variable as stored in static area.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

If a same fn. is called again and again and it includes declaration of a variable which is not static, what happens?

A

Memory is allocated to that variable again and again and it is initialized again & again

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Stack overflow occurs when functions are called infinitely but not for an infinite loop, WHY?

A

Because when function is called , activation records are pushed into stack but infinite loop doesn’t affect stack.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Default value of static variable?

A

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Global variable are stored in?

A

Static area

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Local static variable can be accessed only in?

A

That particular function

17
Q

When is static variable deallocated?

A

When main over

18
Q

a*=b+c

A

a=a*(b + c ) , First b + c is evaluated then it is multiplied by a

19
Q

r*f(n)
r+f(n)
r-f(n)
r/f(n)

A

We will not place value of r until f(n) is calculated

20
Q

r*7+f(n)

A

We can put r before calculating f(n) as r adjacent operand decided

21
Q

r+3*f(n)

A

You have to wait before putting value of r because r’s adjacent operator is not decided

22
Q

a+b*c()

A

High priority of b*c hence both a, b will wait

23
Q

a=b=c

A

R to L associative , value of c required for b which is required for a

24
Q
A