Pointer to structures


I have a structure like this:

[code]struct node{
int top;
struct node * topnext;

Then I have the following arrays.
struct node tops[n+1];
struct node * currtop[n+1];[/code]

where "tops" is an array of nodes, and currtop is an array of pointers to nodes.

Since both these arrays are not global, I have to pass pointers to these to functions in order to perform tasks on these arrays.

I tried passing just their addressed and using them like this:

[code]void foo(t1,&currtop,&tops)

void foo(int t1,struct node*ptr_curr,struct node*ptr_tops){



but I get a compiler error which says :
incompatible types in assignment

What am I doing wrong?


  • An array variable is a pointer that hold the address of the first element. for example:


    void main() {
    char string[256];
    sscanf("world peace","%s",string);
    putchar(*string); //output will be: w
    putchar(*(string+2)); //output will be: r
    Note that when calling sscanf the argument string was passed without the referencing symbol &. sscanf stores the sentence "world peace" into the address of the array string.

    Here is the error:


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion