> As it's the first time I'm dealing with stuff like this, I'm pretty much confused.
The declaration of a pointer is very straightforward; there is one and only one simple rule to remember:
If T
is a type, then the type T*
is 'pointer to an object of type T
'.
There is nothing else that you have to remember.
For more complex types, just divide and conquer.
> 5) declare ex5 as array 10 of pointer to array 500 of char
1 2 3 4
|
using array_type = char[500] ; // type 'array_type' is 'array of 500 char'
using ptr_type = array_type* ; // type 'ptr_type' is 'pointer to 'array_type'
using ex5_type = ptr_type[10] ; // type 'ex5_type' is 'array of 10 ptr_type'
extern ex5_type ex5 ; // declaration of ex5
|
> declare bar as const pointer to array 5 of pointer to function (int) returning const pointer to char
> (from the gibberish specialist ridicous_fish@
http://www.cdecl.org/ ):
1 2 3 4 5 6 7
|
using pchar = char* ; // pointer to char
using const pchar function_type(int) ; // type of the function
using pfn_type = function_type* ; // type of the pointer to function
using array_type = pfn_type[5] ; // type of the array
using parray_type = array_type* ; // type of pointer to the array
using required_type = const parray_type ;
extern required_type bar ; // declaration of bar
|
Answer from the C gibberish <-> English site:
char * const (*(* const bar)[5])(int )
Completely avoid this gibberish site like the plague; it just takes perverse delight in making a simple thing appear extremely complicated.
> So.. is this what 8th task wants?
>
int blahblah (char *pc) {return (*pc);}
8) write a function that takes a pointer to char named pc, and returns it
If the 'it' in 'returns it' means 'return the value of the pointed char', then yes.
But I guess the 'it' in 'returns it' means returns the same pointer
char* blahblah( char *pc ) { return pc ) ;