# IMPORTANT POINTS FOR POINTERS:

IMPORTANT POINTS:

1. Pointer variables contain the addresses of other variables as their values.

2. In C++, no name is associated with the pointer data type.

3. A pointer variable is declared using an asterisk, *, between the data type and
the variable.
cin >> p; //Line 9
cout << endl << “Line 10: p(x): ” << p << endl; //Line 10
cout << “Line 11: p(5): ” << p(5) << endl << endl; //Line 11
cin >> q; //Line 12
cout << endl << “Line 13: q(x): ” << q << endl
<< endl; //Line 13
t = p + q; //Line 14
cout << “Line 15: p(x) + q(x): ” << t << endl; //Line 15
cout << “Line 16: p(x) – q(x): ” << p – q << endl; //Line 16
return 0; //Line 17
} //Line 18
Sample Run: In this sample run, the user input is shaded.
The degree of this polynomial is: 7
Enter the coefficient of x^0: 0
Enter the coefficient of x^1: 1
Enter the coefficient of x^2: 4
Enter the coefficient of x^3: 0
Enter the coefficient of x^4: 0
Enter the coefficient of x^5: 0
Enter the coefficient of x^6: 0
Enter the coefficient of x^7: 6
Line 10: p(x): 1x^1 + 4x^2 + 6x^7
Line 11: p(5): 468855
The degree of this polynomial is: 3
Enter the coefficient of x^0: 1
Enter the coefficient of x^1: 2
Enter the coefficient of x^2: 0
Enter the coefficient of x^3: 3
Line 13: q(x): 1 + 2x^1 + 3x^3
Line 15: p(x) + q(x): 1 + 3x^1 + 4x^2 + 3x^3 + 6x^7
Line 16: p(x) – q(x): -1 – 1x^1 + 4x^2 – 3x^3 + 6x^7

4. In C++, & is called the address of operator.

5. The address of operator returns the address of its operand. For example, if p
is a pointer variable of type int and num is an int variable, the statement
p = #
sets the value of p to the address of num.

6. When used as a unary operator, * is called the dereferencing operator.

7. The memory location indicated by the value of a pointer variable is accessed
by using the dereferencing operator, *. For example, if p is a pointer variable
of type int, the statement
*p = 25;
sets the value of the memory location indicated by the value of p to 25.

8. You can use the member access operator arrow, ->, to access the component of an object pointed to by a pointer.

9. Pointer variables are initialized using either 0 (the integer zero), NULL, or
the address of a variable of the same type.

10. The only integer value that can be directly assigned to a pointer variable is 0.

11. The only arithmetic operations allowed on pointer variables are increment (++),
decrement (–), addition of an integer to a pointer variable, subtraction of an
integer from a pointer variable, and subtraction of a pointer from another pointer.

12. Pointer arithmetic is different from ordinary arithmetic. When an integer is
added to a pointer, the value added to the value of the pointer variable is
the integer times the size of the object to which the pointer is pointing.
Similarly, when an integer is subtracted from a pointer, the value subtracted
from the value of the pointer variable is the integer times the size of the
object to which the pointer is pointing.

13. Pointer variables can be compared using relational operators. (It makes
sense to compare pointers of the same type.

14. The value of one pointer variable can be assigned to another pointer
variable of the same type.

15. A variable created during program execution is called a dynamic variable

16. The operator new is used to create a dynamic variable.

17. The operator delete is used to deallocate the memory occupied by a
dynamic variable.

18. In C++, both new and delete are reserved words.

19. The operator new has two forms: one to create a single dynamic variable,
and another to create an array of dynamic variables.

20. If p is a pointer of type int, the statement
p = new int;
allocates storage of type int somewhere in memory and stores the address
of the allocated storage in p.

21. The operator delete has two forms: one to deallocate the memory
occupied by a single dynamic variable, and another to deallocate the
memory occupied by an array of dynamic variables.

22. If p is a pointer of type int, the statement delete p; deallocates the
memory to which p points.

23. The array name is a constant pointer. It always points to the same memory
location, which is the location of the first array component.

24. To create a dynamic array, the form of the new operator that creates an
array of dynamic variables is used. For example, if p is a pointer of type
int, the statement
p = new int;
creates an array of 10 components of type int. The base address of the array
is stored in p. We call p a dynamic array.

25. Array notation can be used to access the components of a dynamic array. For
example, suppose p is a dynamic array of 10 components. Then p refers
to the first array component, p refers to the second array component,
and so on. In particular, p[i] refers to the (i + 1)th component of the array.

26. An array created during program execution is called a dynamic array.

27. If p is a dynamic array, then the statement
delete [] p;