C Programming: Arrays - A Clear Description of Arrays

free web hosting
Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > C/C++ Programming

C Programming: Arrays - A Clear Description of Arrays

jayron
C programming provides a capability that enables a user to design a set of similar data types, called Arrays.

For understanding the arrays properly, let us consider the following program
CODE

main()
{
int x;
j=5
j=10;
printf("\nj= %d",x);
}

No doubt, this program will print the value of j as 10. This is because when a value 10 is assigned to j, the earlier value of j, i.e. 5, is lost. Thus, ordinary variables are capable of holding only one value at a time. However, there are situations in which we would want to store more than one value at a time in a single variable.

For example, suppose we wish to arrange the percentage marks obtained by 100 students in ascending order. In such case we have two options to store these marks in memory.

1) Construct 100 variables to store percentage marks obtained by 10 differ students, i.e. each variable containing one student;s marks.

2)Construct one variable (called Array or subscripted variable) capable of storing or holding all the hundred values.

Obviously, the second alternative is better. A simple reason for this is, it would be much easier to handle one variable than handling 100 different variables. Moreover, there are certain logics that cannot be dealt without the use of an array. An array is a collective name given given to a group of 'similar quantities'. These similar quantities could be percentage marks of 100 students, or salaries of 300 employees, or age of 500 employess. What is important is that the quantity must be 'similar'. Each member in the group is referred to by its position in the group. For example, assume the following group of numbers which represent percentage marks obtained by five students.
CODE

perc = {48, 88, 34, 23, 96};


If we want to refer to the second number of the group, the usual notation used is perc(2) similarly, the fourth number of the group is referred as perc(4). However, in C, the fourth number is referred as perc[3]. This is because in C the counting of elements begin with 0 and not with 1. Thus, in this example perc[3] refers to 23 and perc[4] refers to 96. In general, the notation would be perc[i], where, i can take a value 0,1,2,3 or 4, depending on the position of the element being regerred. Here perc is the subscripted variable (array), whereas 1 is its subscirpt.

Thus, an array is a collection of similar elements. These similar elements could be all ints, or all floats, or all chars, etc. Usually, the array of characters is a called a string, whereas an array of ints or floats is simply called an array. Remember that all elements of any given array must be the same type, i.e. we cannot have an array of 10 numbers, of which 5 are ints and 5 are floats.

 

 

 


Reply

jayron
Array Declaration

To begin with, like other variables an array needs to be declared so that the compiler will know what kind of an array and how large an array we want. An example of declaration is:
CODE

int marks[30];

Here int specifies the type of variable, just as it does with ordinary variables and the word 'mark' specifies the name of the variable. the [30] however is something to stress on. The number 30 tells how many elements of the type int will be in our array. This number is often called the 'dimension' of the array. The brackets ( [] ) tells the compiler that we are dealing with an array.

Accessing Elements of an Array

Once an array is declared, let us see how individual elements in the array can be referred. This is done with subscript, the number in the brackets following the array name. This number specifies the element’s position in the array. All the array elements are numbered, starting with 0. Thus marks[2] is not the second element of the array, but the third. In our program we are using variable I as a subscript to refer to various elements of the array. This variable can take different values and hence can refer to the different elements in the array in turn.. This ability to use variables as subscripts is what makes arrays so useful.

Entering Data into an Array
Here is the section of code that places data into an array:

CODE

for(i=0;i<=29;i++)
  {
     printf(“\nEnter Marks”);
     scanf(“%d”,&marks[i]);
  }


The for loop cause the process of asking for and receiving a student’s marks from the user to be repeated 30 times. The first time through the loop, I has a value 0, so the scanf() statement will cause the value type to be stored in the array element marks[0], the first element of the array. The process will be repeated until I becomes 29. This is the last time though the loop, which is a good thing, because there is no array element like marks[30].

In the scanf() statement, we have used the “address of” operator (&) on the element marks[i] of the array. In so doing, we are passing the address of this particular array element to the scanf() function, rather than its value, which is what scanf() requires.

 

 

 


Reply

gdinod
Clear description of arrays for beginners! Whats your reference? book? site?

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. arays in c programming - 301.52 hr back. (2)
Similar Topics

Keywords : c, programming, arrays, clear, description, arrays

  1. Clearing Your Ie Tif
    Clear your Temporary Internet Files on IE (0)
  2. Any Way To Get Clear, Fresh Skin In 4 Days?
    (3)
    friday is girls night me and my bestfriend get all dressed up and hot and go to dinner and a
    concert. well i want to look absolutely great and i always do.. except right now my skin isnt in its
    best condition. any tips on clearing it up in a few days if it helps im 17 and eat really healthy
    thank you for all your answers i really appreciate them /tongue.gif" style="vertical-align:middle"
    emoid=":P" border="0" alt="tongue.gif" />....
  3. Short Info About About Apache Maven.
    It's a brief description about Apache Maven and how does it woks. (0)
    Hi there. Well, it's my first post and I'd like to write about Apache Maven: What is it?
    How does it works? and a short example. I hope this post results interesting and useful for
    someone, and well. Let's start.! What is Apache Maven? Apache Maven (or simple Maven)
    is a helpful tool design to create and build projects (usually Java Projects) almost in the same way
    than Ant and the classic "GnuMake", but Maven goes beyond and incorporate some another concepts
    like: archetypes, build cycles and plug-ins For those who had use Ant, the way you bu....
  4. Project Euler
    Website(s) with computer programming exercises (1)
    Well, I tried to post this to the Programming Languages subforum, but it seems that I could only do
    so in one of the subforums there... As this is not related to any particular language, I posted it
    here (admins & mods, please feel free to move this to the right section, if this isn't it :))
    So, on we go... Some of you may have already heard about computer programming exercises... Some
    people create exercises and post them on the web, and other people solve them... It's fun, and
    helps you know your math and programming language a lot better... Recently, I found....
  5. Making A Picture Viewer Website
    Html programming or javascript (3)
    this is one thing i've struggled with for ages. I want a webpage where there are little
    thumbnails and in the middle somewhere is the main picture. The littole thumbnails or snipets of
    infor when clicked display the main image corresponding to that clicked thumbnail or link. e.g
    pictures of the country side listed in pairs or 3's or 4's in a column and you click each
    one an the main view on the screen displays that particular picture. How is this achieved. Can any
    one gimme a link to a site with templated for that or javascript for that or html code or past....
  6. Best Programming Language For Win Vista?
    Whats the best/most used programming language for Vista? (3)
    Hey All What you guys think is the best programming language for Windows Vista? Ive been doing C#
    for some months, but im looking for something else, something easier for making fast applications,
    and no extra things needed like the .NET Framework. Doesnt have to be GUI Applications. Any Idea?
    Post up your idea /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif"
    /> - optiplex....
  7. A Prelude To Programming
    What to learn? How to learn? (10)
    I'm quite interested in learning programming. I want to know how us eager souls can go about
    doing that. I'm interested in both web and desktop programming. I already know XHTML & CSS. Any
    recommended books?....
  8. What Is Genetic Programming?
    (3)
    Genetic Programming is a machine learning technique inspired by the theory of biological evolution.
    It is usually started with a huge number of programs, which are randomly generated, hand-coded or
    known solutions. These programs are then made to compete against each other to see which program
    performs better. Once the competetion is complete, we'll get a ranked list of the programs
    sorted in the order of best to worst programs. Next comes the evolution, the best peroforming
    programs are replicated and modified further in two ways, Mutation and Crossover. Mutation ....
  9. Learn Java Programming Language Online Step By Step
    (1)
    I had found this site >> http://learnjava.awardspace.com This website is for people who want
    to learn Java Programming Language step by step. This website also includes JAVA lessons from the
    beginning to advanced level. So this site appropriates for the beginner of Java programmer language
    or non-basic Java Programming Language. The lessons are easy to follow and understand starting
    from how to get your PC JAVA ready, the fundamental programming concept and creating the real
    application. Moreover, the working examples are also included. Please enjoy the les....
  10. Arrays And List Boxes
    VB6 Codes needed (2)
    Hello Guys, I am working on an application. It is such that there are 2 list boxes or combo boxes.
    One is Labeled Departure and the other is labeled Destination. The boxes contain various states in
    America and each state has its unique feature of distances. The difference of the distances has to
    be reflected on a label. Where I need help is a code to execute the contents of the array into
    values For instance: Option Explicit Private Type Stateinfo statedeparture as integer
    stateDestination as integer TotalDistance as integer End Type Dim StateDistance ....
  11. Php And Mysql Programming
    anyone knows a code for mysql and php (2)
    hi everyone! I am making a program using php and mysql...I am a noob on this so i need your
    help guys...I want to make a simple program that will some values and then store them on a database
    and then retrieve them...uhmm let me give an example out put of what i need. This is the example
    say..: Enter First Name: Enter Last Name:
    Enter Age: Enter Address: ..those
    are the data needed for input values...my question now is how can I make a database....
  12. Visual Wd Is The Poorest Attempt Of Programming Yet
    Microsoft has let them selves down (0)
    Well for starters, the installer says it all. It took me 75 mins to install and i got a 4 CPU 3.5
    gHz processor, the images still have their magenta background and they look like its been drawn on
    paint. You go make an application but you dicide its rubbish - so you delete it, and unlike Basic
    and C# your project is still listed with no images and the link is broken, so it just wastes space.
    The sqldb's aren't editable - you can just view them THERE ISNT A BUTTON TO PLACE A DIV
    IN!!! You click on a panel and the properties dont appear I went to ....
  13. Python
    another programming language (8)
    There are so many languages used in software and web development. Python is one of them. Basically
    Python is object-oriented , high-level programming language with dynamic semantics. Python was
    developed in the 90’s. Python is simple and easy to learn. Therefore it reduces cost of program
    maintenance. It is very attractive for rapid application development because of its high-level
    built-in data structures, combined with dynamic typing and dynamic binding. Python is also use as a
    scripting or glue language to connect existing components. Python supports modules and ....
  14. I'm Looking For Help With Programming (i Think)
    (3)
    I'm looking for someone who can help me figure out how to make a site the way I want it. I have
    made several websites, but what I'm looking to do now is make one where I can have members.
    Something where people can sign up and log in. I'm pretty sure there's some kind of special
    coding needed for this, but not sure what. I'm thinking it has something to do with php(no clue
    what that is), but I'm not sure. Any help and input would be GREATLY appreciated! Thanks in
    advance.....
  15. The Best Game Programming Languages?
    (25)
    What are some good programming languages to program games in? C++? /unsure.gif"
    style="vertical-align:middle" emoid=":unsure:" border="0" alt="unsure.gif" /> Thanks /xd.gif"
    style="vertical-align:middle" emoid=":XD:" border="0" alt="xd.gif" />....
  16. Alright, I'm Taking Computer Programming As A Class In School.
    (10)
    Is there anything I should personally be worried about or anything I really need to know? I'm
    pretty much good with computers and such and pretty much spend my whole life on them, lol.....
  17. Programming In Glut (lesson 6)
    Texture filters and lighting (2)
    This is the last of the six tutorials I have moved from astahost. I hope you enjoy these and the
    rest soon to come. QUOTE This tutorial demonstrates how to use texture filters and will let you
    see the differences of each filter. I will also be introducing lighting into this tutorial. We
    first have to create our "bitmap.h" header file with the functions we use to load our bitmaps, this
    is changed from the last tutorial to fit the needs of this one. The first thing to do is to link
    all of our OpenGL libraries and include our needed headers for the functions we w....
  18. How Many of You Use the C Programming language?
    (23)
    Just wanted to know how many of you are currently using C language for programming. If you can tell
    what sort of programs you do, it would be useful. ....
  19. Java Helpdesk
    All your queries regarding Java Programming goes here. (8)
    Hellow friends, I am creating this thread for all queries and suggestions related to java coding. If
    you face any problem, post it here, and others who have a solution can post the reply here. Hope it
    helps the users.....
  20. Detailed C Beginner Tut
    basis for learning any application programming language (2)
    QUOTE The best way to learn programming is to dive right in and start writing real programs.
    This way, concepts which would otherwise seem abstract make sense, and the positive feedback you get
    from getting even a small program to work gives you a great incentive to improve it or write the
    next one. Diving in with ``real'' programs right away has another advantage, if
    only pragmatic: if you're using a conventional compiler, you can't run a fragment of a
    program and see what it does; nothing will run until you have a complete (if tiny or trivi....
  21. What Is Programming Language Of Google Etc.?
    (21)
    Im just curious to know , which is the programming language behind the following websites.if u know
    anyone/all of them please tell me. 1- ebay.com 2- amazon.com 3- msn.com ( i assume asp.net) 4-
    yahoo.com 5- google.com As i mentioned in previous posts that im in learning mode /smile.gif"
    style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> so i just ask sometimes
    stupid questions.. and i have to confess that this forum is very excellent place , since its not
    only providing the free hosting , it is giving me so much knowledge , what Google or others c....
  22. Win32: Dialog Box And Accelerator
    Win32 API programming (1)
    ok my problem is how do i make or assign a keyboard accelerator with modal dialog boxes since the
    message loop is inside the function call of DailogBox() functions, unlike the modeless dialog box in
    which you are the one who will create the message loop for the dialog box... is it even possible?....
  23. Free Tutorial (web Programming) + Free Web Hosting
    Bravehost dot com (10)
    Welcome to bravehost com!! Bravehost com offers many free stuffs!! They have free
    tutorials about web programming. They also have free audio clips to be downloaded for FREE!!
    You can also visit their forum. They also give free web hosting and if you need more space and
    tools, don't worry they also give paid web hosting!! Just www bravehost com!!
    And start to gain more knowledge... Moved to Hosts review, added description ....
  24. Life In Programming?
    wheres this headed? (11)
    Hey guys im 16 and really like programming (although im fairly new at it) ive already taken a year
    of basic html and what not. This year im taking a class in c++ and VB next year i hope to take java
    and php. However next year will be my senior year and i will have to start applying for colleges
    and im trying to convince my parents that there ARE jobs in computers its hard for them to do this
    they like to stay locked up in there own little world **cough cough** stone age **cough** so what i
    was wondering is what jobs are actually out there for this kinda stuff what are ....
  25. How Can I Learn Assembly
    where to Assembly Language Programming (14)
    Please help me in learning assembly ....
  26. What Programming Languages Should I Choose?
    taking AAS in Computer Information Sys (17)
    I have a question to ask all the programming proffesionals out there. I'm going to college this
    fall for AAS in Computer Information Systems, and I would like to know what programming languages
    should I go for? I like Visual Basic, but that is required, I was thinking Java, C++, and one
    programmer for the state said I should take Cobol but my mother says it is boring and for the lesser
    businesses or whatever. What do you guys think? Topic titles and descriptions are important at
    Trap17. College Programming isn't that descriptive. Title and description rename....
  27. Good Books On C++ Game Programming
    I need some books! (2)
    I am looking for some good books on game programming in c++ if any body out there has any
    suggestions feel free to post them. Oh by the way should i start out with an easier language like
    BASIC or should I just work on c++. Ineed some help people please reply fast. Tahnx
    David H /biggrin.gif' border='0' style='vertical-align:middle' alt='biggrin.gif' /> ....
  28. What Is Neuro Linguistic Programming
    I'll tell you... (19)
    Neuro Linguistic Programming or NLP is a methodolgy for modelling... We know that there are some
    people in the world who are fantastic at what they do. AThey probably don't know how they are
    good at it, but with Neuro Linguistic Programming we can find out. A Neuro Linguistic Programming
    Practictioner can use some of the skills and methods included in the field of NLP, to elicit any
    persons stratagy for any given behaviour. We, the NLPers, call this modelling. With the skill of
    modelling we can successfully teach ourselves any stratagy that will help us be outs....
  29. What Is A T_string?
    Please help! I'm new at PHP Programming (13)
    I'm new at PHP, and I looked for a while on here, and found some stuff I was looking for about
    form processing, and sending E-Mail through PHP. However, the script I just created won't work.
    I get the following error: Parse error: parse error, unexpected T_STRING in
    /home/hamtaro/public_html/send_feedback.php on line 9 Exactly what is a T_STRING? If I need to post
    my code, I will.....
  30. A Question About C++ Programming Under Linux
    (7)
    Hello guys! i prepare to develop under linux using c++, but i don't know what tools i should
    use...some one tell me to use vim, but i think vim is so hard to use!can u recommend me some
    ide??? thank u very much....

    1. Looking for c, programming, arrays, clear, description, arrays

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for c, programming, arrays, clear, description, arrays

*MORE FROM TRAP17.COM*
Similar
Clearing Your Ie Tif - Clear your Temporary Internet Files on IE
Any Way To Get Clear, Fresh Skin In 4 Days?
Short Info About About Apache Maven. - It's a brief description about Apache Maven and how does it woks.
Project Euler - Website(s) with computer programming exercises
Making A Picture Viewer Website - Html programming or javascript
Best Programming Language For Win Vista? - Whats the best/most used programming language for Vista?
A Prelude To Programming - What to learn? How to learn?
What Is Genetic Programming?
Learn Java Programming Language Online Step By Step
Arrays And List Boxes - VB6 Codes needed
Php And Mysql Programming - anyone knows a code for mysql and php
Visual Wd Is The Poorest Attempt Of Programming Yet - Microsoft has let them selves down
Python - another programming language
I'm Looking For Help With Programming (i Think)
The Best Game Programming Languages?
Alright, I'm Taking Computer Programming As A Class In School.
Programming In Glut (lesson 6) - Texture filters and lighting
How Many of You Use the C Programming language?
Java Helpdesk - All your queries regarding Java Programming goes here.
Detailed C Beginner Tut - basis for learning any application programming language
What Is Programming Language Of Google Etc.?
Win32: Dialog Box And Accelerator - Win32 API programming
Free Tutorial (web Programming) + Free Web Hosting - Bravehost dot com
Life In Programming? - wheres this headed?
How Can I Learn Assembly - where to Assembly Language Programming
What Programming Languages Should I Choose? - taking AAS in Computer Information Sys
Good Books On C++ Game Programming - I need some books!
What Is Neuro Linguistic Programming - I'll tell you...
What Is A T_string? - Please help! I'm new at PHP Programming
A Question About C++ Programming Under Linux
advertisement



C Programming: Arrays - A Clear Description of Arrays



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE