How to compute the variable type range

This is a discussion on How to compute the variable type range within the C Programming forums, part of the General Programming Boards category; Hi, In K&R C book in the second chapter there is an exercise to compute the range of variables like ...

  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, 04:33 PM
  3. Replies: 6
    Last Post: 04-11-2008, 12:49 AM
  4. Replies: 0
    Last Post: 03-20-2008, 08:59 AM
  5. typename madness
    By zxcv in forum C++ Programming
    Replies: 4
    Last Post: 05-13-2006, 11:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21