That covers the locomotives.
With railway cars, it's a different matter. Today, the majority of railway cars are lease cars. One of the major suppliers of lease cars is TTX - originally known as Trailer Train.
TTX Home They have a fleet of over 210,000 - intermodal, autorack and general use. You are probably familiar with the yellow autoracks with the logos of major railways on the side. However, look at the reporting marks (the car numbers preceded by letters) and you will see that the autoracks have TTX (or a combination thereof). For the yellow double-stack intermodals, you will see DTTX. TTX is owned by their primary customers - all of the major Class 1 railways in North America, including CN and CP.
In addition to their lease cars, TTX provides fleet management services to the major railways. They are specialists in the management of railcar fleets so it is quite common to see Norfolk Southern on CP Rail in Eastern Ontario. In this case, the NS car probably delivered product to southern Ontario. In days gone by, this car would have been immediately returned empty to NS. However, TTX knows that CP needs a car in Smiths Falls to load mechanics tool boxes manufactured by Stanley Tools. So the NS car is sent empty to Smiths Falls where it is loaded with the tool boxes and then returned to a customer on the NS line. For more info, click on this link
TTX - Boxcar and Gondola and look at the top right-hand box.
Because of free trade, multi-national markets, the consolidation of smaller railway lines into a few major railway lines, the efficient management of a railcar fleet has become more important. In the same way that a rolling stone gathers no moss, an empty car gathers no revenue. Fleet management has become more important which is where TTX steps in. Many Class 1 railways no longer manage their railcar fleets - they hand the job over to TTX.
"X marks the car", the X indicating that it is a private car not owned by the railways. It is very common to see lots of "X" cars that look like railway cars. For example, look for the cars marked CNLX or CPLX. These cars have CN and CP logos on their sides. Actually, they're CN and CP lease cars.