How to Initialize an Array

Save
Next Video:
About Different Types of Processors....5

Initialize an array by creating a program that includes an iostream, an array of integers and an initialization loop. Run the output for a program to see whether the array runs correctly with help from a software developer in this free video on computers.

Part of the Video Series: Computers Tips & Advice
Promoted By Zergnet

Comments

Video Transcript

Hi, my name is Dave Andrews. Today I'm going to show you how to initialize an array. Let's go to our computer and I have a little program here. The first thing I've done is include iostream which is a C method of or gives us the objects to print data out to the screen like this STD cout object is available in iostream. The very first thing that I do in my main function is I create an array of 5 integers which will store 5 numbers in memory. Now this next for loop is my initialization loop. It basically loops through that array and it sets each value of the object to the current number. So j is going to go from 0 to 5 which means it will be 0, 1, 2, 3, 4 and each of those val objects will be assigned to the current number. So if I go back afterwards and print out those values in my next for loop here, it should basically print out the values that are in the val array which is going to be 0 through 4. So I'm going to compile my program here for you and I'm going to show you that my array has successfully been initialized in this for loop here. Now that my program is compiled, I'm going to run the output and as you can see, I get the values 0 through 4 as output from my array. My name is Dave Andrews and I've just showed you how to initialize an array.

Featured

Related Searches

M
Is DIY in your DNA? Become part of our maker community.
Submit Your Work!