Thread: C passing array to function

  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    45

    C passing array to function

    Hi all,

    I want to pass array to function, to fill array with new values and then to print the array in the main. But I have problem because it prints me just array of zeros. Maybe the concept is wrong, I'm new with passing arrays to function. Please help me.


    function:
    Code:
        void printSum(int *return_array) {
    
            int return_array[3];
            int i;
    
            for(i = 0; i < 3 ; i++){
                return_array[i] = 5;
            }
    
        return;
    
        }
    main:

    Code:
    void printSum(int *return_array);
    
    
        int main {
    
            int m_return_array[3];
            int i,j;
    
             for(i= 0 ; i < 3 ; i++){
                 m_return_array[i] = 0;
             }
    
            printfSum(start,m_return_array);
    
            for(j = 0 ; j < 3 ; j++){
    
                printf("Array %d\n",m_return_array[i]);
            }
        return 0;
    
        }

  2. #2
    Registered User
    Join Date
    Jul 2012
    Posts
    45
    I figured out, deleting int return_array[3]; from the printSum function solved the problem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing an array to function
    By Linkx16 in forum C++ Programming
    Replies: 7
    Last Post: 06-09-2013, 07:46 AM
  2. Replies: 4
    Last Post: 09-25-2012, 01:31 AM
  3. Passing Array To Function & Display Array Contents
    By mcertini in forum C++ Programming
    Replies: 4
    Last Post: 12-10-2010, 01:32 PM
  4. passing 2D array to a function
    By ashesh in forum C Programming
    Replies: 4
    Last Post: 06-09-2003, 11:16 PM
  5. passing 2d array in to function
    By Kings in forum C++ Programming
    Replies: 1
    Last Post: 01-16-2003, 11:35 AM

Tags for this Thread