C is not a loosely typed language, unlike Python or Perl where variables are dynamically-typed. What does this mean?
In Python or in Perl, we do not specify the type of data we assign to a variable, so in course of time, we can assign char, int, float, object values to the same variable without any declaration. The interpreter is smart enough to assign values and judge the type of data value.
An example in Python:
x=45; x="Rama"; x=4.65
The code in Python works fine.
In C or Java, this is not the case. Here we have to tell the compiler beforehand that what data are you going to assign to a variable name. Accordingly, C or Java compiler will create memory space in the heap and let you assign values.
This happens due to the fact that C or Java is statically-typed, which means that once you declare a variable with a particular data type you cannot in due course of time change the data-type until and unless the state of the variable is destroyed. Again the memory allocation is not dynamic, thus every time you create a variable the compiler will create some storage-space in the heap and you cannot modify it.
Thus declaration is important before initialization in C and Java.
No comments:
Post a Comment
Convey your thoughts to authors.