title: Why does this give junk value?
body: <p>I am getting garbage / junk values as output when my program is run and the data displayed.</p>
  
  <p>Why is it so? </p>
  
  <p>Can someone help me to understand how to properly pass by pointers and not get junk values?</p>
  
  <p>This program is about stack creation of <code>struct books</code> type variables.</p>
  
  <p>By default shouldn't the variable <code>bks</code> pass by pointer and change when <code>b</code> is changed?</p>
  
  <p><code>bks</code> is still storing garbage value.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  struct books
  {
      int yrpub;
      char name[100],author[50];
  };
  int top=-1;
  int push(struct books b[],int top,int n)
  {
      if(top==n-1)
          return -1;
      else
      {
          ++(top);
          printf("Enter books info: \n");
          printf("Enter name: ");
          gets(b[top].name);
          printf("Enter author: ");
          gets(b[top].author);
          printf("Enter Year of publish: ");
          scanf("%d",&amp;b[top].yrpub);
          return top;
      }
  }
  void display(struct books b[],int top)
  {
      int i;
      if(top==-1)
          printf("No books in the stack...");
      for(i=0;i&lt;=top;i++)
      {
          printf("Details of book %d: \n",i+1);
          printf("Name: %s\nAuthor: %s\nYear of publish: %d\n",b[i].name,b[i].author,b[i].yrpub);
      }
      system("pause");
  }
  
  int main()
  {
      struct books bks[10];
      int ch;
      system("cls");
      printf("Select an option:\n");
      printf("1. Push book\n2. Pop book\n3. Peep book\n4. Display all books info\n5. Exit\n");
      printf("Enter a choice: ");
      scanf("%d",&amp;ch);
      fflush(stdin);
      switch(ch)
      {
      case 1:
          system("cls");
          top=push(bks,top,10);
          break;
  
      case 4:
          system("cls");
          display(bks,top);
          break;
  
      case 5:     exit(0);
  
      default:    printf("\nWrong choice...Please retry.");
          long i,j;
          for(i=0;i&lt;1000000;i++)
              for(j=0;j&lt;100;j++);
      }
      main();
  }
  </code></pre>