C, Cannot retrieve variable value through dereferencing, unknown segmentation fault
===

If I do the operation on the pointer within the method, it works. But when used as a argument in another method the same operation fails. There's clearly something I'm missing. My guess is for some reason foobar can't "see" the variables *ptr is pointing to. 

    int main(int argc, char *argv[]){
        unsigned short b =15;
        unsigned short *ptr = &b;
	
        //If I do it in main it works
        unsigned short c = 10 & (*ptr);
	
        //If I send it to foobar, it segfaults
        foobar(*ptr);
    }

    void foobar(unsigned short *ptr){
        unsigned short c = 10 & (*ptr);
    }

How do I get my variable over to the foobar, if I foobar(unsigned short b) it does not compile (through trial and error I've found you can only use basic types as arguments).


If anyone could 'point' me to an explanation I would be grateful. I've read several C tutorials, but I can't find a specific reason why this happens, or how to solve it.

Thanks