O'Reilly logo

C Programming: Visual Quickstart Guide by Marc Liyanage, Larry Ullman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Assigning Values to Arrays

You can initialize arrays (assign values to them) in one of two ways. First, you can do it one element at a time. Second, you can assign all of the values when declaring the array (just as you can assign values to any variable when you declare it). Let's go over both approaches in more detail.

Assigning values to one element

Assigning values to array elements is similar to assigning values to any other variable: you use the assignment operator. The one distinct difference is that you must indicate the index to which the assigned value should apply. But first, a quick word about indexes in C.

Strange as it may seem, arrays in C are indexed beginning at 0. So the first element in an array called answers is answers[0] ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required