What happens when we try to change the value of base address of the string?

The base address of the sting takes a special place in the context of strings. This is because suing this base address only the string gets identified. In other words the base address therefore takes the position of constant. As we all know it is not possible to change the value of constants so is the base address. Let us see this concept with the help of a small program.


For instance consider the program



main()

{

static char samp[] = “Knowledge Base articles given by Exforsys “

samp++;

printf(“%c”,*samp);

}



In the above program samp refers to the base address of the string. Hence using this only the whole string is identified and therefore the samp is considered as constant as explained before. No the statement samp++ gives error because it is incrementing the constant which is not allowed and hence compiler throws error for the above program.


One must take care not to change the constant value or the base address of string.

Questions by GeekAdmin   answers by GeekAdmin

Showing Answers 1 - 3 of 3 Answers

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions