[dgplug-users] A trivial C concept problem
Shakthi Kannan
shakthimaan at gmail.com
Thu Jul 2 21:54:25 PDT 2009
Hi,
--- On Fri, Jul 3, 2009 at 9:15 AM, abhishek
sharma<emote2abhishek at gmail.com> 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
--
Shakthi Kannan
http://www.shakthimaan.com
More information about the Users
mailing list