You are here:About>Computing & Technology>C / C++ / C#> C> C Tutorials> Finishing the Lesson
About.comC / C++ / C#

C Tutorial - Lesson Three - About Chars

From David Bolton,
Your Guide to C / C++ / C#.
FREE Newsletter. Sign Up Now!

Finishing the Lesson

Pointers can be quite challenging to learn. The diagram should provide a better insight.

The variable name (a pointer to a char) was located at address 0x007fe78. A pointer is 32 bits, ie. 4 bytes long and holds an address of the string which was 0x00408004. Addresses are always given in hexadecimal. The arrow shows what the pointer is pointing to, ie what is at the address in the pointer variable.

At this address there were 13 bytes holding the string "David Bolton" with a terminating NULL, the same value as '\0'.

Arrays and Pointers are the Same

Modify the existing program and change the declaration of the pointer variable to this.
char name[]="David Bolton";

Compile and run it and you should get the same as before. In C an array and a pointer are really the same thing. They refer to a memory address. Obviously you cannot change the array at runtime (as you can a pointer) but being able to use an array this way can be useful.

That finishes this lesson. In the next lesson we'll start looking at expressions in C.

  1. All about Chars
  2. Assigning Strings using Pointers.
  3. Finishing the Lesson

<< Previous | Next

 All Topics | Email Article | Print this Page | |
Advertising Info | News & Events | Work at About | SiteMap | Reprints | HelpOur Story | Be a Guide
User Agreement | Ethics Policy | Patent Info. | Privacy Policy©2008 About, Inc., A part of The New York Times Company. All rights reserved.