From the Super Mario Wiki
The ? Block (known as the Mystery Block in Super Mario Land and the Prize Block in Super Mario World) is one of the many blocks found in the Mario universe, and one of the most common. Question Blocks are usually seen floating in midair, often containing Coins, Super Mushrooms, or Fire Flowers. In some games (for example Paper Mario and Mario & Luigi: Superstar Saga, as well as several classic platformers) there are some invisible Item Blocks. Beginning in Super Mario Bros. 3, there are different ways to hit the block other than simply punching it from below. One example is when Mario or Luigi use the Super Leaf, Tanooki Suit or Cape Feather, they can use their tails or cape to whack the Question Block. Another example is using the Koopa Shell; Mario or Luigi can kick the Koopa Shell at the Item Block. In New Super Mario Bros. series and Super Mario 3D Land, a Ground Pound may also be used to activate it.
Much mystery enshrouds the ? Blocks, and little detail has been given about their origin. Super Mario Bros., however, gave the explanation that Bowser, using the Koopa Clan's famous dark magic, had cursed the Mushroom Kingdom, turning its citizens (presumably the Toads) into a variety of objects, including bricks (which the ? Blocks could alternately be thought of as). Princess Peach could apparently reverse this spell, so she was kidnapped by the "Koopa Clan". The game's manual later talked about how Mario could "come across Mushroom People who had been turned into bricks" and receive items from them. Although this is the only official origin story of the ? Blocks, it would appear to have been long since retconned out of Mario games, with ? Blocks now seemingly being a natural feature of the Mushroom Kingdom. ? Blocks are not to be confused with Exclamation Mark Blocks, which are similarly floating blocks.
Super Mario series
Super Mario Bros.
Super Mario Bros. is the ? Block's debut appearance in the Mario series, along with a handful of other items. They appear to be flashing and they give Mario either coins or items that can help Mario. They are very common, since they are sometimes needed to complete a level or help Mario in a tough situation. Some blocks are hidden and can be only seen when Mario happens to hit them. Some blocks also release Beanstalks into the air, making it available for climbing.
Super Mario Bros.: The Lost Levels
These blocks reappear in the sequel Super Mario Bros.: The Lost Levels with the exact same appearance and function. No changes have been made to these blocks, but certain ? Blocks can contain the new tricky non-Power-up, the Poison Mushroom, which were introduced in The Lost Levels as well.
Super Mario Bros. 3
Although absent in Super Mario Bros. 2, ? Blocks have a slightly different design change; they are no longer flashing and the ? marks on the blocks seem to be moving in the game, Super Mario Bros. 3. They still give out coins and other items that can help Mario when hit.
Super Mario World
The Prize Blocks of Super Mario World have eyes and seem to be re-animations of that game's Rotating Blocks. They also are given Rotating Block-like eyes when hit; these expressions-when-hit are often seen even in non-eyed Question Blocks. Otherwise, no function-related changes has been made. There are also flying variants called Flying ? Blocks which fly left to right while moving up and down. A red ? Block only found in the dark area of Bowser's Castle activates a spotlight.
Super Mario 64 DS
In Super Mario 64 DS, red ? Blocks replace the red, blue, and green ! Blocks from Super Mario 64. They are initially transparent, and had to be activated by hitting the ? Switch in a secret level named after the switch. They contain either Power Flowers, Feathers or Bob-ombs, depending on character and hat status.
New Super Mario Bros.
In New Super Mario Bros., red Flying ? Blocks similar to the ones from Super Mario World fly around the world map, moving to different levels every time Mario or Luigi lose a life, complete a level, enter a Toad House, etc. Five items can be inside: a Fire Flower, 1-Up Mushroom, Mini Mushroom, Mega Mushroom, or a Blue Shell. Normal Flying ? Blocks from Super Mario World also appear, but while some of them fly left to right, others only move up and down. Also, in two Ghost Houses, ? Blocks that contain Boos appear. The original yellow ? Blocks also appear and the Beanstalk-sprouting blocks make an appearance again. The game also features rare Spiky ? Blocks in World 6, which only appear in this game. Mario must be careful to hit the block only on a spikeless side. If the player hits the question block fast enough, a mushroom will come out.
Unlike in the other games, where the player can only hit ? Blocks from below or throw something at them to release an object, Question Blocks in this game can also be ground pounded.
Super Mario Galaxy
In Super Mario Galaxy, ? Blocks contain Star Bits and coins, and can usually be hit multiple times before vanishing. If the player manages to hit a ? Block with Star Bits, it would release a multitude of Star Bits before disappearing. Unlike in New Super Mario Bros., ? Blocks in this game cannot be ground pounded and the ? are flashing.
New Super Mario Bros. Wii
The ? Blocks make a return in New Super Mario Bros. Wii. Here, they have the exact function and appearance as in New Super Mario Bros. but some behave differently from the average stationary ? Block. In some levels, for example, some blocks tend to sway left and right along with other objects such as brick blocks and coins. Others lay in the water in some levels, where it is easier to ground pound them. Flying ? Blocks also appear, acting the same way as in the previous game, but the red ones that appear in the map didn't reappear. There is also a species called a Ghost Block.
Super Mario Galaxy 2
? Blocks from Super Mario Galaxy re-appear in Super Mario Galaxy 2. In this game, they once again release a bunch of Star Bits when hit. Like in Super Mario Galaxy, coins can be released one at a time from Coin Blocks. Question Blocks that release one Star Bit at a time when hit repeatedly do not return. The Flying ? Blocks from Super Mario World also appear, and they act the same; however, they don't move up and down while flying, and they vanish when they are hit, the same as normal ? Blocks in this game. They make chirping noises while they fly (like a bird).
Super Mario 3D Land
? Blocks appear in the Nintendo 3DS game, Super Mario 3D Land. Unlike past 3D Super Mario games, they can be activated with a Ground Pound and transformed into Blocks. Like past Super Mario games, they can produce items, such as the Super Leaf. A rare wearable version called the Question Box is introduced, which continuously provides coins to the player as he moves or jumps. Like the Propeller Box, if the player finishes a level with a Question Box, he is awarded an extra life and the box is removed. Rectangular ? Blocks are also introduced, which have the same effect as a normal block; however, they give the player three coins in one hit and can contain items.
New Super Mario Bros. 2
The ? Blocks reappear in New Super Mario Bros. 2. Rectangular ? Blocks from Super Mario 3D Land also reappear, with the same function as before. The rectangular blocks are also used as the platforms Reznors stand on.
New Super Mario Bros. U
Super Mario 3D World
Both regular ? Blocks and Rectangular ? Blocks reappear in Super Mario 3D World. The wearable Question Box from Super Mario 3D Land also appears, except this time they can only be produced after hitting a Coin Block enough times, similar to the Gold Block from New Super Mario Bros. 2. They are also shinier than a regular ? Block.
Occasionally, hitting a ? Block would make an 8-bit sprite of Luigi pop out of the block.
Super Mario Land
? Blocks can be found once again in Super Mario Land. Here, they serve the exact same purpose and function as the previous games they appeared in.
A similar block can be found in Yoshi's Story. This time, they are known as the Mystery Crate.
Paper Mario series
In the Paper Mario series, red ? Blocks contain badges and yellow ones contain coins or items. ? Blocks are sometimes invisible at first. They are turned visible by jumping into them (or using Watt in Paper Mario and Tippi in Super Paper Mario). Once they are visible, they can also be used as stepping stones.
In Paper Mario: The Thousand-Year Door during Bowser's event, Meat will come out of the ? Blocks. If the player obtains four of these Meats, Bowser will grow huge, allowing him to smash through objects.
In Paper Mario: Sticker Star, ? Blocks have their sides peeled off upon being hit. Additionally, Mario can use Kersti's "paperizing" power to create these blocks from small sized stickers from his album. All the player needs to find is a small "paperizing" zone with red dotted outlines. From there Mario can stick any small sticker, except Thing stickers, to it. Most of the time, when Mario hits the ? Block which he just created after "paperizing", the sticker he used to create it will come out differently; mostly the sticker's outcome will either become a better class sticker (e.g. from a Hammer Sticker to a Shiny Hammer Sticker) or into another different type of sticker (e.g. from a Hammer Sticker into a Jump Sticker). Rarely, when one sticker is used to create a ? Block, three stickers will come out of it.
Mario Kart series
In the Mario Kart series, from Super Mario Kart and onwards, similar item blocks, called Item Boxes are found on every track. However, they are usually not flying up in the air but they are floating on the ground and they are usually semi-transparent and reappear when they get hit.
In Mario Kart Wii, on the track Coconut Mall, there is shop that is selling ? Blocks along with other classic Mario items. In the track Grumble Volcano, there are giant ? Blocks on some of the sinking mountains, along with regular Brick Blocks.
Super Smash Bros. series
? Blocks make an appearance as objects in the latter two games in the Super Smash Bros. series. In Super Smash Bros. Melee, ? Blocks appeared on the Mushroom Kingdom stage and can contain items if attacked or simply smashed from below. They also appear in Super Smash Bros. Brawl in the Mushroomy Kingdom stage, with the same purpose.
Mario & Luigi series
? Blocks are one of many types of block to appear in the Mario & Luigi series. They can give Mario and Luigi coins or items that can help them, similar to the series the blocks normally appear in. One hit on, they turn brown and they won't offer any more items. If Mario and Luigi happen to have 99 of the item found in the block, the item will remain in the block. This also applies if the player has 9999 coins.
In Mario & Luigi: Superstar Saga, there is a room in the Woohoo Hooniversity which is designed to study different kinds of ? Blocks. The blocks found in this room are from Super Mario Bros., Super Mario World, Paper Mario and Super Mario 64.
In Mario & Luigi: Bowser's Inside Story, ? Blocks look more like those in New Super Mario Bros.. This game also featured a character named Broque Monsieur, who appears to be made from ? Blocks. Some other characters such as Broggy and Broque Madame also appeared to be made from blocks.
In Nintendo Land, presents resembling ? Blocks can be won from the pachinko minigame found in the central tower of the main plaza. For every stage completed in the minigame, a ? Block will fly out of the tower. After locating the ? Blocks on the plaza grounds, the player can tap them open to reveal different prizes based on objects found in the 12 attractions of the game. Mini ? Blocks also appear on the Jukebox prize and when tapped, will unlock a song the Player can play in the main plaza.