Re: C - Pass by reference to pointers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Anitha Boyapati wrote:

>  Usually, (well I thought so) the argument expected in f() is a pointer
>  variable. The above gives the result as 2 for the first call to f()!
>  Why is t giving out 2 without being dereferenced in case 1 ?

You explicity cast an integer into a pointer to an integer.  The whole
point of a cast is to tell the compiler to consider one thing as
another.  In this case you're telling it that an integer's value is
actually a pointer -- a completely invalid pointer, but a pointer
nonetheless.  There is no dereference because you didn't ask for a
dereference.  Nothing is automatic in C, if you want the address of i
you must write &i.

Brian

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux