If an implementation is Type safety the compiler
will validate types while compiling, and throw an error if wrong type value is
assigned to a variable.
Example 1
Eg int i= “hello”
Error since sring value is assigned to an
integer value
Example 2
int sum (int a, intb)
{
return a+b;
}
If the Example 2 function is called as followes
c=sum(5,”hello”);
Error since instead of passing two numbers a
number and a string is passed to the function.
Note :
PHP, Javascript and other dynamic scripting
languages are commonly weakly-typed which means, they will convert a (string)
"7" to an (integer) 7 if we try to add "7" + 3, even though
it may be done by us explicitly.
Weakly typed programming languages make it easy
to use a value of one type as if it were a value of another type.
"strong" or "weak" typing may
be stated as the presence or absence of type safety, memory safety, static type-checking, or dynamic type-checking.
No comments:
Post a Comment