C / C++ / C#

  1. Home
  2. Computing & Technology
  3. C / C++ / C#

C Tutorial - Lesson Three - About Chars

By David Bolton, About.com

3 of 3

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.

Explore C / C++ / C#

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

C / C++ / C#

  1. Home
  2. Computing & Technology
  3. C / C++ / C#
  4. C
  5. C Tutorials
  6. Finishing the Lesson

©2009 About.com, a part of The New York Times Company.

All rights reserved.