Thread: array initialization

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    33

    array initialization

    i have two c files
    in the first file i have declared and initialised an array and i need to use the array in my second file also,how to use the same array in my second file......

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Look up the extern keyword, and examples of its usage. Google is your friend.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Registered User
    Join Date
    Jun 2009
    Posts
    120
    Declare an array in the second file using extern keyword.
    Code:
    // file01.c
    int array[3] = {1, 2, 3};
    Code:
    // file02.c
    extern int array[3];
    Or create a header file for the first file and include in the second file.
    Code:
    // file01.h
    extern int array[3];
    Code:
    // file02.c
    #include "file01.h"
    Last edited by DRK; 11-26-2012 at 04:15 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array Initialization
    By niteshsood in forum C Programming
    Replies: 2
    Last Post: 04-13-2009, 06:22 AM
  2. Array initialization with int variable
    By tsantana in forum C++ Programming
    Replies: 5
    Last Post: 03-31-2009, 02:48 PM
  3. array initialization & C standard
    By jim mcnamara in forum C Programming
    Replies: 2
    Last Post: 09-12-2008, 03:25 PM
  4. Array initialization...
    By eccles in forum C Programming
    Replies: 4
    Last Post: 12-10-2004, 02:18 AM
  5. array of structs initialization - PLZ help...
    By Vanya in forum C++ Programming
    Replies: 2
    Last Post: 12-11-2002, 08:10 PM

Tags for this Thread