As the word suggests, I would say that you can only discuss coupling if you have at least two elements involved.
Saying that scanf()
, by itself, is coupled, does not make much sense to me.
Given two modules (two functions, two classes, ...) they may be more or less "coupled" depending on how much one depends on the other.
For example, they may share a global variable or (a file) so that if one alters it, the other is affected too. Or they must be called in a certain order (or they won't work).
Too tight coupling is a bad thing from a maintenance perspective, you may change something in a module and later discover that you introduced a bug in another module!
From this perspective I can't think of any function in the standard C library on which scanf()
may depend. But even if there were one it would be a problem for the standard library mainteners, not for programmers.
Cohesion, instead, refers to the fact that a module (again: a function, a class, ...) performs a single, identified task. The worst you can have is when you have a function that performs two (or more) unrelated tasks just because they can be performed at the same time. For example you have a function that computes the average of a set of numbers and cleans up the directory where you will store the results.
This is bad from a clarity point of view (and hence, you are increasing the chance of bugs) and from a reuse point of view (little chance you will ever call that function again in the program).
As far as I can tell, scanf()
does a single job (reading a set of values from stdin according a pattern) and does it well.