The num is array with numbers, so num[0] is the first number. Then it’s one-by-one compared to other numbers, and if any of them is smaller or larger, then that value is replaced by another number.
You are not comparing the first value, you are comparing all values “starting” with the first.
You start with the first because you need to make sure, that smallest/largest are numbers actually present in the array.
Imagine you have both initialized with 0, but the array is [1,2,3,4,5] → suddenly “smallest” would still have the initial value of 0, despite the array not having any 0.
That’s already happening in the code.
Except largest/smalles are initialized at the beginning of the program and then overwritten with num[0] after the input.
It’s common practice to create all variables at the start, that are used throughout the program.