Thread: Array Doubt

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    47

    Array Doubt

    Q. How many values can be stored by an array A(-1...m,1...m)?

    a. m
    b. m2
    c. m(m+ 1)
    d. m(m+2)

    I am not getting any clue what's the output, can anyone help me out with correct option and explanation

    thanks a lot in advance

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Consider a few values of m, list out the elements, and count. You should be able to spot some kind of pattern.
    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
    Jul 2010
    Posts
    47
    Quote Originally Posted by laserlight View Post
    Consider a few values of m, list out the elements, and count. You should be able to spot some kind of pattern.
    Thanks for the reply , let me try this will get back

  4. #4
    Registered User
    Join Date
    Jul 2010
    Posts
    47
    Quote Originally Posted by laserlight View Post
    Consider a few values of m, list out the elements, and count. You should be able to spot some kind of pattern.
    but I am not getting how to declare array for example it is declared generally as A[1][2] if 2 dimensional and A[2] if one dimensional , here how to declare it, how to place value of m can u give one example

  5. #5
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    Quote Originally Posted by shyjuu View Post
    but I am not getting how to declare array
    The array is two dimension, but it's not like C since the first and last indexes are being specified. Assuming that the notation is "inclusive", then the first dimension's indexes go from -1 to m, and the second dimension's indexes go from 1 to m.

  6. #6
    Registered User
    Join Date
    Jul 2010
    Posts
    47
    Quote Originally Posted by rcgldr View Post
    The array is two dimension, but it's not like C since the first and last indexes are being specified. Assuming that the notation is "inclusive", then the first dimension's indexes go from -1 to m, and the second dimension's indexes go from 1 to m.
    If its not of C then its of which programming language, and what's the answer

  7. #7
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    You should know which programming language the question is about. From where did you copied it?

    I would say it's pseudocode and thus a general question.

    Do the calculation yourself then come back, tell us what you think the answer is and why.

    Bye, Andreas

  8. #8
    Registered User
    Join Date
    Jul 2010
    Posts
    47
    I am solving some question on the net I found that there, but I am unable to solve it , I just want example of the declaration, so I can think further

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by shyjuu View Post
    I am solving some question on the net I found that there, but I am unable to solve it , I just want example of the declaration, so I can think further
    C doesn't support negative indices in arrays. You can answer the question and make the program, by using an offset of -1, in the first range of indices, however.

    But you can't make array declarations in C, that strictly match up with the index numbers you have given in your first post.

    As AndiPersti replied above, it has to be pseudo code if the language is C. If it's for another language, I'd guess it's Pascal(Delphi), since that language was created to help teach programming, and it uses array syntax like that.

  10. #10
    Registered User
    Join Date
    Jul 2010
    Posts
    47
    Quote Originally Posted by Adak View Post
    C doesn't support negative indices in arrays. You can answer the question and make the program, by using an offset of -1, in the first range of indices, however.

    But you can't make array declarations in C, that strictly match up with the index numbers you have given in your first post.

    As AndiPersti replied above, it has to be pseudo code if the language is C. If it's for another language, I'd guess it's Pascal(Delphi), since that language was created to help teach programming, and it uses array syntax like that.
    As per as I remember it was C language question, so what should me the solution

  11. #11
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by shyjuu View Post
    As per as I remember it was C language question, so what should me the solution
    Read post #5 again. That's the answer.

  12. #12
    Registered User
    Join Date
    Jul 2010
    Posts
    47
    Quote Originally Posted by Adak View Post
    Read post #5 again. That's the answer.
    According to that Post, suppose m=2

    A(-1..2 , 1..2 )

    I am still confused about the declaration , how to run this and know the output

  13. #13
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by shyjuu View Post
    According to that Post, suppose m=2

    A(-1..2 , 1..2 )

    I am still confused about the declaration , how to run this and know the output
    There are hundreds of C examples of array declarations on this web site. If you are still confused, click on the "C Tutorial" button, near the top (center) of this page, and go through some of it.

    One of the beautiful things about programming is, you can try out different syntax's and blocks of code, in very little time.

    I am not going to spoon feed you on this. You've already been told the answer, and more. Either you want to work on it, or you don't. Choice is yours.

  14. #14
    Registered User
    Join Date
    Jul 2010
    Posts
    47
    Quote Originally Posted by shyjuu View Post
    According to that Post, suppose m=2

    A(-1..2 , 1..2 )

    I am still confused about the declaration , how to run this and know the output
    I surely want to work out by my own so I am putting so much efforts on clearing my doubts

  15. #15
    Registered User
    Join Date
    Jul 2010
    Posts
    47
    Quote Originally Posted by Adak View Post
    There are hundreds of C examples of array declarations on this web site. If you are still confused, click on the "C Tutorial" button, near the top (center) of this page, and go through some of it.

    One of the beautiful things about programming is, you can try out different syntax's and blocks of code, in very little time.

    I am not going to spoon feed you on this. You've already been told the answer, and more. Either you want to work on it, or you don't. Choice is yours.
    I am just confused with the declaration part, I think what I have written is wrong in C , so how to do that
    Last edited by shyjuu; 06-15-2013 at 11:35 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. doubt in boolean and array
    By prathiksa in forum C Programming
    Replies: 7
    Last Post: 10-22-2012, 03:20 AM
  2. doubt while defining array and pointer
    By karthik537 in forum C Programming
    Replies: 4
    Last Post: 08-24-2010, 12:05 AM
  3. Array declaration doubt
    By finalsayan in forum C Programming
    Replies: 8
    Last Post: 03-29-2010, 09:56 AM
  4. a doubt about sending an array to a function
    By louis_mine in forum C Programming
    Replies: 13
    Last Post: 05-14-2005, 11:50 PM
  5. a Movement doubt in an array
    By louis_mine in forum C Programming
    Replies: 4
    Last Post: 02-03-2005, 09:12 PM