Hello ladies and gents,

Was wondering if any of you could check this exercise out, I finished it, but, I'm not sure whether Ive got it exactly right, especially the last two definitions.

The exercise is as follows:

- Use typedef to define the types unsigned char, const unsigned char, pointer to integer, pointer to pointer to char, pointer to array of char, array of 7 pointers to int, pointer to an array of 7 pointers to int, and finally, array of 8 arrays of 7 pointers to int.

This is what I have:

include <iostream>

int main()											//Use typedef to define the following types
{
	typedef unsigned char UChar;					//unsigned char
	UChar ch = 'a';
	std::cout << ch << "\n\n";
	
	typedef const unsigned char CUChar;				//const unsigned char
	CUChar cch = 'b';
	std::cout << cch << "\n\n";

	int myInt = 0;									
	typedef int *pINT;								//pointer to integer
	pINT pI = &myInt;
	std::cout << &myInt << " == " << pI << "\n\n";

	typedef char **ppCHAR;							//pointer to pointer to char

	typedef char *mychArr[];						//pointer to array of char


	typedef int *apINT[7];							//array of 7 pointers to int

	typedef int **ppMYARRAY[7];						//pointer to an array of 7 pointers to int

	typedef int *pMYARRARR[8][7];					//array of 8 arrays of 7 pointers to int

	std::cin.get();

	return 0;
}

Recommended Answers

All 4 Replies

> typedef int **ppMYARRAY[7]; Thats array of [7] pointers to pointers to int typedef int *(*ppMYARRAY)[7]; pointer to an array of [7] pointers to int

There's a program to help with the complicated ones.
http://packages.debian.org/stable/devel/cdecl

Here's an article on how to read those complex beasties.
http://www.codeproject.com/cpp/complex_declarations.asp

commented: Thanks for those links Salem +3
commented: Impressive, you live upto your reputation Mr. Salem - ~s.o.s~ +7

Thanks for the correction and those links Salem, I always wonder how you guys come up with such good links you know :)

I always wonder how you guys come up with such good links you know

Err...I hope you know that he is not exactly a 12 year kid . :mrgreen:

Going into professional software development, hauting the google groups and various forums is what makes a good programmer. (and of course dedication and interest)

Err...I hope you know that he is not exactly a 12 year kid . :mrgreen:

Yeah, figured that out once I saw the way he killed of those void main'ers :cheesy:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.