Abstract

This chapter provides an overview of pointers and their usage to the best programming advantage. Unlike single-element variables, char arrays offer more sampling variations. The address of the start of the array can be found by using the array name, c, which is a pointer to the start of array storage as an argument to a printf() function that contains the & u conversion specifier. The entire contents of this array can be displayed by using c again, still a pointer, as an argument to a printf() function that contains a %5 conversion specifier. To continue, the address of any single element in the array is obtained by using the ampersand unary operator in front of the array name followed by its bracketed subscript. It is necessary to use the %u specifier again. If one merely wants the object stored by a single array element, the element name without the ampersand is used with a %c specifier. For all intents and purposes, each element in a char array is treated exactly like a standard variable of type int, except that only 1 byte of storage is allocated instead of 2. However, the entire contents or combined contents of the array are also accessed as a single unit. This provides great flexibility, uncommon to many other languages, and should not add a great deal of confusion if one is aware of the two-part nature of character arrays. The first part is that of a group of individual values. The second part is the string, which is all of these values rolled into a single unit.

Full Text
Paper version not known

Talk to us

Join us for a 30 min session where you can share your feedback and ask us any queries you have

Schedule a call

Disclaimer: All third-party content on this website/platform is and will remain the property of their respective owners and is provided on "as is" basis without any warranties, express or implied. Use of third-party content does not indicate any affiliation, sponsorship with or endorsement by them. Any references to third-party content is to identify the corresponding services and shall be considered fair use under The CopyrightLaw.