user11897: I want to create a structure called CarSpeed it has 4 int FR,FL,BR,BL (FrontRight,..) ; and i would like to create a function that returns this structure : 
ActualSpeed Readspeed(void)
{
   code to read the speed of the car(already done)
}

Can someone help me define a function that returns this structure  ? only the way how I should define it, the usual C way doesnt work :
typedefstruct CarSpeed{...}

and then
CarSpeed ActualSpeed;
ActualSpeed Readspeed(void){.. }


user7856: I would recommend to use pointers, it's faster and has the same result.
Something like this (disclaimer - I did not compile it):
typedef struct {
   int a;
   int b;
} pair;


int init_pair(pair *ptr) {
   if (!ptr)
      return -1;
   ptr->a = 6;
   ptr->b = 9;
   return 0;
}

int do_something() {
   pair mypair;
   return init_pair(&mypair);
}


user42: Since you're (probably) using a C++ compiler, it's usually easier to declare structures like this:
struct CarSpeed
{
    int fr, fl, br, bl;
};

(Note that there's no need for typedef.)
You can then return an instance of it directly from your function:
CarSpeed ReadSpeed()
{
    CarSpeed data;

    data.fr = ...;
    data.fl = ...;
    data.br = ...;
    data.bl = ...;

    return data;
}

You can call it from another function like this:
CarSpeed speed = ReadSpeed();

That will copy the contents of the structure into an object called speed. In this example, it's an 8 byte structure so it's a non-trivial copy. That shouldn't be a big problem unless you're calling it very frequently though.
As noted in another answer, using a pointer (or a reference) can be more efficient if necessary.

11897: <p>I want to create a structure called CarSpeed it has 4 int FR,FL,BR,BL (FrontRight,..) ; and i would like to create a function that returns this structure : </p>

<pre><code>ActualSpeed Readspeed(void)
{
   code to read the speed of the car(already done)
}
</code></pre>

<p>Can someone help me define a function that returns this structure  ? only the way how I should define it, the usual C way doesnt work :</p>

<pre><code>typedefstruct CarSpeed{...}
</code></pre>

<p>and then</p>

<pre><code>CarSpeed ActualSpeed;
ActualSpeed Readspeed(void){.. }
</code></pre>
 7856: <p>I would recommend to use pointers, it's faster and has the same result.</p>

<p>Something like this (disclaimer - I did not compile it):</p>

<pre><code>typedef struct {
   int a;
   int b;
} pair;


int init_pair(pair *ptr) {
   if (!ptr)
      return -1;
   ptr-&gt;a = 6;
   ptr-&gt;b = 9;
   return 0;
}

int do_something() {
   pair mypair;
   return init_pair(&amp;mypair);
}
</code></pre>
 42: <p>Since you're (probably) using a C++ compiler, it's usually easier to declare structures like this:</p>



<pre class="lang-cpp prettyprint-override"><code>struct CarSpeed
{
    int fr, fl, br, bl;
};
</code></pre>

<p>(Note that there's no need for <code>typedef</code>.)</p>

<p>You can then return an instance of it directly from your function:</p>

<pre class="lang-cpp prettyprint-override"><code>CarSpeed ReadSpeed()
{
    CarSpeed data;

    data.fr = ...;
    data.fl = ...;
    data.br = ...;
    data.bl = ...;

    return data;
}
</code></pre>

<p>You can call it from another function like this:</p>

<pre class="lang-cpp prettyprint-override"><code>CarSpeed speed = ReadSpeed();
</code></pre>

<p>That will copy the contents of the structure into an object called <code>speed</code>. In this example, it's an 8 byte structure so it's a non-trivial copy. That shouldn't be a big problem unless you're calling it very frequently though.</p>

<p>As noted in another answer, using a pointer (or a reference) can be more efficient if necessary.</p>
