Skip to player
Skip to main content
Skip to footer
Search
Connect
Watch fullscreen
Like
Comments
Bookmark
Share
Add to Playlist
Report
Learn Programming Technique C to Master Skills - First Program of Array
Tutorials Arena
Follow
10/20/2024
Category
š
Learning
Transcript
Display full video transcript
00:00
Hello everyone. This is Sandeep. In my last video, I have explained about array. What
00:08
is array? Why we use array? I just quickly recall the things that array is a variable
00:16
which can store similar data type elements, more than one similar data type elements.
00:23
Suppose if I have to store in a variable a salary of five employees, so the declaration
00:35
will be like this. First of all the data type and the name of the variable and the size.
00:44
Once I will declare it, the five memory locations are going to allocate and in array, the counting
00:53
always starts from zero. So this will be the zeroth position, this will be the first, this
00:58
will be the second, this will be the third and this will be the fourth. So in all these
01:04
locations we will be able to store the salary of employee, salary of employees.
01:15
How to store and how to display it on screen? The things will be more clear when I create
01:22
one of the program. I'm going to create one of the easy program and that program is to
01:29
input salary of three employees from the keyboard and to display it on screen. First of all
01:37
what I have to do, I have to declare the array variable. I will take data type, then name
01:43
of the variable and the size of it. Once I will declare it, the three memory space at
01:49
the run time going to allocate inside the primary memory inside the RAM. That will be
01:56
what the zeroth location, this will be what first location and this will be what second.
02:03
So three locations are going to create. So I'll make the program in code blocks to read
02:12
the salary of the employees and to store it on the and to store inside the variables
02:19
and then to display it on the screen. Let us see how to do it. So the first thing what
02:25
I will do, I will include the standard input output header file. Let me save it also. So
02:32
I will go to file, I will click on save. Let us give a name to it what PRG array and save
02:39
it. Now I will use what int main and inside it the first thing which I will do, I will
02:48
declare the array variable with element size what 3. So with this how many values are going
03:02
to store? 3. Inside which variable? Cell variable which is array variable. Having the similar
03:09
data type integer, for that we have used what int. I have taken one more variable i. Now
03:17
I just give a message here inside the printf that is to input salary of three employees.
03:31
And I will not use scanf directly as I have to apply the loop as to reach to the position
03:39
of an array. So I will use what i equals to 0, i less than equal to 2 or I can also write
03:50
in this way less than 3, it's same thing. So 0, 1, 2 it's going to carry on the loop
04:00
for three times, 0, 1, 2 and then it's going to terminate. So we all know how the loop
04:07
works, we have covered this. Now inside the loop I am going to use scanf. We will use
04:17
what percent d, comma what cell ampersand or you can say the and sign cell and inside
04:28
it what i. So I am using a very easy program just only to explain that how the values get
04:39
stored inside the locations of array variable and how from those locations we can take out
04:46
the values and do the work. So with the help of scanf we can able to read the values and
04:54
store inside the different locations or different position of array variable. Once the values
05:03
stored now I have to display it on the screen. So I give a message here display salary of
05:15
employees. For display I am going to again apply the loop. So we can make the same program
05:33
by use of single for loop that also I will explain but at present I am using the for loop
05:41
for two times just so that you can easily understand and do not get confused that how
05:49
the values are stored and then displayed. So here I will use what printf then what inside
05:58
it the specifier that is what percent d, comma and where is the value inside the cell and I
06:07
is going to take to the position of an array. I need some space also after each value so I
06:16
will use what printf and some space. So I hope everything is fine I have made the program.
06:22
Let us click on build and see if there is any error so there is no error. I am going to run
06:31
it also and I am going to input the salary of three employees. This one is of the first,
06:38
this one is of second, this one is of third. Let us press the enter so it displayed also.
06:46
Now how the things work let us understand that. When I declare the variable cell3 what
06:56
happened behind the scene at runtime it's going to allocate three spaces cell0, cell1,
07:04
cell2 like this. Now what I have to do I have to input the salary of the three employees inside
07:11
those locations so I have applied the loop here. Let us run the loop the value of i is 0 it will
07:20
come to the decision part 0 less than 3 the condition is true with the help of scanf inside
07:27
the array variable cell we are talking about the location 0 as the value of i is what 0.
07:34
So inside the 0 location that is here the value of i is what 0 so inside here will store the
07:43
salary. So the salary is going to store here like this then what will happen the value of
07:54
i is going to increment by 1 less than 3 the condition is true it will come here to the
08:02
scanf. Now we are talking about the second position of an array so the next value the
08:10
next salary of the second employee that is going to store inside the second or inside
08:17
the second position or you can say the it starts from 0 so in the first position of an array that
08:23
is here this okay. So what we have done we have stored the first employee salary at the
08:35
jth position now we are going to store inside the first position of an array the salary of
08:41
the second student okay so that is going to store of the second employee okay the salary of the
08:49
second employee is going to store and what will happen
08:58
this loop will carry on the value of i is going to increment from 1 to 2, 2 less than 3 the
09:05
condition is true now this time we are talking about the second position of array that is this
09:13
one okay. So the salary of the third employee the salary of the third employee is going to store
09:21
inside here okay now suppose we have we have input from the keyboard for 3000 so that is
09:26
true okay. So all these salaries are stored and what will happen this loop will carry on the
09:36
value of i is going to increment again now from 2 the value will be what 3 so you have to remember
09:45
the remember the values of the variable so now the value of i is what 3 it will come to the
09:51
decision part 3 less than 3 okay the condition is what false. So this loop will terminate but we
09:59
have got the salary of the three employees inside the memory space in zeroth in the first in the
10:07
second. Now what I have done I have again applied the loop for the display of the value okay so I
10:14
have given a message first display salary of employees and then I have applied the loop let
10:21
us run the loop the value of i is 0, 0 less than 3 okay the condition is true from the zeroth
10:28
position of an array as the value of i is 0 from the zeroth position of an array the salary of the
10:37
first employee that is going to display on screen from here that is going to display on a screen it
10:45
will display on screen from here from the zeroth position okay. Then the value of i is going to
10:56
increment from 0 to 1 okay 1 less than 3 the condition is true okay now we are talking about
11:03
what the first position of an array of here okay the first position of an array. So what is there
11:12
in the first position of an array let us see here is the salary of the second employee that will be
11:20
display on the screen as we have used the printf okay. Then what happened the value of i is going
11:29
to increment now the value will be what 2 it will come to the decision part 2 less than 3 okay 2
11:36
less than 3 the condition is true. Now from the second position as the value of i is what 2 okay
11:43
from the second position that is from here from the second position of an array the value is
11:51
going to display on the screen okay. Then again this i is going to increment okay the value of
12:00
i will be what 3 it will come to this position 3 less than 3 the condition is what false the
12:08
loop will terminate. So in this way we will get all the values okay. So the next program I am
12:15
going to explain with the help of a single for loop and how it will work that I am going to
12:22
explain. Thanks for today.
Recommended
11:41
|
Up next
Learn Programming Technique C to Master Skills - Second Program of Array
Tutorials Arena
11/1/2024
9:58
Learn Programming Technique C to Master Skills - Third Program of Array
Tutorials Arena
11/1/2024
12:37
Learn Programming Technique C to Master Skills - Fourth Program of Array
Tutorials Arena
10/20/2024
13:04
Learn Programming Technique C to Master Skills - Double Dimension Array Program
Tutorials Arena
10/20/2024
9:40
Learn Programming Technique C to Master Skills - Fifth Program of Array
Tutorials Arena
10/20/2024
3:40
Learn Programming Technique C to Master Skills - Array of Pointer Program
Tutorials Arena
11/9/2024
4:22
Learn Programming Technique C to Master Skills - Pointer And Arrays Program
Tutorials Arena
11/9/2024
12:03
Learn Programming Technique C to Master Skills - Array of Structure Program
Tutorials Arena
11/10/2024
6:40
Learn Programming Technique C to Master Skills - Explanation of Array
Tutorials Arena
10/20/2024
3:37
Learn Programming Technique C to Master Skills - Pointers And Arrays
Tutorials Arena
11/8/2024
8:08
Learn Programming Technique C to MasterĀ Skills - First Program of Function
Tutorials Arena
11/3/2024
6:04
Learn Programming Technique C to Master Skills - First Program (Array with Function , Call by Value)
Tutorials Arena
11/9/2024
7:02
Learn Programming Technique C to Master Skills - Sixth Program of Array (Loop with if)
Tutorials Arena
11/1/2024
9:20
Learn Programming Technique C to Master Skills - Union Program
Tutorials Arena
11/10/2024
7:16
Learn Programming Technique C to Master SkillsCharacter String First Program
Tutorials Arena
11/19/2024
5:02
Learn Programming Technique C to Master Skills - Third Program of Loop
Tutorials Arena
10/17/2024
9:12
Learn Programming Technique C to Master Skills - Program of Recursion
Tutorials Arena
11/6/2024
3:51
Learn Programming Technique C to Master Skills - First Program of Loop (Flowchart)
Tutorials Arena
10/13/2024
7:12
Learn Programming Technique C to Master Skills - Third Program (Passing Entire Array in Function)
Tutorials Arena
11/9/2024
4:55
Learn Programming Technique C to Master Skills - Linked List Program
Tutorials Arena
12/2/2024
5:14
Learn Programming Technique C to Master Skills - Single If Statement Program Explanation
Tutorials Arena
10/12/2024
3:51
Learn Programming Technique C to Master Skills - First Program of Loop (For Loop)
Tutorials Arena
10/13/2024
8:01
Learn Programming Technique C to Master Skills - Loop Within Loop Program
Tutorials Arena
10/17/2024
8:06
Learn Programming Technique C to Master Skills - Linked List ( First Program)
Tutorials Arena
11/30/2024
3:02
Learn Programming Technique C to Master Skills - Linked List Program - Recursive
Tutorials Arena
12/2/2024