










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!











Constants, Declarations, and Definitions
(There is a strong correlation between classes and structures.)
Using the correct name is critical. Sometimes you need to add a tag field to help keep track. It is important that the tag field be in the same location in every variant.
This is the first new C++ capability. You canโt do this in C.
termination
execution
destroyed automatically
and delete operators.
const int x = 10; /* x is a Constant Object */
const int y[] = {1, 2, 3, 4}; // y is a Array of Constant Objects const char ptr = "csci220"; / ptr: Pointer to a CONST OBJECT ptr[0] = 'R'; //ERROR!!! ptr = "Class_Notes"; /* ptr CAN POINT TO ANOTHER CONSTANT OBJECT! / char const cptr = "C++"; // cptr is a CONSTANT POINTER cptr[0] = 'c'; //LEGAL cptr = "Assignment"; //ERROR!! cptr CANNOT POINT TO // ANOTHER CONSTANT OBJECT! const char const dptr = "Simple_Language"; / dptr is a CONSTANT POINTER pointing to a CONSTANT OBJECT */ dptr[0] = 's'; //ERROR!! dptr = "Difficult_Language"; //ERROR!!
/* Declarations */ int my_function(); //function extern int x; //external variable struct S; //structure typedef int INT; //typedef
/* Implementation */ int my_function() { int i = 100; return(i); }
S *ps; //Acceptable S s1; //ERROR struct S { int x; char *ptr; }; // Complete Declaration S s2; //FINE int array[]; //incomplete int array[5]; //FINE