#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    1
    Rep Power
    0

    Initializing datatypes in another function


    Hi All ,

    I would like someone to guide me as to how to go about doing this . I would like to initialise all my dataypes in one function and call them from main . Is this a possiblity ?

    Code:
    void Initialize();
    
    void Initialize()
    {
     int t = 4 ;
     int time ;
     char name;
    }
    
    void main()
    {
     Initialize();
     printf(" t = %d", t);
    }
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Iran
    Posts
    149
    Rep Power
    139
    Hi,

    Either

    - you need to use global variables, initialized inside your function, which is not often recommended as there could be unexpected side effects leading to ambiguous situations when the program becomes larger in future

    - Or an initializing function returning the initialized variables, but again the types must already have been declared globally.

    Regards,
    Dariyoosh

IMN logo majestic logo threadwatch logo seochat tools logo