I have the Starter Edition of WoW, so my level cap is 20. If I complete quests at my level 20 level cap and then buy the full game, will the XP I could have gotten but didn't get because I was level 20 be wasted, or saved up and given to me after I buy the full game?
No, any experience you earn in excess of the cap is lost.
It's not explicitly called out on the starter edition page, but it's the same mechanic used for the expansion trials. There's no "saving up experience" that can't be immediately applied towards the next level.
Likewise, if you reach the level cap for an expansion without having purchased the next expansion, you stop gaining experience upon reaching the level cap. E.g. if you bought Cataclysm but not Mists of Pandaria, your character would hit level 85 and stop earning/banking up new experience. You would also not earn rested experience until you unlocked the levels beyond the level cap by purchasing the expansion (and any rested bonus you had upon reaching the cap would be lost).
Also, if you played an expansion as a trial, you would have a similar experience restriction. For example, players who are using the Mists of Pandaria trial would hit one experience point below level 86 and then stop gaining experience from anything.
That is not true. I just finished the trial after not playing for seven plus years (wanted to know if it was something I could get back into before I purchased it) then capped out at 20 and got mad I couldn’t do anything. So I then began just running around killinrandom things and seeing what I could and couldn’t do. A few days later I go sick of that and bought the game downloaded it and logged in. I logged in and instantly became a lvl 22. The experience does stay with your toon. But I only waited a few days. I don’t know if it expires.