All of cell's values are "1" into stream network. Later, stream link seperates the segments using stream order tool. And, each stream segment has different grid codes. How do Stream Order discriminate the pixels of the same value "1"? If it considers the junction between links, how is it getting the value?
I gave a fairly detailed description of how these types of stream network operations work in my previous answer here. But if you're looking for the exact algorithmic solution for how stream cells are recognized in the stream link raster and how confluences (junctions) are spotted in the network then you may look at the following source code as examples:
The first is a stream ordering tool and the second is a stream link tool. All of these tools work in a similar fashion. You'll notice that stream cells are identified as being any grid cell with a value greater than zero (if (streams.getValue(row, col) > 0)) and that confluence cells are those where the number of inflowing stream cells are greater than one ( if (numNeighbouringStreamCells > 1)). The number of inflowing stream cells is determined using the combination of the flow direction grid values and the stream network grid values. Basically the algorithms work by tracing a flow path starting at a stream head cell downstream until it finds a junction cell. Then a new value is assigned to the newly encountered stream segment.