Re: swap of two no.?????
imnilima@xxxxxxxxx:
i want to know that how to swap 2 values ,that is one is integer &
other is float using pointers in C.
void SwapIntWithFloat(int *const pi,float *const pf)
{
int const temp i = *pi;
*pi = *pf;
*pf = i;
}
You might want some safe-guard such as:
assert(pi); assert(pf);
assert(*pf>=INT_MIN && *pf<=INT_MAX);
--
Frederick Gotham
.
Relevant Pages
- Re: Pointers vs References: A Question on Style
... void funk(SimCity const * pCity) ... > pointers when it comes to parameter passing. ... C++ functions can take arguments by copy, by address, or by reference. ... (comp.lang.cpp) - Re: Proper way to do casts while avoiding aliasing issues
... I have a piece of code that uses hashtables to store pointers to ... The hashtable sees all pointers as const ... void *, while the application obviously uses various other pointer ... (comp.lang.c) - Re: [Bug #11342] Linux 2.6.27-rc3: kernel BUG at mm/vmalloc.c - bisected
... The const has different ... Quite frankly, I personally do hate typedefs that end up being pointers, ... But because you hid the pointerness inside the typedef, ... Lists by definition are always ... (Linux-Kernel) - Re: constructor initialization list
... consult a reference. ... For example, I know how "const" works with pointers, ie.: ... But then when it comes to pointers to pointers, I'm not sure how the whole ... *not* guess (similarly with the constructor order scenario), ... (comp.lang.cpp) - Re: non-standard behaviour of qsort on SunOS 5.8?
... int cmp(const void *aptr, const void *bptr) { ... What I want is that vec is a pointer of pointers to DS structures. ... (comp.lang.c) |
|