GeekInterview.com
  I am new, Sign me up!
 
Home C
 

Base Address of the String

 
Category: C
Comments (0)


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.



Read Next: Position of Substrings



 

 

Comments



Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact  

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape