# How to create pointer / reference to structure

**URL:** <https://discourse.julialang.org/t/how-to-create-pointer-reference-to-structure/54824>\
**Category:** New to Julia\
**Created:** [February 8, 2021, 5:17am UTC](https://discourse.julialang.org/t/how-to-create-pointer-reference-to-structure/54824 "2021-02-08T05:17:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nitish\_Dubey](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nitish_dubey/32/9092_2.png) [@Nitish\_Dubey](https://discourse.julialang.org/u/Nitish_Dubey)\
**Post date:** [February 8, 2021, 5:17am UTC](https://discourse.julialang.org/t/how-to-create-pointer-reference-to-structure/54824/1 "2021-02-08T05:17:26Z")

</div>

I am trying to create a symbol table in Julia. While i can get create an empty structure pointer in c just by typing  
struct xyz \*p  
but i can’t find any equivalent to it in julia. also how do i parse a structure as function input ?

---

<div class="post-metadata">

**Author:** ![L\_Adam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/l_adam/32/12086_2.png) [@L\_Adam](https://discourse.julialang.org/u/L_Adam)\
**Post date:** [February 8, 2021, 5:39am UTC](https://discourse.julialang.org/t/how-to-create-pointer-reference-to-structure/54824/2 "2021-02-08T05:39:44Z")

</div>

`:symbolname`, or `Symbol("symbolname")`

---

<div class="post-metadata">

**Author:** ![Nitish\_Dubey](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nitish_dubey/32/9092_2.png) [@Nitish\_Dubey](https://discourse.julialang.org/u/Nitish_Dubey)\
**Post date:** [February 8, 2021, 5:48am UTC](https://discourse.julialang.org/t/how-to-create-pointer-reference-to-structure/54824/3 "2021-02-08T05:48:35Z")

</div>

I think I have not explained myself well… I am trying to create symbol table from scratch… that’s where we use the empty struct to assign pointers for ending or first element… i want to create equivalent of this. i am basically having trouble with data structures in Julia

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [February 8, 2021, 5:53am UTC](https://discourse.julialang.org/t/how-to-create-pointer-reference-to-structure/54824/4 "2021-02-08T05:53:08Z")

</div>

```julia
julia> struct a end

```

?

---

<div class="post-metadata">

**Author:** ![Nitish\_Dubey](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nitish_dubey/32/9092_2.png) [@Nitish\_Dubey](https://discourse.julialang.org/u/Nitish_Dubey)\
**Post date:** [February 8, 2021, 6:03am UTC](https://discourse.julialang.org/t/how-to-create-pointer-reference-to-structure/54824/5 "2021-02-08T06:03:55Z")

</div>

````julia
type or paste code he# include <stdio.h>
# include <conio.h>
# include <alloc.h>
# include <string.h>
# define null 0
int size=0;
void insert();
void del();
int search(char lab[]);
void modify();
void display();
struct symbtab
{
          char label[10];
          int addr;
          struct symtab *next;
};
struct symbtab *first,*last;
void main()
{
          int op;
          int y;
          char la[10];
          clrscr();
          do
          {
                   printf("\nSYMBOL TABLE IMPLEMENTATION\n");
                   printf("1. INSERT\n");
                   printf("2. DISPLAY\n");
                   printf("3. DELETE\n");
                   printf("4. SEARCH\n");
                   printf("5. MODIFY\n");
                   printf("6. END\n");
                   printf("Enter your option : ");
                   scanf("%d",&op);
                   switch(op)
                   {
                             case 1:
                             insert();
                             display();
                             break;
                             case 2:
                             display();
                             break;
                             case 3:
                             del();
                             display();
                             break;
                             case 4:
                             printf("Enter the label to be searched : ");
                             scanf("%s",la);
                             y=search(la);
                             if(y==1)
                             {
                             printf("The label is already in the symbol Table");
                             }
                             else
                             {
                             printf("The label is not found in the symbol table");
                             }
                             break;
                             case 5:
                             modify();
                             display();
                             break;
                             case 6:
                             break;
                   }

          }
          while(op<6);
          getch();
}
void insert()
{
          int n;
          char l[10];
          printf("Enter the label : ");
          scanf("%s",l);
          n=search(l);
          if(n==1)
          {
          printf("The label already exists. Duplicate cant be inserted\n");
          }
          else
          {
                   struct symbtab *p;
                   p=malloc(sizeof(struct symbtab));
                   strcpy(p->label,l);
                   printf("Enter the address : ");
                   scanf("%d",&p->addr);
                   p->next=null;
                   if(size==0)
                   {
                             first=p;
                             last=p;
                   }
                   else
                   {
                             last->next=p;
                             last=p;
                   }
                   size++;
          }

}
void display()
{
          int i;
          struct symbtab *p;
          p=first;
          printf("LABEL\tADDRESS\n");
          for(i=0;i<size;i++)
          {
                   printf("%s\t%d\n",p->label,p->addr);
                    p=p->next;
          }

}
int search(char lab[])
{
          int i,flag=0;
          struct symbtab *p;
          p=first;
          for(i=0;i<size;i++)
          {
                   if(strcmp(p->label,lab)==0)
                   {
                             flag=1;
                   }
                   p=p->next;
          }
          return flag;
}
void modify()
{
          char l[10],nl[10];
          int add, choice, i, s;
          struct symbtab *p;
          p=first;
          printf("What do you want to modify?\n");
          printf("1. Only the label\n");
          printf("2. Only the address of a particular label\n");
          printf("3. Both the label and address\n");
          printf("Enter your choice : ");
          scanf("%d",&choice);
          switch(choice)
          {
                   case 1:
                   printf("Enter the old label\n");
                   scanf("%s",l);
                   printf("Enter the new label\n");
                   scanf("%s",nl);
                   s=search(l);
                   if(s==0)
                   {
                             printf("NO such label");
                   }
                   else
                   {
                             for(i=0;i<size;i++)
                             {
                                      if(strcmp(p->label,l)==0)
                                      {
                                                strcpy(p->label,nl);
                                      }
                                      p=p->next;
                             }
                   }
                   break;
                   case 2:
                   printf("Enter the label whose address is to modified\n");
                   scanf("%s",l);
                   printf("Enter the new address\n");
                    scanf("%d",&add);
                   s=search(l);
                   if(s==0)
                   {
                             printf("NO such label");
                   }
                   else
                   {
                             for(i=0;i<size;i++)
                             {
                                      if(strcmp(p->label,l)==0)
                                      {
                                                p->addr=add;
                                      }
                                      p=p->next;
                             }
                   }
                   break;
                   case 3:
                   printf("Enter the old label : ");
                   scanf("%s",l);
                   printf("Enter the new label : ");
                   scanf("%s",nl);
                   printf("Enter the new address : ");
                   scanf("%d",&add);
                   s=search(l);
                   if(s==0)
                   {
                             printf("NO such label");
                   }
                   else
                   {
                             for(i=0;i<size;i++)
                             {
                                      if(strcmp(p->label,l)==0)
                                      {
                                                strcpy(p->label,nl);
                                                p->addr=add;
                                      }
                                      p=p->next;
                             }
                   }
                   break;
          }
}
void del()
{
          int a;
          char l[10];
          struct symbtab *p,*q;
          p=first;
          printf("Enter the label to be deleted\n");
          scanf("%s",l);
          a=search(l);
          if(a==0)
          {
                   printf("Label not found\n");
          }
          else
          {
                   if(strcmp(first->label,l)==0)
                   {
                             first=first->next;
                   }
                   else if(strcmp(last->label,l)==0)
                   {
                             q=p->next;
                             while(strcmp(q->label,l)!=0)
                             {
                                      p=p->next;
                                      q=q->next;
                             }
                             p->next=null;
                             last=p;
                   }
                   else
                   {
                             q=p->next;
                             while(strcmp(q->label,l)!=0)
                             {
                                      p=p->next;
                                      q=q->next;
                             }
                             p->next=q->next;
                   }
                   size--;
          }
}

```This is a c code for symbol table i don't care about the display and switch block. I just want to create this program in Julia.
````

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [February 8, 2021, 6:09am UTC](https://discourse.julialang.org/t/how-to-create-pointer-reference-to-structure/54824/6 "2021-02-08T06:09:46Z")

</div>

the point being? I think you’re not looking for empty struct, you’re looking for `Ref()` that acts like pointer in C. Where these pointers/references are not initialized but the struct DOES have field, thus not empty

---

<div class="post-metadata">

**Author:** ![Nitish\_Dubey](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nitish_dubey/32/9092_2.png) [@Nitish\_Dubey](https://discourse.julialang.org/u/Nitish_Dubey)\
**Post date:** [February 8, 2021, 6:11am UTC](https://discourse.julialang.org/t/how-to-create-pointer-reference-to-structure/54824/7 "2021-02-08T06:11:58Z")

</div>

yes  
sorry for not being clear

---

<div class="post-metadata">

**Author:** ![L\_Adam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/l_adam/32/12086_2.png) [@L\_Adam](https://discourse.julialang.org/u/L_Adam)\
**Post date:** [February 8, 2021, 6:15am UTC](https://discourse.julialang.org/t/how-to-create-pointer-reference-to-structure/54824/8 "2021-02-08T06:15:23Z")

</div>

does not look into the code carefully yet, there’s an `@enum` macro in julia. Or why do you care about whether it’s a struct or not if what you want is a singleton and does not care about strict typing, just `OPRATION::UInt8 = opcode`, and use the opcode

---

<div class="post-metadata">

**Author:** ![Nitish\_Dubey](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nitish_dubey/32/9092_2.png) [@Nitish\_Dubey](https://discourse.julialang.org/u/Nitish_Dubey)\
**Post date:** [February 8, 2021, 6:35am UTC](https://discourse.julialang.org/t/how-to-create-pointer-reference-to-structure/54824/9 "2021-02-08T06:35:56Z")

</div>

Thanks Solved it
