1)How would you give a short and good explaination to someone who is a beginner in programming
of the following

  • short
  • long
  • typedef
  • const

Edited 2 Years Ago by rowen_1

short and long are two of the numeric data types (char, short, int, long, float and double). Only char has a guarenteed size, which is 1 byte with a range of -127 to 126. The size of all the others is compiler-dependent, so you have to look in the compiler's header file limits.h to find out what they are.

typedef just creates an alias name for something else. For example, typedef int MYINT; creates a new datatype name MYINT that's the same as int.

const just means the value of the variable or function can't be changed.

Only char has a guarenteed size, which is 1 byte with a range of -127 to 126.

Off by one. The guaranteed size is -127 to 127.

Yes, it was off, the range is -128 to 127

define SCHAR_MIN   (-128)      /* minimum signed char value */
#define SCHAR_MAX     127       /* maximum signed char value */

Edited 2 Years Ago by Ancient Dragon

Even char is not strictly defined as one byte, by my reading of the standard.

Objects declared as characters (char) shall be large enough to store any member of the implementation’s basic character set.

Could there be an implementation that uses a larger character set?

Or smaller? I know the number of bits im a byte varies quite a bit from one patform to another, but AFAIK a char is always 1 byte.

Yes, it was off, the range is -128 to 127

You're still off. The standard doesn't assume two's complement, so the minimum required range is 127 to 127. Your limits.h header will be more specific to the hardware, so it's best to get these minimum ranges right from the standard document.

This article has been dead for over six months. Start a new discussion instead.