Base Address of the 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.

This concept is explained below with the help of a small program.

For instance consider the program

main()
{
static char samp[] = “Knowledge Base articles provided by Exforsys “
samp++;
printf(“%c”,*samp);
}

In the above program samp refers to the base address of the string. Using this base base address, the whole string is identified and therefore samp is considered as constant as explained before. 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.

Editorial Team at Geekinterview is a team of HR and Career Advice members led by Chandra Vennapoosa.

Editorial Team – who has written posts on Online Learning.


Pin It