kent logo

CO538 Anonymous Questions and Answers Keyword Index

This page provides a keyword index to questions and answers. Clicking on a keyword will take you to a page containing all questions and answers for that keyword, grouped by year.

To submit a question, use the anonymous questions page. You may find the keyword index and/or top-level index useful for locating past questions and answers.

Keyword reference for variable-initialisation


Question 33 (2000):

When I do the following:

 INT x:

is it ok to assume that the x variable is always initialised to zero?

Or is it a bad assumption (like assuming the ALT statement will always act like the PRI ALT statement)?

Answer 33:

No, it's not OK - and yes, it is a bad assumption.

occam does not specify any initial values for variables. The KRoC implementation specifically does not initialise variables to zero - we get whatever happens to be in the memory allocated for the variable.

In general, it's probably a bad thing for languages to initialise variables automatically to arbitrary values like zero. Ideally, I would prefer any automatic initialisation to set data values to something very bad - like NaN (Not-a-Number) for floating-point or MinInt (for integers). We don't always want variables initialised to zero and having that happen by default makes us lazy - we may miss out a non-zero initialisation when it's needed. [Of course, this is not a universally held view ...]

Keywords: variable-initialisation

Valid CSS!

Valid XHTML 1.0!

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.
Last modified Mon May 20 13:50:34 2013
This document is maintained by Fred Barnes, to whom any comments and corrections should be addressed.