Statically Typed Language

Definition – What is Statically Typed Language

Statically typed is a feature of programming language. It means, while declaring a variable, the user must define the data type before declaring the variable otherwise the compiler will through a compilation error. Statically typed languages have some advantages and also have some disadvantages as well.

Unlike loosely typed language, programmers must define the data type each time for declaring every single variable. So it is tiresome to write code in statically typed languages compared to loosely typed language. But statically typed language is very efficient for a language compiler or computer itself for computation performance.

In a statically typed language, the language compiler or interpreter does not perform a single check for data type detection, because the data type is already declared by the programmer. In the case of mistaking data type definition, the compiler does not compile the code at all or it will through syntax error or other errors. That’s why statically typed language becomes fast and light-weight.

But statically typed languages limit some programming features as well. It prevents to extend object-oriented features. That means, statically typed programming language is not fully object-oriented or not at all.

Popular Statically Typed Language

Many widely used programming languages are statically typed. Some popular statically typed programming language seems to be:

C Pascal
C++ ML
C# Scala
Ada Perl
Java Fortran
Jade Haskell

Statically Typed Example in C

When data types are defined while declaring variables is called statically typed language. C is one of the popular and worldwide general-purpose and statically typed languages since 1972. See the example below of the statically typed program.

#include <stdio.h>

int main() {
    int x = 5, y = 10, total;
    total = x + y;
    
    printf("%d\n", total);

    return 0;
}

In the above example, we declared two variables called x and y. But we have also defined the data type int that indicates to store integer data in those variables. To learn more about C variables, click here

Tags