News:

Choose a design and let our professionals help you build a successful website   - ITAcumens

Main Menu

Base Address of the String !

Started by krishnan, Jul 29, 2008, 08:03 PM

Previous topic - Next topic

krishnan

Hi [you],

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.