A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

Hello. I'm taking the C++ tutorials found at cprogramming.com, and one of the example codes for a lesson on arrays kind of confused me. This is the code and resulting output: http://codepad.org/VIMFsa9v I started fiddling around with it because I didn't understand the logic in it, and after a few tries I decided to give up and try to produce the same output from scratch. Here's my version: http://codepad.org/GIGEnZgZ Could anyone tell me *why* they did it that way? Mine seems a bit simpler, but I don't know if their version might have any advantages in a different situation.

  • This Question is Closed
  1. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Programs which code you pasted do practically same thing, your program does assigning and printing out simultaneously and their program has this steps separated. In general, sometimes there are situations where you can assign values and perform operations on them simultaneously, sometimes processing part is to complex to merge it with assigning/preparing part.

  2. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I see. So in larger programs, separating the two reduces the chance of errors, then. From what you say I take it mine wasn't faulty in logic, though ( quite a relief! ). I was worried that mine might've been a fluke with some rather horrendous flaw that I narrowly escaped by sheer luck. I'm afraid it's happened before. Thank you so much for replying. Another quick question: is naming the array "array" okay, too? I was told to stay away from... 'reserved' key words like "int" and "char", and though I don't know how "array" might be used, Microsoft Visual Studio did highlight it, and the program ran flawlessly despite that.

  3. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    The word "array" isn't a keyword in C/C++, if it had been, your program wouldn't have compiled. So, you can name array as "array" and this is not a fault. Of course you should often have better names for your arrays - such names that are better describing destination of particular ones.

  4. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    By the way, the reason that there is no reserved word "array" is that we don't use keywords to declare arrays, we just declare pointer and this can be pointer to space allocated earlier - statically or dynamically, then, we only use offset from this pointer to get access to particular elements (this is the reason for numbering of elements starting from zero).

  5. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    when naming is always good to try camelCase naming style.. is pretty helpfu l and is better to understand.

  6. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Yes, that's why I didn't really understand why 'array' was highlighted. Thank you =) Thanks kuro, I'll try camelCasing. I'm still trying to figure out a consistent naming scheme for myself since it seems to vary from person to person.

  7. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.