basic C questions: variables, arrays and loops


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: basic C questions: variables, arrays and loops

  1. #1
    Join Date
    Jul 2004
    Location
    India.
    Posts
    7

    want help in C

    hi all,

    I am currrently trying to learn C.

    in book it states that contant are term that dosent change while execution of progaram......

    and variable is name given to the place in computer memory where this constant are stored?


    i cant get this fact about variable?

    can anyone explain it to me plz..........

    thanks....
    Anupam Misra.
    Be Kool.

  2. #2
    Join Date
    Dec 2003
    Posts
    3,366
    The chip can have a constant value placed into a register for computations; the compiler can do this from your constants, so they do not require a memory location unless the constant is an array (string, etc).

    most variables (values that can change) do use a memory location unless optimizations decide to use a register (for example, a loop variable that is destroyed when the loop is done).

  3. #3
    Join Date
    Apr 2004
    Posts
    136
    A variable is a reserved amount of memory to hold data. Variables differ depending on what type of data they will be holding. 'Char' will hold alphabetical data where as a 'float' will hold decimalised data.

  4. #4
    Join Date
    Jul 2004
    Location
    India.
    Posts
    7
    i have just started reading book on C

    so i cant get you......

    loop?

    arrray?

    i cant really get it..... sorry:confused: :confused: :confused: :confused:
    Anupam Misra.
    Be Kool.

  5. #5
    Join Date
    Apr 2004
    Posts
    136
    a loop is a kind of function that loops/repeats a certain part of code untill the code reaches 'false'...it then exits the loop to proceed with the rest of the code.

    an array is a mass of variables. where as variables are normaly single slots of memory an array is a collection of these slots. arrays are used to simplify refrencing and calling procedures.


    ***Im also a c++ newby coming from little experience with Vb...so please correct me if im wrong! ***

  6. #6
    Join Date
    Jun 2004
    Posts
    15
    As process says, arrays are just collections as variables. You probably already know that a variable is like a box - you give it a name, and it can hold a certain type of data. For an array, imagine a row of boxes:

    --------ARRAY-----
    | 0 | | 1 | | 2 | | 3 |


    The whole lot is called "array", but is made of four seperate elements: array[0], array[1], array[2] and array[3]. We can assign values to these elements just like a normal variable (eg writing "array[2]=65;" puts a 65 into the box marked 2). There can be more than one dimension to an array - for instance the pigeonholes in a hotel could be represented by a row number and a column number (2 dimensional).

    That said though, I wouldn't worry too much about arrays until you've got the basics mastered - in the book I've been following I (as a BASIC programmer) was surprised to see them come in quite late (after objects) - but you don't really need them to start with, and you cannot do terribly much with them without knowing things like interation (so you can write a loop that goes to the same bit of code, but moves one element down the array at a time, for instance).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center