On Fri, Jul 3, 2009 at 10:24 AM, Shakthi Kannan <[email protected]>wrote:
> Hi, > > --- On Fri, Jul 3, 2009 at 9:15 AM, abhishek > sharma<[email protected]> wrote: > | int *p=c; //For this code > | gcc compiles normally without any error or problem > \-- > > This is correct. > > --- > | int c[5]={1,2,3,4,5}; > | > | int *p; > | > | *p=c; //GCC gives a typecast > \-- > > It should be 'p = c'. On the left-hand side of the assignment there > should be an address or LVALUE. On the right-hand side of the > assignment you should have a value or RVALUE. When you do *p on the > left-hand side of the assignment, you are dereferencing the address or > pointer, to get a RVALUE. Hence, the error. > > 1. Don't use // comments in C coding style. > > 2. Initialize your pointer variables, or assign NULL to them. > > int *p = NULL; > > SK > > -- > I agree with Shakthi. When you are doing int *p=c, the compiler does two things: 1. int *p //declare the variable p as type int * 2. p=c // store the base address of the variable a So instead of *p=c, your code should feature p=c. Thanks and Regards Sumit Chakraborty
_______________________________________________ Users mailing list [email protected] http://lists.dgplug.org/listinfo.cgi/users-dgplug.org
