Department of Electrical Engineering and Computer Science
6.087: Practical Programming in C
IAP 2010
Problem Set 2 – Solutions
Types, operators, expressions
Out: Tuesday, January 12, 2010. Due: Wednesday, January 13, 2010.
Problem 2.1
Determine the size,minimum and maximum value following data types. Please specify if your
machine is 32 bit or 64 bits in the answer.
• char
• unsigned char
• short
• int
• unsigned int
• unsigned long
• float
Hint: Use sizeof() operator,limits.h and float.h header files
Answer: On my 32-bit machine (/usr/include/limits.h,/usr/include/float.h), the sizes and limits
are as follows. Results may differ if you used a 64 bit machine.
Data type size (bytes) min max
char 1 SCHAR MIN (-128) SCHAR MAX (127)
unsigned char 1 0 UCHAR MAX(255)
short 2 SHRT MIN (-32768) SHRT MAX (32767)
int 4 INT MIN (-2147483648) INT MAX (2147483647)
unsigned int 4 0 UINT MAX(4294967295)
unsigned long 4 0 ULONG MAX(4294967295)
float 4 FLT MIN(1.175494e-38) FLT MAX(3.402823e+38)
Problem 2.2
Write logical expressions that tests whether a given character variable c is
• lower case letter (Answer: c>=’a’&& c<=’z’)
• upper case letter (Answer: c>=’A’&& c<=’Z’)
• digit (Answer: c>=’0’&& c<=’9’)
1