0
void main(){
    char *const p="Hello";
    p++;   // causes error object p non modifiable 
}

void main(){
    char A[10]="ANSHU";
    A++;  // here causes lvalue problem  
}

So, my question is, what is difference between these two programs and next question is that is array's declaration like this

int *const A;
user3386109
  • 34,287
  • 7
  • 49
  • 68
  • 1
    You really need to learn basics before hitting the code – Vishal Sharma Aug 11 '16 at 05:19
  • It would be good to re-edit the question, so the meta text "enter code here" disappears and the two code blocks stand as they should ;-) ... and please only one question per question ... it reads a bit like any C (pointer) tutorial out there or existing SO answers already should help ... – Dilettant Aug 11 '16 at 05:19
  • 1
    You can click the [edit] button to finish up your question. – user3386109 Aug 11 '16 at 05:24

2 Answers2

1

In the first program you declared p as const, regardless of its type. So you cannot assign to it after the first initialization. p++ tries to assign to p the value of p+1 and thus fails.

In the second program you used an array. The name of the array, A is actually like a label. You can use it as an address to pass on, but you can't change it.

Israel Unterman
  • 13,158
  • 4
  • 28
  • 35
0

In char *const p="Hello"; p is a const pointer to a (non-const) char. You can change the actual char, but not the pointer pointing to it. So, It cannot point to any other memory location after its initialization. Its important to note that in this statement, the initialization has to be done when declaring this pointer.

In char A[10]="ANSHU"; A is an array object and not a pointer. so you could not use the operation A++ for an array object.

In int *const A; A is a const pointer to int. So, Pointer cannot change, pointed to value can change.

msc
  • 33,420
  • 29
  • 119
  • 214