Search | | Contact Us | Resource Center Login | Home|

What is the output of the following program?

record rec
                a, a*, "Hello "
                s, string
                s = "world"

a. "Hello world"
b. "Hello" followed by the ASCII equivalent of the handle value of s
c. This does not compile
d. A runtime error

While strings and alphanumeric values can be used interchangeably most of the time, they differ in one very important respect:  alphanumeric fields are just sequences of bytes in memory, while strings are objects. Thus, you cannot overlay a string variable (which is really the object's handle) with an alphanumeric field in order to get at its contents.

A record is essentially a single alphanumeric field that overlays all of its member fields. But when a member is an object handle, alphanumeric operations on its containing record are not allowed, because then it would become possible to alter the handle value and create havoc for object management.  Thus, the compiler issues an error "Cannot use a record that contains a handle" on the "writes" statement, and (c) is therefore the correct answer.

In order to concatenate an alphanumeric value with the value of a string object, you can use string addition rather than an overlaying record.
For instance,

writes(1, a + s)

would produce the expected "Hello world".

More information about News and Events

Contact Synergex to learn more about  News and Events