1. const int* x=5;
Declares a pointer to a constant.
So now a assignment *x=10; will fail
2. int* const x=5;
Declares a constant pointer to a variable.
so *x=10 will PASS while x=10 will fail.
3. const int * == int const *
The above 2 mean the same thing
4. const int const *x=5;
Using 3. statement 4 Declares a pointer to a constant. (same as 1)
Showing posts with label C. Show all posts
Showing posts with label C. Show all posts
Tuesday, December 9, 2008
Wednesday, December 3, 2008
New vs. Malloc
New calls the "operator new(...)" method to allocate memory (like what malloc does), but memory allocation is followed by a call to the appropriate constructor. Also new is type-safe, yet malloc is not.
Static function in C
A static function is a function with the static qualifier applied:
static void foo ( void )
{
/* Blah blah */
}
What it does is restrict visibility of the function to the translation unit in which it's declared. Functions are implicitly declared as extern by default, which means they're visible across translation units.
Reference
http://www.daniweb.com/forums/thread82504.html
static void foo ( void )
{
/* Blah blah */
}
What it does is restrict visibility of the function to the translation unit in which it's declared. Functions are implicitly declared as extern by default, which means they're visible across translation units.
Reference
http://www.daniweb.com/forums/thread82504.html
Subscribe to:
Posts (Atom)