CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 1999
    Location
    Australia, Melbourne
    Posts
    10

    how do you use arrays when the size is not known.

    How do you use an array to pass to a function when the function is...

    OpenPrinter(String, int [], null /* this is always null)

    This function fills the int [] array.

    How do I pass an array to the second paramter when i don't know the size so that the function can build up the array???


  2. #2
    Guest

    Re: how do you use arrays when the size is not known.

    In java if u do not know the size to allocate ,Vector(java.uitl package) can be used.The Vector object grows dynamically and no size is required,but still Vector constructor can take size as a parameter if needed.In case if u want to use arrays the size is mandatory and can be taken as input from the user.


  3. #3
    Join Date
    Aug 1999
    Location
    Michigan, USA
    Posts
    4

    Re: how do you use arrays when the size is not known.

    Your question is not exactly clear. Are you calling the function, and you want to know how big to make the array? Are you writing the function and you want to know how long the array is so you can fill it? Or something else?

    In the first case, if there is some minimum length for the array, the function documentation should specify it.

    In the second case, the number of elements in an existing array is given by its length member:


    int a = new int[4];
    System.out.println("Number of elements in a is " + a.length);







Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured