networking · beginner · ~15 min
Recall the privileged port range.
Decide whether a port is in the "well-known" range — ports 1 through 1023, which require privilege (root) to bind.
Implement int is_well_known_port(int p) that returns 1 if p is in the well-known range 1..1023, otherwise 0.
One int p.
Returns 1 if 1 <= p <= 1023, else 0.
is_well_known_port(80) -> 1
is_well_known_port(1023) -> 1
is_well_known_port(1024) -> 0
is_well_known_port(0) -> 0
One integer p.
1 if 1 <= p <= 1023, else 0.
Well-known range is 1..1023 inclusive.
int is_well_known_port(int p) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.