Jul 31, 2014

How many bits are allocated by "int i;"?

A few years ago I took the Texas certification exam you must pass if you want to teach computer science in grades 8 through 12. It was a waste of time because I wound up teaching in junior colleges where you need at least a masters degree, but no certification. (Isn't it more than a little bit odd that you need a certification to teach in grades K-12 but none is required for college level teachers? Makes no sense to me.)

The test questions were mostly very simple, some down right stupid. But one question left me completely stumped.

How many bits are allocated by "int i;"?

You are supposed to pick the correct answer from a list of four possible values. None of the values were 64, but 8. 16. and 32 were on the list. IIRC 24 bits was also on the list.

At first I thought it must be 32. But, then I realized they had not stated which programming language they were talking about. Off the top of my head I could think of four languages with an "int" data type. It could have been C, C++, Java, or C#. I'm sure there are many more possibilities.

Depending on the age of the test and the version of the standard and/or the implementation of which ever language it was the answer could reasonably be 16 or 32. Which to pick? I picked 32. I didn't get a perfect score on the test, actually I got a high "B". Kind of embarrassing. But, I didn't feel too badly about the score. More than one question was either incomplete or had an answer that wasn't in the multiple choice list of answers. Ever been in that situation? You have to pick the correct answer from A, B, C, or D, but there is not enough information provided to pick the answer they want. Makes for a nasty day.

The point I'm trying to make is that the people, the panel of experts, chosen to write the test knew less about programming languages than I expect a second year CS student to know. Maybe standards for second year students have declined since I was in school (yeah, I know, typical old fart comment!). But, standards for experts have not declined. So, how could this happen? Even if you assume the language was C, the answer could be either 16 or 32. And, truth be told, I know of implementations where it could have been 36 bits.

The people who wrote the test did not know that there was more than one valid answer to the question. They could have checked most of the answers to the test questions by exercising their google muscles. But, they did not. The people trusted to write the certification test for CS teachers in Texas are clueless on the subject they are supposed to be experts in. So clueless they didn't even try to verify their answers. OK, what does that tell you about the other certification tests?

To make it worse... not long after I took that test CS was dropped from the required curriculum in Texas schools. That almost makes sense, if you can't even write a valid certification test, maybe you shouldn't try to teach the subject at all.


8 comments:

  1. Expert (Pronounced: /ˈekˌspərt/ or ex' spurt) An EX is something that once was, and a spurt is a drip under pressure. So an Expert is a merely a has been drip under pressure.

    ReplyDelete
  2. There are 8 bit "micro controllers" on the market. There are C compilers for them. But I don't know if int is 8, or a multiple precision 16.

    ReplyDelete
  3. I've never seen one with an 8 bit int. Those machines usually have 16 bit arithmetic operations that work on a pair of registers. I was able to find references to a small-C compiler for the pdp 8 that has a 12 bit int. But I'm not sure it it is real or just a discussion of what C would likely be like on a pdp 8.

    ReplyDelete
    Replies
    1. You are right Bob... You've never seen an 8 bit int.
      I note that the ANSI C standard sets 16 bits as a minimum size for int.

      Delete
  4. "sizeof(int) * 8" would have been a decent guess. If it compiled and there were 8 bits per byte...

    ReplyDelete
  5. In university I got a C++ test with a question like "In bool x = 9 > 4, what value is stored in x?" The answers were like "0, 1, 2, none of the above" and I chose "none of the above" because the correct answer is "true", knowing perfectly well that in all likelihood a compiler would store 1 in the register or memory that represents x, assuming that a register is allocated at all (depending on how x is used or not used, the optimizer might not even allocate a register for x at all, but never mind that.)

    They marked it wrong. So I went in and argued that just because ((int)x == 1) doesn't mean that 1 is stored in x. They wouldn't change my test score :P

    ReplyDelete
  6. professional web design companies
    Thanks for the entire information you have given here to impart knowledge amongst us?

    ReplyDelete