Q:

How to scan elements with pointer variable to an array

I am using visual studio 2012.
I am trying to implementing 2 stacks using a single array.  
My C code 
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
 {
int arr[10], ch=1, *top1=&arr[0]-1, *top2=&arr[9]+1;

while(ch!=5)
{
printf("1. Push in Stack 1\n2. Pop from Stack 1\n3. Push in Stack 2\n4. Pop from Stack       2\n5.Exit");
scanf("%d",&ch);
    switch(ch)
    {
    case 1:
        if(top1+1 !=top2)
        {
        scanf("%d",*++top1);
        }
        else
        printf("stack is full");
break;
    case 2:
        if(top1 != &arr[0]-1)
        printf("%d",*top1);
        else
        printf("Stack is Empty");
break;
    case 3:
        if(top2-1 !=top1)
        {
        scanf("%d",*--top2);
        }
        else
        printf("stack is full");
break;
    case 4:
        if(top2 != &arr[9]+1)
        printf("%d",*top2);
        else
        printf("Stack is Empty");
break;
    case 5:
        return(0);
    }
}

return 0;

}  

Code is running properly,    scanf("%d",*++top1); and scanf("%d",*--top2); are  not
taking input. 
usage of scanf is correct or not ?

A:

You should consider warning seriously, you are overlooking: 
warning: format ‘%d’expects type ‘int *’, but argument 2 has type ‘int’

for line scanf("%d", *++top1); and scanf("%d", *--top2);.
Because scanf()  with %d format string accepts a address not the value. So for example value of expression *++top1 is treated as address that is not a valid address hence this causes  undefined behavior at runtime. Remove dereferencing * pointer in scanf() and it will work.

A:

scanf() Requires  an address for second and third arguments
If you pass value rather than address, you will get following warning   
 warning: format â%dâ expects argument of type âint *â, but argument 2 has type âintâ [-Wformat]  

MOdify like this   
scanf("%d",*++top1); ==> scanf("%d",++top1);  
scanf("%d",*--top2); ==> scanf("%d",--top2);

EDIT
Your POP Implementation is not correct   
1. pop1 you need to decrement top1
2. pop2 you need to increment top2

