answersLogoWhite

0


Best Answer

Arrays are group or set of variables having the same data type. Arrays can hold different values depending on the values assigned to them.

To create (or declare) an array is somewhat similar to declaring a variable. You must first enter the data type, the array name (you can name your array anything you like), then array size enclosed in square brackets.

Example:

int arrNum[5];

Using the example given above, it shows that we declare an integer array with the size of 5. Five (5) is the total elements in an integer array called "arrNum" So there are 0 to 4 (zero to four) arrNum arrays (array counts must always start at zero). Namely:

int arrNum[0];

int arrNum[1];

int arrNum[2];

int arrNum[3];

int arrNum[4];

You can store different integer values at any element of int ArrNum. But, do not assign a value that is beyond the size of the array. It will give you a logical error.

Example:

arrNum[6] = 95;

arrNum[5] = 20;

On the second example above, it will still give you a logical error. We defined arrNum to have 5 elements (from zero to four). So, arrNum[5] is out of arrNum's size capacity. Also, once we declared an array to have a definite size, it cannot be redefined to have more elements than what is declared.

To initialize an array, you may need to use loops, specifically "for loop". You may do it manually (without using loops) but loops are useful with arrays. For example, we want to initialize all elements of arrNum[5] to zero:

int Counter = 0;

int arrNum[5];

for (Counter = 0; Counter < 5; Counter++)

{

arrNum[Counter] = 0;

}

In the example above, we used a for loop to initialize all elements of int arrNum[5] to zero. The loop will only stop if and only if the counter exceeds 4. We borrow the value of the counter to act as the size of the array.

Meanwhile, in using an array of characters (also called character array or String), the size of the string must be the number of string plus one. Example, you wanted to write Fire as the value of string called "Word":

char Word[5]; // Array declaration

Word[0] = 'F';

Word[1] = 'i';

Word[2] = 'r';

Word[3] = 'e';

Word[4] = '\0';

As you can see, we declared an array that is the number of character more than 1. The last element in a string should be a null value denoted by "\0" (backward slash and zero). This will tell the computer that the string will end and no further character will be added.

User Avatar

Wiki User

9y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What do you mean by arrays and explain how to create and initialize arrays in C?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering
Related questions

What does initialize mean?

The term "initialize" means to start, begin, or prepare. Often the word "initialize" is used in context with starting something such as a program or sequence.


What does it mean when you pose a question?

Could mean ask, or initialize somehow.


What does it mean to initialize a memory card?

It means to format


What does initialized mean?

The term "initialize" means to start, begin, or prepare. Often the word "initialize" is used in context with starting something such as a program or sequence.


What words mean the same as start?

Begin, commence, initialize Beginning, commencement Jump, flinch


Can arrays be processed with a single instruction.....without running a loop?

What do you mean by "processed"?


Can ragged arrays created by using java?

I assume you mean that you have a number of rows, and that not all rows have the same number of "cells". Yes, in Java a two-dimensional array is implemented as an array of arrays (each item in the top-level array is, in itself, an array); a 3-dimensional array is an array of arrays of arrays, etc.; and there is no rule stating that all secondary (etc.) arrays must have the same number of elements.


Can you use Endeavor in a sentence?

I shall endeavor to create this sentence for you.


Explain what does spattering of crystals mean?

This a process where crystals are infused with other elements to create a beautiful product


Can arrays be created dynamically?

Yes, arrays can be created dynamically. The following shows how it can be done in C: void f (unsigned n) { int* p = malloc (n * sizeof (int)); /* allocate memory to accommodate n integers */ /* use p... */ free (p); p = 0; }


What does draw arrays to find the factors of each number mean?

Factors are integers that multiply to create a product.3 x 4 = 123 and 4 are factors of 12.Divisibility refers to a number capable of being divided by another number without a remainder: 24 is divisible by 4.


What tis explain?

What does "explain" mean? To "explain" something is to tell in detail what something means.