Question

Compare and contrast static variable declarations versus dynamic variable declarations. State as many pros and cons...

Compare and contrast static variable declarations versus dynamic variable declarations. State as many pros and cons as you can.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi,

Let's see the basic definition and syntax of both variable types first.

Static Variable:

Static values are basically holding its values even after it is in out of scope. So, it will not initialize in the new scope due to its previous value. SO the value is unchanged.

static data_type variable_name = variable_value;

Dynamic Variable:

Dynamic variable can change its value during the run time. It will get the value from the user at any point of time and can be changed again.

data_type variable_name;

Advantages of Static Variable:

- It improves the code performance
- It uses Heap memory.
- It is changeless hence no additional memory is required.

Disadvantages of Static Variable:

- It will always consume the memory whether used or not.
- You cannot have control while creating and destructing the static variable.
- Scope is limited.
- Serialization won't work here.

Advantages of Dynamic Variable:

- It can be used across the program in all the scopes.
- Maintenance is very easy.
- Declaration of variable is done only once outside the module and then it can be changed in the functions.

Disadvantages of Dynamic Variable:

- Code debugging is hard.
- It might change the value in other place than it was actually intended to use.
- Value is unpredictable in some point of time.

Please let me know if you need more information. Please like if you are happy with the answer.

Happy Learning!

Add a comment
Know the answer?
Add Answer to:
Compare and contrast static variable declarations versus dynamic variable declarations. State as many pros and cons...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT