Data types in C interview questions


Total available count: 8
Subject - Programming Languages
Subsubject - Data types in C

How short modifier is used to modify the int data type?

The short modifier is used to modify the int data type. 

Compilers, which have the same memory requirement e.g. 4 bytes (or 32 bits) for int as well as long int, will generally have half the size i.e., 2 bytes for a short int. In such a case, if an int is defined as, short int, then it will occupy only 2 bytes as against 4 bytes, had it been defined as an ordinary int. 
 
But if a compiler is written so that the compiler requirement is the same for an ordinary int as well as short int e.g. 2 bytes, then it makes no difference whether it is defined as a short int or just an int. The range of numbers that it can store in either case will be the same.

An unsigned int has the same memory requirements as an ordinary int. However, in the case of an ordinary int, or short int or long int, the left most bit is reserved for the sign. 
 
A typical 2-byte int,  has a range of +32767  to -32768. An unsigned int is supposed to store only non negative values and thus can utilize the sign bit also. In this way a 2-byte unsigned int can store integer values ranging from 0 to 65535. 

The signed data modifier makes it explicit that the basic data type uses a sign bit. That is, the data type can accommodate both positive and negative numbers.
 
If a variable is a signed int, it has the same positive and negative range as a regular int. By default, an int is a signed data type. 

Example:  

  1. short int j;
  2. unsigned char a;
  3. unsigned int i;
  4. unsigned short int i;
  5. long  int i;
  6. unsigned long int n;



Next 2 interview question(s)

1
What are the Basic Data types?
2
Which Modifiers used with Basic Data Types?


Comments