What is the difference between static int and simple int???? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the difference between static int and simple int????

its related to C,C++and Java

6th Dec 2017, 4:55 PM
TIRTHARAJ SEN
TIRTHARAJ SEN - avatar
1 Answer
0
A static variable is a variable that is allocated at the start of the compilation process and thus cannot be initialized multiple times. unlike non static Data types, static types hold their values as well as their memory address throughout multiple objects of a class. In short, if you have an "Int x;" you can have multiple numbers of X. One for each object and with different values. But if you initialize a "static int x;", there will be only a single X, with the value of X being shared between objects. they are mostly used when a single copy of a data is enough, usually with the "Final" keyword.
6th Dec 2017, 7:39 PM
Kave Eskandari
Kave Eskandari - avatar