Click here to Skip to main content
15,891,682 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi

I want to know is there any difference between (*char) and (char*) , (*float) and (float*) and simillars?

Also what is then difference between these codes :
C++
int(*p)[3];

and
C++
int *p[3];


Thank you !
Posted
Updated 14-Jan-14 5:54am
v2

1 solution

As far as I know (*char), (*float) are noty valid C constructs.

(char *) and (float *) are used to cast respectively to pointer to char and pointer to float, e.g.

C
char * pc = (char *) malloc( 100 );
char * pf = (float *) malloc( 100 * sizeof(float));


int(*p)[3]; declares p as a pointer to an array of three integers:
C
int(*p)[3];
int k[3] = {1,-2,0};
p = &k;



int *p[3]; declares p as an array of three pointers to integers:
C
int *p[3];
int i=5;
int j=7;
p[0] = &i;
p[1] = p[2] = &j;
 
Share this answer
 
Comments
Stefan_Lang 15-Jan-14 4:27am    
You're correct. At least in C, "*char" produces a syntax error. See http://cdecl.ridiculousfish.com/?q=*char
CPallini 15-Jan-14 4:32am    
I'm correct, of course :-)
Nice link.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900