Sorry, what are flags? I kinda get it but not...really...
When you encounter or capture a Pokemon, the game sets a bit in memory to notate that you have seen/caught that pokemon. This way, the Pokedex will be able to accurately show all the Pokemon you've seen and caught.
This is all done by means of an array. There are 19 bytes to store whether the pokemon have been caught, followed by 19 bytes to store seen pokemon. Since there are 8 bits in a byte, each of these arrays can hold the data for 152 pokemon. The game has a somewhat complicated way of determining which pokemon corresponds to which byte, but it basically follows that the higher the dex number, the later in memory the pokemon's bit will be.
This all works dandy if the dex numbers are from 1-151, as it should be. But, since some glitches have a dex number outside of that range, it is possible for the game, when setting the bit to say "this pokemon has been encountered," sets a bit beyond the 19 bytes allocated for "encountered pokemon." What happens to be stored after the pokedex encounter array is the list of items you have. So an encounter with a glitch with dex number not from 1-152 (e.g. Missingno.) will change either the number of item slots you have, the quantity of an item, or the identity of an item. These effects can be completely predicted by looking at the dex number, as I stated in my first post.