@Aichan
Yes and no, the Yamato did have impressive firing capabilities, said to reach 42km of distance (impressive, definitely, useful, arguable at best), but it had flaws, first, it didn't have firing assistance made of radar (it was visual, the spotter planes could assist, but against a fighter squadron of a carrier, that was as good as gone so it can't be considered against a carrier), and its armor was actually weak to torpedoes (it was damaged by a submarine torpedoes and was forced to go back to a port for repairs). But one of the biggest flaws of that huge range, it's that the crew would need to know the exact position of the ship, it's direction and speed, and calculate the right angles to shoot, which from that perspective makes it kinda pointless to have a huge range that you would have very low chances of actually hitting something that's moving at a very decent speed, and an artillery barrage only need to know where the enemy is and let the hell loose and they have the ground to make the shells explode, a battleship needs to be precise to deal damage, not just shoot and pray that something gets hit because if they do that they only hit the water, and splash water everywhere
As for the carriers, their main advantage it's that that they can attack for long distances and with pretty good accuracy. During the battle of Midway, both carrier groups didn't see each other as their planes attacked, and I'm sure that Yorktown, Hornet, and Enterprise were all attacking at a range way longer than 42km, so Yamato's gun would be useless unless it got itself close enough, ut by that time it would definitely be spotted by some scout plane of one of the three carriers (or even from the Midway base itself)
So basically in that fight, it would be Yamato with its main gun's maximum range of 42km, with low precision and low accuracy at that distance, and without any help of spotting planes (since they would be shot down by fighters), against three carriers each carrying around 36 Douglas SBD Dauntless: 1 795 km (1 120 mi), 18 Grumman F4F Wildcat: 1 360 km (845 mi), and 18 Douglas TBD Devastator: 1 152 km (716 mi) (I'm using Enterprise's 1st Deployment: 7 December 1941 - 10 March 1942 fighter planes)
If the Yamato truly went against a carrier in 1942, the only thing she would see would be a bunch of planes coming towards her, dropping bombs and torpedoes, if she survives, she won't be able to hit a carrier because it would be striking her at around 27 times her effective distance. So the Yamato by the time she was being used was useless because the USN was going all-in for carriers, while the Yamato would be a great battleship killer... In a one on one
My sources: http://www.cv6.org/company/airgroups.htm
https://youtu.be/Pot-PNTYopA [IJN Yamato - Guide 082 (Extended)]