Question:
C basic programing..?
:)
2009-03-19 09:09:45 UTC
Im completely confused in Array fundamentals...even im not able to understand that why we use array programing in C language..some body please help me out...!

Thanks in advance!
Five answers:
Prateek Gupta
2009-03-19 10:25:10 UTC
Good that u have started off ur programing with C language...

Arrays are easy concept... if u r learning C, i advise u to go for Yashwant Kanetkar's LET US C...



See, u probably by now know that we declare variables to store all kind of values... int, float, character etc.... Single variables are fine for small programs...

But what will u do if u are making a program to input marks of 100 students?? U will probably define 100 variables names m1, m2...., m100.

this is also ok but its a very poor practice. U will have to write 100 words.. and then u will have to input all of them individually! That is quite a tough task....

That is where arrays come to ur rescue.. Arrays are nothing but group of similar type of variables... for eg, in the above problem, u can define an array called marks[100]... consisting of 100 elements, in just few seconds... See the ease...

Also, when u have to input the marks of all 100 students, just make a loop of 100 iterations and put the loop variable as the array number..



int i;

for(i=0;i<100;i++)

scanf("%d",&marks[i]);



these 3 lines will ask the user to input marks for 100 students...



Arrays provide us with ease of use... and thus it is easy to find errors in the program...



Hope u would have got some understanding od arrays... for complete clarification, with easy to understand examples, read Yashwant kanetkar...
shayakd
2009-03-19 09:16:25 UTC
Well what don't you understand about arrays.



They are extremely useful...for eg. if you have a 100 students and you want to store their marks, you would use an array rather than declare a 100 variables separately.



Edit:



Arrays are a collection of many variables under a common name.

So like for the marks thing...you can define an array like this:

int marks[100];

this means you have a 100 "int" variables at your disposal but you didn't have to declare them manually....that would be sooo tedious and annoying.

Once you have the array marks...you can access each of it's elements by the index.

The first location is at index 0 (arrays in C always start from 0...not 1) and you would access it by saying marks[0]...and the last element is at index 99...so marks[99];

These elements...marks[0], marks[1], etc...you just treat them as normal variables.

You can assign values to them:

marks[0] = 87;

marks[1] = 69;

etc.

and you can do other normal operations...like

int avg = (marks[0] + marks[1]) / 2;

this will give you the average of the first two marks



marks is an integer array because you declared it by saying int marks[100];

you can have other kinds of arrays like character arrays:

char name[100];

This will let you store a 100 characters...for eg. you can store a student's name

name[0] = 'P';

name[1] = 'a';

name[2] = 'u';

name[3] = 'l';

name[4] = '\0'; (with character arrays you always have to put this at the end to tell them where the name or whatever it is ur interested in ends...name[5] to name[100] has values that don't interest you and putting '\0' at marks[4] lets C know that )



you can also have arrays in more than 1 dimension...

for example in the name array you have a list to characters to make up a name....but if you wanted a list of names then you need a two dimensional array...but you can worry about that later.
π
2009-03-19 09:20:09 UTC
Arrays are extremely useful. You can use them to store a lot of seperate data (x and y coordinates for 100 people, for example), or even use it as a board for a board game or an arena for some sort of fighting game.



The way you declare an array is similar to the way you declare other C variables. You use the type of var (char, int) for what the different values stored into each space in the variable. You declare the name, and the size. Then you have to reference each specific place in the array.
2009-03-19 09:19:02 UTC
Arrays isn't a C subject, it's a programming subject - if you had learned programming before you learned C, you would have learned what arrays are, and why and how to use them. It's not too late - study programming: http://www-old.oberon.ethz.ch/WirthPubl/AD.pdf
kelsoe
2016-10-07 03:03:41 UTC
i does no longer say there's a greater useful programming language. seen straightforward is surprisingly sturdy, even with the indisputable fact that it does not get you familiarized with something previous straightforward programming ideas. C# and Java are based on an identical concepts, yet Java is greater transportable because it works on any working gadget, whilst C# will artwork in basic terms on domicile windows. even with the indisputable fact that, the integrated progression ecosystem (IDE) you have for C#, seen Studio, is relatively superb to apply. i might advise gaining knowledge of the two Java or C#. as quickly as you recognize one in each of them, this is worry-free to evaluation different different. sturdy luck!


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...