<br><br><div class="gmail_quote">On Fri, Jul 3, 2009 at 10:24 AM, Shakthi Kannan <span dir="ltr"><<a href="mailto:shakthimaan@gmail.com">shakthimaan@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>
<br>
--- On Fri, Jul 3, 2009 at 9:15 AM, abhishek<br>
<div class="im">sharma<<a href="mailto:emote2abhishek@gmail.com">emote2abhishek@gmail.com</a>> wrote:<br>
| int *p=c; //For this code<br>
| gcc compiles normally without any error or problem<br>
</div>\--<br>
<br>
This is correct.<br>
<br>
---<br>
<div class="im">| int c[5]={1,2,3,4,5};<br>
|<br>
| int *p;<br>
|<br>
| *p=c; //GCC gives a typecast<br>
</div>\--<br>
<br>
It should be 'p = c'. On the left-hand side of the assignment there<br>
should be an address or LVALUE. On the right-hand side of the<br>
assignment you should have a value or RVALUE. When you do *p on the<br>
left-hand side of the assignment, you are dereferencing the address or<br>
pointer, to get a RVALUE. Hence, the error.<br>
<br>
1. Don't use // comments in C coding style.<br>
<br>
2. Initialize your pointer variables, or assign NULL to them.<br>
<br>
int *p = NULL;<br>
<br>
SK<br>
<font color="#888888"><br>
--<br>
</font></blockquote></div>I agree with Shakthi. <br><br>When you are doing int *p=c, the compiler does two things:<br><br>1. int *p //declare the variable p as type int *<br>2. p=c // store the base address of the variable a<br>
<br>So instead of *p=c, your code should feature p=c.<br><br>Thanks and Regards<br>Sumit Chakraborty<br>