What does the word “semantic” mean in Computer Science context?

Semantics are the meaning of various elements in the program (or whatever).

For example, let’s look at this code:

int width, numberOfChildren;

Both of these variables are integers. From the compiler’s point of view, they are exactly the same. However, judging by the names, one is the width of something, while the other is a count of some other things.

numberOfChildren = width;

Syntactically, this is 100% okay, since you can assign integers to each other. However, semantically, this is totally wrong, since the width and the number of children (probably) don’t have any relationship. In this case, we’d say that this is semantically incorrect, even if the compiler permits it.

Leave a Comment