Thread: Why do I need arrays?

  1. #1
    Registered User
    Join Date
    Jan 2020
    Posts
    5

    Angry Why do I need arrays?

    So I'm starting to learn C (again again, hopefully I don't quit this time), and I can't understand the use of arrays.

    Don't get me wrong, I know how to use an array. I just don't understand why I would want to.

    Does it have any advantages over just creating a bunch of variables, other than better organised code?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Yes, it has a huge advantage in that you can properly access the elements of the array by index or through a pointer, hence allowing you to do things like loop over them. You cannot normally do that when you have a bunch of separate variables.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-11-2013, 10:57 PM
  2. Modifying parallel arrays to arrays of structures
    By xkohtax in forum C Programming
    Replies: 7
    Last Post: 07-28-2011, 12:07 AM
  3. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  4. Replies: 2
    Last Post: 02-23-2004, 06:34 AM
  5. separating line of arrays into array of arrays
    By robocop in forum C++ Programming
    Replies: 3
    Last Post: 10-20-2001, 12:43 AM

Tags for this Thread