user3895933
user3895933

Reputation:

C: Pointer after function call

I have to following C code:

a.b[(c+d(e,f,g)**i)]->j<-k

Now I have to add code to make it compile.

Most of that isn't a problem but what really irritates me is the d(e,f,g)**i part. **i as I understand is a pointer to a pointer, but I don't know how to handle it directly after a function call.

Upvotes: 0

Views: 114

Answers (3)

Bill Lynch
Bill Lynch

Reputation: 81926

Well this is relatively awful. Let's work from the inside out and remove things as we deal with them:

  1. d is a function with 3 parameters. Let's assume it can return an int, and if it can't we'll deal with that later:

    int e, f, g;
    int d(int, int, int);
    
  2. d(e,f,g) * *i will be fine if i is a pointer to an int.

    int *i;
    
  3. c + d(e,f,g) * *i will be fine if c is also an int.

    int c;
    
  4. So now we have the inside of the brackets completed. We also wanted that to be an integer so that it could work as an array notation. So we're good there. Let's rewrite the question without some of the stuff that we've resolved.

    a.b[<some integer>]->j < -k
    
  5. We can do the right side pretty easily.

    int k;
    
  6. This part is difficult to put into words, but I'm just walking the types. b is a double star because it's using array brackets followed by an -> sign.

    struct {
        struct {
            int j;
        } **b;
    } a;
    

So we end up with:

#include <stdlib.h>

int main() {
    int e, f, g;
    int d(int e, int f, int g);
    int *i;
    int c;
    int k;
    struct {
        struct {
            int j;
        } **b;
    } a;

    a.b[(c+d(e,f,g)**i)]->j<-k;
}

Upvotes: 0

shashank
shashank

Reputation: 410

Simple Enough

d(e,f,g) * *i // where d(e,f,g) is a function which should return a value and
*i is a pointer value
Eg if function d(e,f,g) returns 10 and if *i=5 then then output will be 10*5 = 50

Upvotes: 0

abelenky
abelenky

Reputation: 64682

Just break it down:

d(e,f,g)**i

FunctionCall d with params e,f,g
Multiplied by
pointer-dereferce of i

Or:

 d    (e,f,g)     *          (*i)
Func. Params  Multiply value-stored-at-pointer

Upvotes: 2

Related Questions