title: Terminology when Initializing C Structures
body: <p>This will be an easy question but googling around does not seem to provide me with an answer. The way I understand it in C we have two ways to initialize a foo object, when foo is a structure. Look at the code below for an example</p>
  
  <pre><code>typedef struct foo
  {
     int var1;
     int var2;
     char* var3;
  }foo;
  
  //initializes and allocates a foo
  foo* foo_init1(int v1,int v2,const char* v3)
  {
     if(..some checks..)
        return 0;
     foo* ret = malloc(sizeof(foo));
  
     ret-&gt;var1 = v1;
     ret-&gt;var2 = v2;
     ret-var3 = malloc(strlen(v3)+1);
     strcpy(ret-&gt;var3,v3);
  
     return ret;
  }
  
  // initializes foo by ... what? How do we call this method of initialization?
  char foo_init2(foo* ret,int v1,int v2, const char* v3)
  {
     //do some checks and return false
      if(...some checks..)
           return false//;assume you defined true and false in a header file as 1 and 0 respectively
     ret-&gt;var1 = v1;
     ret-&gt;var1 = v1;
     ret-&gt;var2 = v2;
     ret-var3 = malloc(strlen(v3)+1);
     strcpy(ret-&gt;var3,v3);
  
     return true;
  }
  </code></pre>
  
  <p>So my question is this. How do we refer in C to these different initializing methods? The first returns an initialized pointer to foo so it's easy to use if you want a foo object on the heap like that:</p>
  
  <pre><code>foo* f1 = foo_init1(10,20,"hello");
  </code></pre>
  
  <p>But the second requires a foo .. what? Look at the code below.</p>
  
  <pre><code>foo f1;
  foo_init2(&amp;f1,10,20,"hello");
  </code></pre>
  
  <p>So the second method makes it easy to initialize an object on the stack but how do you call it? This is basically my question, how to refer to the second method of initialization.</p>
  
  <p>The first one allocates and initializes a pointer to foo.
  The second one initializes a foo by ... what? Reference?</p>
  
  <p>As a bonus question, how do you guys work when coding in C? Do you determine the usage of the object you are making and by that determine if you should have an initializing function of type1 , or 2 or even both of them?</p>