This blog is going to be an introduction to how programming languages consider data types. As we know, there are many data types in C programming. C is an example of a strongly typed programming language. Strongly typed means that every piece of data has a specific type.
Imagine if we stored everything in strings. This would become a problem because the computer would never know how to work with certain data. For example, let’s say we have “5” and “6” and we try to add them. Should the computer add the numbers to be “11”, or should it combine the strings to be “56” (The process of combining two strings like this is known as concatenation).
Concatenation doesn’t work quite this way in C, but in general, these are the kinds of problems that come up when we do not have things strongly typed. The opposite of a strongly typed language is called a loosely typed language. Now, a loosely typed language is not quite this loose.
A loosely typed language will usually have a few general types such as numbers, characters, or strings, but they are not nearly as strict with the typing.
What is a good example of this?
In C, if we do something like this: 1/3, the result is going to be zero. That’s because the type of data being used are all integers. A loosely typed language is probably not going to be that obnoxious about types.
The benefit of using a strongly typed language is that it teaches you to be very discrete about what you want the computer to do. I think of a loosely typed language like water: it’s flowy and forgiving. I imagine a strongly typed language as very strict.
Using a loosely typed language can be more simple starting out because you don’t have to worry about all of the different data types, but there is less protection as we will see soon.
Let’s say you write a function (which is just a section of code you can call multiple times) which expects a number. Whoever uses that function can pass in whatever they want, or pass in nothing at all.
With a strongly typed language, you often have to pay extra attention to data types, but you have an extra layer of protection, too. Different people like different things.
In C, it is not easy to flow between data types. Because of this, we need something called type casting. That is what we will be discussing in the next video.
In the next blog we are going to be discussing all of the Type Casting. Check it out!