Thread: Can I Confirm an Array is A Variable?

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    81

    Can I Confirm an Array is A Variable?

    Hi, our assignment asks us to do something with a program where we store three inputs in one variable?

    Surely the easiest way is to use an array?

    But our lecturer told us an array isn't a variable - is that correct (it seems just to be a big variable) cos I've been told by other people that it is indeed just that?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Interista
    But our lecturer told us an array isn't a variable - is that correct (it seems just to be a big variable) cos I've been told by other people that it is indeed just that?
    Hmm... I generally think of a variable as an object, or as a name for an object. An object is a "region of data storage in the execution environment, the contents of which can represent values". Therefore, an array is a variable.

    On the other hand, "an array type describes a contiguously allocated nonempty set of objects with a particular member object type". So, an array is a set (or rather, sequence) of objects, hence it is a sequence of variables rather than just a variable. Yet, this sequence of variables might be considered a variable in itself.

    In summary, I'm inclined to consider an array to be a variable.

    The more interesting question though is what does "store three inputs in one variable" mean?
    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

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    81
    That the user inputs three numbers which getchar gets and puts into a variable.

    I really don't know anymore. There was a program I couldn't get last week and even though all marks have been given out, and solutions have been issued for other programs students had trouble with, I've been told he refuses to issue a solution example for this program. I honestly think this is the last straw. I've never studied anything before where lecturers refused to give solutions to answers once work had been submitted, particularly when they had already issued solutions for other questions in the same assignment. Think its time for me to knock this course on the head which is clearly what they want given that attitude.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Interista
    That the user inputs three numbers which getchar gets and puts into a variable.
    The "three numbers which getchar gets" sounds fishy. It is true that getchar returns an int, but normally we would say "three characters which getchar gets". I'm guessing that what your teacher had in mind was to read three characters and store them in the different bytes of say, an int.

    However, unless you have been taught the idea of bit manipulation, this is just a mathematical trivia question that will not serve you well out of context.

    Quote Originally Posted by Interista
    There was a program I couldn't get last week and even though all marks have been given out, and solutions have been issued for other programs students had trouble with, I've been told he refuses to issue a solution example for this program.
    If that problem was just an extra quiz then that is not unusual. If it is actually related to what is in the syllabus, then you probably should discuss it with him, then contact the administration if he refuses to help you.
    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

  5. #5
    Registered User
    Join Date
    Oct 2011
    Posts
    81
    Quote Originally Posted by laserlight View Post
    The "three numbers which getchar gets" sounds fishy. It is true that getchar returns an int, but normally we would say "three characters which getchar gets". I'm guessing that what your teacher had in mind was to read three characters and store them in the different bytes of say, an int.

    However, unless you have been taught the idea of bit manipulation, this is just a mathematical trivia question that will not serve you well out of context.


    If that problem was just an extra quiz then that is not unusual. If it is actually related to what is in the syllabus, then you probably should discuss it with him, then contact the administration if he refuses to help you.
    The problem is, as you suggested, he's giving us stuff which is out-of-context, in that he is not covering it. For example, he wants us to manipulate stuff but doesn't even touch on how to.

    I'm also on a similar java course, which is great. Whilst the lecturer on that course, naturally doesn't spoon-feed us, he shows us something then says adapt it to do this. It has a level of difficulty but isn't impossible as it is has already been shown to us and rather than learning it ourselves (as with C), we have to learn how to adapt it ourselves - much less problematic.

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    You might want to look up the meaning of "data structure" or (in C) of struct.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by grumpy
    You might want to look up the meaning of "data structure" or (in C) of struct.
    I'd argue that if an array is not a variable, then an object of struct type is not a variable either. Other than that, yeah, a struct would be an alternative.
    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

  8. #8
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Sure. However, the question the OP was asked concerned getting "three inputs into one variable".

    The fact the OP jumped to the idea that meant array, lecturer suggested otherwise, so I suggested an alternative.

    In computer science, a "variable" is a symbolic name given to something, that allows the value of that "something" to be used. The name of an array (as opposed to the array itself) can therefore be viewed as a variable.

    The definition in computer science differs from most commonly used mathematical definitions where a "variable" is something that has a value that can change, and a "constant" is something with a value that cannot change. Since "variable" and "constant" are mutually exclusive concepts, and an array can be either variable or constant, an array is not normally viewed mathematically as a variable (nor is it viewed as a constant). It is a distinct concept.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  9. #9
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    If the value(s) it holds can vary then I'd say that kinda makes it a variable.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. confirm that the result of stringstream is integer.
    By brack in forum C++ Programming
    Replies: 1
    Last Post: 09-12-2010, 03:26 PM
  2. How to confirm there're holes in a file on windows?
    By password636 in forum Windows Programming
    Replies: 2
    Last Post: 04-23-2010, 01:48 AM
  3. Virus in Commercial Download - Can anyone confirm this?
    By Davros in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 08-03-2004, 05:07 PM
  4. Can anyone help me confirm that this is the 10 millionth Prime?
    By Davros in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 01-17-2004, 11:44 PM
  5. My own variable - the array
    By CodeMonkey in forum C++ Programming
    Replies: 6
    Last Post: 03-03-2002, 08:29 PM