Jump to content

help with confusing declarations please

- - - - -

  • Please log in to reply
2 replies to this topic

#1
csepraveenkumar

csepraveenkumar

    Learning Programmer

  • Members
  • PipPipPip
  • 52 posts
in k&r c the following declaration is given to be pointer to array[13] of int
int (*daytab)[13]

on similar lines i initialize a pointer to array[2]of int in my program as follows
int c[2];
int (*d)[2];
d=c;
when compiling this code i get a warning as follows

sizeof.c: In function ‘main’:
sizeof.c:7: warning: assignment from incompatible pointer type

what is generating this warning and how to get rid of it? also are there any good resources for understanding complicated declarations in c?

#2
rocketboy9000

rocketboy9000

    Learning Programmer

  • Members
  • PipPipPip
  • 79 posts
d=&c;


#3
grisha

grisha

    Learning Programmer

  • Members
  • PipPipPip
  • 35 posts
To clarify what went wrong:
The name of the array is a pointer to its first element. So both c and d are pointers to the first elements.
The thing is, that you made d a pointer to a pointer (**) thus the assignment d = c; was invalid since it was char** = char*.
So as rocketboy wrote - you need to get the address of the c variable using & to fulfil the type match requirement.

Hope I've explained it clearly ;)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users