Thread: passing an array

  1. #1
    Banned
    Join Date
    Apr 2015
    Posts
    596

    passing an array

    Hey guys, what's up?
    I want to know if I have
    Code:
    int arr[10]={1,2,3,4,5,6,7,8,9,10};
    and I have passed just three elements of the arr to another function, meaning I pass arr[3] to another function, my question is, the array in the another function is just 3 and if I exceeded there the index 2, then it will be an error or any trash value of index 3+ , right?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    3.5 years ago, you were asking basically the same question.
    Slicing's string concept.

    Only the data type has changed.

    Is your memory so bad that it's one fact in, one fact out?

    I mean, you seemed to be making decent progress in 2015.
    But now? - your "floating point array sizes" was pathetic.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Banned
    Join Date
    Apr 2015
    Posts
    596
    Quote Originally Posted by Salem View Post
    3.5 years ago, you were asking basically the same question.
    Slicing's string concept.

    Only the data type has changed.

    Is your memory so bad that it's one fact in, one fact out?

    I mean, you seemed to be making decent progress in 2015.
    But now? - your "floating point array sizes" was pathetic.
    maybe you didn't understand my question well, or I didn't clear it well ..
    what I'm going to ask is if I have a recursion with array of integers size of 10 (1,1,1,1,1,1,1,1,1,1,1), and I called inside that function the function itself with array size 3, my question is just three elements will be copied into the new "call" of that function or all the array? meaning if over new call I have exceeded the index 2, what will happen? will print the value of the prime array with size 10?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Post a sample program to demonstrate your question and you might find the answer yourself.
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing a 2d array help?
    By ebro97 in forum C Programming
    Replies: 2
    Last Post: 06-16-2017, 08:11 PM
  2. Passing Array To Function & Display Array Contents
    By mcertini in forum C++ Programming
    Replies: 4
    Last Post: 12-10-2010, 01:32 PM
  3. Passing array right
    By devilsknight in forum C Programming
    Replies: 7
    Last Post: 06-18-2006, 12:21 AM
  4. passing an array to a function (2d array)
    By revelation437 in forum C Programming
    Replies: 5
    Last Post: 03-11-2003, 03:32 PM
  5. help with passing 2d array...
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 02-05-2002, 02:06 PM

Tags for this Thread