Monday 3 August 2015

Pointers and Strings: Part Two

Last time we started an important topic in C++, pointers. Today, we shall continue from that.

Using 'const' with Pointers

          const qualifier
        Value of variable should not be modified
        const used when function does not need to change a variable
          Principle of least privilege
        Award function enough access to accomplish task, but no more
          Four ways to pass pointer to function
        Nonconstant pointer to nonconstant data
          Highest amount of access
        Nonconstant pointer to constant data
        Constant pointer to nonconstant data
        Constant pointer to constant data
          Least amount of access









          const pointers
        Always point to same memory location
        Default for array name
                             Must be initialized when declared



'sizeof' Operator

sizeof
–Unary operator returns size of operand in bytes
–For arrays, sizeof returns
( size of 1 element ) * ( number of elements )
–If sizeof( int ) = 4, then
int myArray[10];
cout << sizeof(myArray);
     will print 40
sizeof can be used with
–Variable names
–Type names
–Constant values






About the Author

Unknown

Editorial Team

Post a Comment

 
Codexify © 2015 - Designed by Templateism.com