Declaring One-Dimensional Arrays: Definition & Example

An error occurred trying to load this video.

Try refreshing the page, or contact customer support.

Coming up next: Array Initialization in C Programming

You're on a roll. Keep up the good work!

Take Quiz Watch Next Lesson
Your next lesson will play in 10 seconds
  • 0:04 Arrays in C…
  • 1:01 Syntax
  • 1:32 Adding Elements to Arrays
  • 2:16 Using an Index or Loops
  • 3:10 Example
  • 3:21 Lesson Summary
Save Save Save

Want to watch this again later?

Log in or sign up to add this lesson to a Custom Course.

Log in or Sign up

Speed Speed

Recommended Lessons and Courses for You

Lesson Transcript
Instructor: Meghalee Goswami
In this lesson we discuss the concept of arrays in the C programming language. The basic type of array is called a one-dimensional array. We also go through the usage of arrays in C and why they are so important.

Arrays in C Programming Language

Arrays are fixed length data structures that store homogeneous data. The word 'homogeneous,' in this scenario, means that an integer array can only store integer values, a character array can only store characters, etc.

An array is also a sequential data structure which means all the elements are stored in sequential memory order. In simple terms, you may think of an array as a collection of similar variables. Each element of the array is represented as array_name[0], array_name[1], array_name[2], and so on, until array_name[n-1], where n is the number of elements in the array. The array naming convention follows the same set of rules as other variables.

The first element of the array is indexed at 0. In the following example the array name is num and the elements are represented as num[0], num[1], num[2]... until num[lengthOfArray-1].

Arrays in C


The general syntax for declaring an array in C is as follows:

data-type arrayName [arraySize];

This type of an array is called a single dimensional or one dimensional array. Please note that the size of the array needs to be a positive integer value greater than 0. The data type can be among any of the data types supported by C. For example, if you want to create an array of 10 elements holding integers, the declaration would be as follows:

int arrayInteger[10];

This statement creates an array called arrayInteger capable of holding 10 elements.

Adding Elements to Arrays

There are a number of ways to add elements to an array. This could be done by initializing one element at a time or doing it all together in a single statement. Some examples using the array called arrayInteger are shown here:

int arrayInteger[3] = {10,20,30};

This creates an array of size 3 with the name arrayInteger and initializes arrayInteger[0] as 10, arrayInteger[1] as 20, arrayInteger[2] as 30. The size of the array has to be specified inside the square brackets [] and the elements have to be assigned inside the { }, separated by commas.

int arrayInteger[] = {10,20,30,40};

If the size of the array is not specified in [], an array is created which is large enough to hold the number of elements listed inside the curly braces {}, 4 elements in this case.

Using an Index or Loops

An element of the array can be accessed using the index of that element and assigned one at a time to the required values. For example, if you want to access the 4th element of arrayInteger (please note the index of the element is (4 - 1) = 3.)

int fourthElement = arrayInteger[3];

To unlock this lesson you must be a Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use

Become a member and start learning now.
Become a Member  Back
What teachers are saying about
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create an account