The C language offers many varieties of integer types a Expl

The C language offers many varieties of integer types, (a) Explain why. Is this wide variety of types good or bad?

Solution

a)

C offers many integer types, because C gives the programmer the option of matching a type to a particular use. In particular, the C integer types vary in the range of values offered and in whether negative numbers can be used. The int type is the basic choice, but should you need other choices to meet the requirements of a particular task or machine, they are available.

The int type is a signed integer. That means it must be an integer and it can be positive, negative, or zero. The range in possible values depends on the computer system. Typically, an int uses one machine word for storage. Therefore, older IBM PC compatibles, which have a 16-bit word, use 16 bits to store an int. This allows a range in values from –32768 to 32767. Current personal computers typically have 32-bit integers and fit an int to that size.

ISO/ANSI C specifies that the minimum range for type int should be from –32767 to 32767. Typically, systems represent signed integers by using the value of a particular bit to indicate the sign

b) The output is :

sh-4.3$ gcc -o main *.c                                                                                                                                

main.c: In function \'main\':                                                                                                                            

main.c:7:5: error: unknown type name \'unsigned_int\'                                                                                                    

     unsigned_int stop_val;                                                                                                                            

     ^                                                                                                                                                 

main.c:14:10: error: \'EXIT_SUCESS\' undeclared (first use in this function)                                                                             

     exit(EXIT_SUCESS);                                                                                                                                

          ^                                                                                                                                            

main.c:14:10: note: each undeclared identifier is reported only once for each function it appears in                                                   

sh-4.3$

 The C language offers many varieties of integer types, (a) Explain why. Is this wide variety of types good or bad? Solutiona) C offers many integer types, beca

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site