Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

The GNU C Programming Tutorial - Array bounds

Node:Array bounds, Next:, Previous:Arrays, Up:Arrays



Array bounds

In keeping with C's free-wheeling, "I assume you know what you're doing" policy, the compiler does not complain if you try to write to elements of an array that do not exist. For example, the code below defines an array with five elements. (Remember, C arrays are zero-based.)

char my_array[4];

Given the line of code below, your program will happily try to write the character * at location 10000. Unfortunately, as may happen when writing to an uninitialized pointer, this may crash the program, but will probably do nothing worse on a GNU system. (See Pointers and initialization.)

my_array[10000] = '*';

The first and last positions in an array are called its bounds. Remember that the bounds of an array are zero and the integer that equals the number of elements it contains, minus one.

Although C will not warn you at compile-time when you exceed the bounds of an array, the debugger can tell you at run-time. See Introduction to GDB, for more information.

 
 
  Published under free license. Design by Interspire