Thread: Passing arrays and string arrays to functions

  1. #1
    Registered User
    Join Date
    Mar 2015
    Posts
    5

    Passing arrays and string arrays to functions

    Hi,

    This is my first post i am just geting started in programing C.

    I have seen functions that declare arrays in the function input even thou the arrays is already declared in main. Why do you do this?

    for example:

    int ova(int antal, char glosorSv[][MAX], char glosorEn[][MAX])

    int main(void)

    char glosorSv[][MAX]
    char glosorEn[][MAX]

    BR

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    You see, the thing is those are not already declared, because they're not the same. C has scope rules, which in a nutshell means that variables have distinct "lifetimes" in the code, beyond which they can't be accessed anymore. Therefore, there's nothing wrong with calling a function argument the same as a local variable, because they exist in different scopes.
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    Mar 2015
    Posts
    5
    Thank you for the replay. I am sorry if i was a bit unclear when i described the problem. The two Arrays is used throughout the program. The function "ova" adds the contents to the array. This array is then used by several different functions in the code. But the "ova" function does not return any value. So basically it is declared in main then it is filled up in the "ova" function without the "ova" function returning anything. Then the array is used in another function which uses the values that "ova" has put in it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing arrays to functions
    By cda67 in forum C Programming
    Replies: 3
    Last Post: 11-05-2011, 03:37 AM
  2. Passing arrays to functions
    By engine in forum C Programming
    Replies: 7
    Last Post: 03-22-2011, 03:36 PM
  3. Passing 2D arrays between functions
    By taurus in forum C Programming
    Replies: 10
    Last Post: 09-28-2009, 05:05 AM
  4. Passing Arrays to Functions...
    By txcs in forum C++ Programming
    Replies: 4
    Last Post: 04-22-2009, 10:36 AM
  5. Passing Arrays into functions
    By manutdfan in forum C Programming
    Replies: 23
    Last Post: 11-14-2006, 01:25 PM