Thread: Arrays

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    2

    Arrays

    if we declare: int a[4][3]; then a[i][j] is equalivent to:

    1. *(a[i]+j)
    2. *(&a[0][0]+4*i+j)
    3. Both 1 and 2
    4. none of the above.

    Please assist in this question

  2. #2
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posts
    404
    Try compiling each one of those and see what happens.

  3. #3
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by guoer View Post
    if we declare: int a[4][3]; then a[i][j] is equalivent to:

    1. *(a[i]+j)
    2. *(&a[0][0]+4*i+j)
    3. Both 1 and 2
    4. none of the above.

    Please assist in this question
    Do your own homework!

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  4. #4
    Registered User
    Join Date
    Feb 2009
    Posts
    2
    Could any expert kindly assist? Or should i say the question is too hard to the experts over here?

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by guoer
    Could any expert kindly assist? Or should i say the question is too hard to the experts over here?
    Read about the homework policy. It does not take an expert to answer your question correctly.

    Take this as an unofficial warning: do not try emotional blackmail by implying that if we do not spoonfeed you the answer, we must be incompetent.
    Last edited by laserlight; 02-27-2009 at 05:02 AM. Reason: Might as well delete pic-o-matic's post since matsp has a better and yet non-obvious answer.
    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

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by guoer View Post
    Could any expert kindly assist? Or should i say the question is too hard to the experts over here?
    No, it is a case of : You figure out what it does, and then we can either EXPLAIN why it is that way, or tell you where you went wrong, if you get it wrong. It is not "ask a question and get the answer", when the actual purpose of the question itself is that you should learn something.

    And just so that we can rule out that I'm waiting for your input to know the answer, here's the answer encrypted:
    Where n is the question number, x = correct answer:
    Code:
    x = (8 >> (n+2));
    --
    Mats
    Last edited by matsp; 02-27-2009 at 05:00 AM.
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function to read in two arrays
    By ssmokincamaro in forum C Programming
    Replies: 7
    Last Post: 11-12-2008, 07:59 AM
  2. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 04:24 PM
  3. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  4. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10:47 PM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 09:24 PM