0

I have the question about this codec.

I know sizeof(struct baseball) = 16.
what's the sizeof(Yankees)?

Also,
What will these cout s yield?
cout <<Yankees[2].player;
cout <<Yankees[2].Bbp->player;
cout <<BigPointer+1);

#include <iostream>
using namespace std;

int main()
{
	struct baseball
	{
		char   *Player;
		int    Hrs;
		float  average;
		struct baseball *Bbp;
	};

	struct baseball Yankees[]= {
	"Mantle",     52, .313, Yankees + 1,
	"Maris",      61, .291, Yankees + 2,
	"Richardson", 23, .252, Yankees + 3,
	"Boyer",      18, .301, Yankees + 4,
	"Skowron",    31, .281, NULL},

	*BigPointer = Yankees;
	cout << sizeof(struct baseball);
	cout <<"\n";

	cout << sizeof(Yankees);
	cout << "\n";
}
2
Contributors
1
Reply
2
Views
11 Years
Discussion Span
Last Post by Ancient Dragon
0

>>I know sizeof(struct baseball) = 16.

Not necessarily -- that is compiler implementation dependent. Just because one compiler says its 16 doesn't mean it will be the same for all compilers.

The sizeof(Yankeys) is the sizeof(struct baseball) * numer of elements in the Yankeys array. And the number of elements in Yankeys array is calculated like this:

sizeof(Yankeys) / sizeof(Yankeys[0])

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.