Thread: How to compute the variable type range

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    2

    How to compute the variable type range

    Hi,

    In K&R C book in the second chapter there is an exercise to compute the range of variables like int, char etc. I have created a program to print the value from limits.h float.h. But it says we can compute the range and it is hard to compute. How can we compute the range without printing the header values.

  2. #2
    Registered User
    Join Date
    Jul 2009
    Posts
    9
    Quote Originally Posted by webofunni View Post
    Hi,

    In K&R C book in the second chapter there is an exercise to compute the range of variables like int, char etc. I have created a program to print the value from limits.h float.h. But it says we can compute the range and it is hard to compute. How can we compute the range without printing the header values.
    Think about what happens when you try to store a value larger than the maximum value for that type. Like storing 256 in an unsigned char. Try to come up with something that will incorporate that idea. You have learned about loops, haven't you?

    Or, you can get the size of the type by the sizeof operator and proceed on those lines.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Conversion of pointers to functions
    By hzmonte in forum C Programming
    Replies: 0
    Last Post: 01-20-2009, 01:56 AM
  2. Need some help...
    By darkconvoy in forum C Programming
    Replies: 32
    Last Post: 04-29-2008, 03:33 PM
  3. Replies: 6
    Last Post: 04-10-2008, 11:49 PM
  4. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  5. typename madness
    By zxcv in forum C++ Programming
    Replies: 4
    Last Post: 05-13-2006, 10:35 PM