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.
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
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.
Profile Answers by GeekAdmin Questions by GeekAdmin
Questions by GeekAdmin answers by GeekAdmin
Related Answered Questions
Related Open Questions