Page 257 - DCAP404 _Object Oriented Programming
P. 257

Object-oriented Programming




                    Notes             The operator &, when placed before a variable, returns the memory address of its operand.
                                       The operator * returns the memory address of its operand.

                                      The operator * returns the data value stored in the area being pointed to by the pointer
                                       following it.
                                      The pointer variables must always point to the correct type of data. Pointers must be
                                       initialized properly because uninitialized pointers result in the system crash.
                                      In pointer arithmetic, all pointers increase and decrease by the length of the data type
                                       point to.

                                      An array name is a pointer that stores the address of its first element. If the array name is
                                       incremented, It actually points to the next element of the array.
                                      Array of pointers makes more efficient use of available memory. Generally, it consumes
                                       lesser bytes than an equivalent multi-dimensional array.
                                      Functions can be invoked by passing the values of arguments or references to arguments
                                       or pointers to arguments.
                                      When references or pointers are passed to a function, the function works with the original
                                       copy of the variable. A function may return a reference or a pointer also.

                                   11.7 Keywords


                                   Alias: A different name for a variable of C++ data type.
                                   Base Address: Starting address of a memory location holding array elements.
                                   Function Pointer: A function may return a reference or a pointer variable also. A pointer to a
                                   function is the address where the code for the function resides. Pointer to functions can be passed
                                   to functions, returned from functions, stored in arrays and assigned to other pointers.

                                   Memory location: A container that can store a binary number.
                                   Pointer: A variable holding a memory address.
                                   Reference: An alias for a pointer that does not require de-referencing to use.

                                   11.8 Review Questions

                                   1.  How does pointer variable differ from simple variable?
                                   2.  How do we create and use an array of pointer-to-member-function?

                                   3.  How can we avoid syntax errors when creating pointers to members?
                                   4.  How can we avoid syntax errors when calling a member function using a pointer-to-
                                       member-function?

                                   5.  How do we pass a pointer-to-member-function  to a  signal handler, X event callback,
                                       system call that starts a thread/task, etc?
                                   6.  Find the syntax error (s), if any, in the following program:

                                       {
                                            int  x  [5], *y  [5]
                                          for  (i  =  0;  i<  5;  i++)
                                          {  x  [i]  =  I;



          250                               LOVELY PROFESSIONAL UNIVERSITY
   252   253   254   255   256   257   258   259   260   261   262