i think both statements shd give error. as u r trying to change int to const
int in 2 and const int to int in 1..
On 7 June 2010 19:59, mohit ranjan shoonya.mo...@gmail.com wrote:
@Raj,
no they are not same
case 1: i is const
case 2: ptr is const
and whatever is const cann't be modified
@Mohit: If u're saying that in case 2 ptr is const then what is int *const
ptr. I thought this is a constant pointer. Constant pointer is one which
can't be made to point to any other address rit? How is *ptr++ coming into
the way of constant pointer ?
On Mon, Jun 7, 2010 at 7:59 PM, mohit ranjan
Actually the first statement i gave const int i=5; int *ptr=i is itself
giving an error on gcc and a warning on borland. We have to modify it as
const int *ptr=i otherwise it gives illegal pointer conversion error.
On Tue, Jun 8, 2010 at 12:11 PM, divya jain sweetdivya@gmail.comwrote:
i
@Raj,
Sorry for the confusion
yes, you are right that 1st one is giving warning/error
though for 2nd case
int i=5;
const int *ptr=i;
*ptr++;
i am nt getting any error/warning (gcc) and i remains 5
but
int i=5;
const int *ptr=i;
(*ptr)++;
is giving error
Mohit Ranjan
On Tue, Jun 8, 2010
Can someone tell me the difference between
1) const int i=5; 2) int i=5;
int *ptr=i; const int
*ptr=i;
In the first case i can be modified via ptr i.e *ptr++ is valid. In
the second case *ptr++ is illegal. Why is that so? Aren't
@Raj,
no they are not same
case 1: i is const
case 2: ptr is const
and whatever is const cann't be modified
Mohit Ranjan
On Mon, Jun 7, 2010 at 3:01 PM, Raj N rajn...@gmail.com wrote:
Can someone tell me the difference between
1) const int i=5; 2) int i=5;
1) const int i=5;2) int i=5;
int *ptr=i; const
int*ptr=i;
On Mon, Jun 7, 2010 at 3:01 PM, Raj N rajn...@gmail.com wrote:
Can someone tell me the difference between
1) const int i=5;