Re: Re: Understanding Pointers and Strings

Home Forums C Programming Understanding Pointers and Strings Re: Re: Understanding Pointers and Strings


To understand the problem completely, remember that arrays are configured as contiguous blocks of memory ( the first index in memory precedes the next and so on ) and realize the fact that pointers are simply variables that hold the address of other variables ( the size depends on your hardware and operating system ). Also keep in mind that in C the semantic value of an array’s name is the address of the first item in the array ( array [ 0 ] ). So that in your program you have a situation like :

since the array looks like this in memory ( let 0x0065fd94 be the first address of the array ):

memory address item
0x0065fd94 ‘T’
0x0065fd95 ‘h’
0x0065fd96 ‘i’
0x0065fd97 ‘s’

and so on your loop:

starts at index == words [ 11 ] which is ‘h’ and continues until ( *index == *(index + len); ) . But since * ( index + len ) is words [ 32 ] == ‘h’ your loop never executes. I think what you wanted to do is this: