![]() |
VOOZH | about |
Typed Language: Typed languages are the languages in which we define the type of data type and it will be known by machine at the compile-time or at runtime.
Typed languages can be classified into two categories:
Statically typed languages: Statically typed languages are the languages like C, C++, Java, etc, In this type of language the data type of a variable is known at the compile time which means the programmer has to specify the data type of a variable at the time of its declaration. We have to pre-define the return type of function as well as the type of variable it is taking or accepting for further evaluations.
Syntax:
data_type variable_name;Example: The below example illustrates code to show it is statically typed language:
I'm a string with value: GeeksforGeeks I'm a number with value: 109 I'm a floating point number with value: 12.99
Example 2:
Output: It will show an error because we can not directly assign the value to a variable other than its defined data type:
prog.cpp: In function ‘int main()’:
prog.cpp:11:13: error: invalid conversion from ‘const char*’ to ‘int’ [-fpermissive]
int num2="Welcome to GeekdforGeeks";
^
Dynamically typed language: These are the languages that do not require any pre-defined data type for any variable as it is interpreted at runtime by the machine itself. In these languages, interpreters assign the data type to a variable at runtime depending on its value. We don't even need to specify the type of variable that a function is returning or accepting in these languages. JavaScript, Python, Ruby, Perl, etc are examples of dynamically typed languages.
Example: This example demonstrates JavaScript as a dynamically typed language:
I'm a string with value: GeeksforGeeks I'm a number with value: 5 I'm a floating point number with value: 12.99 I'm a string with value: Welcome to GFG