Prashant Dixit said:
(Sun, Jan 30, 2011 03:21:07 AM)
There must be an error in this program because ptr is declared as of constant type and it can not be modified so value of j can not be stored in ptr.
Himanshu said:
(Mon, Feb 21, 2011 10:17:35 AM)
Can't get it. Please explain it in step by step procedure.
Sundar said:
(Fri, Mar 18, 2011 12:15:37 PM)
Output:
In Turbo C (under DOS - 16 bit platform)
i = FFF4 ptr = 10 j = FFF2 ptr = 20
In GCC (under Linux - 32 bit platform)
i = BF93368C ptr = 10 j = BF933688 ptr = 20
I hope this may be help you a bit. Have a nice day guys!
Ajay said:
(Sat, Jul 9, 2011 02:11:26 PM)
const int *ptr = &i;
It declares a pointer which points to integer of constant type.
Pointer is not constant.So we can change it.
Sharath said:
(Thu, Jul 14, 2011 09:50:27 PM)
We can change the value of constant pointer
Sharath said:
(Thu, Jul 14, 2011 10:02:19 PM)
int i=10;
const int *ptr=10; //correct
*ptr=&i; //correct
*ptr=10; //wrong
Siva Pavan said:
(Wed, Sep 14, 2011 10:58:29 PM)
Coming to 2nd printf statement, since in pointers &p represents address,*p represents value then clearly p is declared as pointer preccedding by const keyword so its value is always constant since it is addressed to x(p=&x) the only possible value for p is x value i.e 10.
Karun Das said:
(Thu, Feb 16, 2012 09:21:52 AM)
Yes, here an object is a constant, we can't change pointer here,
Totally confusion, please correct me if I am thinking in incorrect way.
Rupinderjit said:
(Mon, May 21, 2012 10:09:02 PM)
Here object is constant not pointer pointed to by it. So ptr can point to any other address unless we declare int const*ptr=&i;, here pointer points to particular location is constant not an object.
Ashok said:
(Fri, Oct 5, 2012 11:37:21 AM)
"const int *ptr" means ptr is a pointer to const integer so we can modify ptr value.
Where as "int const *ptr" is different one it means ptr is const pointer to int whose value could not be changed. We have to define it at the declaration of that pointer itself.
Vineet Yadav said:
(Mon, Mar 18, 2013 10:02:29 PM)
const int *ptr;
int const* ptr;
It means pointer points to const integer value. that means we cant change the value of that integer but pointer can change its pointing location.
int * const ptr;
const * int ptr;
It means that pointer is constant here, it can point to an integer and then it cant change its pointing location.