Zach wrote:
I recall someone posting a website that had the complete K&R (2nd Ed.
- ANSI) answers posted but I cannot find the post.
Well about a K&R2 exercise posted in another thread. I think the answer:
http://clc-wiki.net/wiki/K%26R2_solu...r_2:Exercise_1
#include <stdio.h>
#include <limits.h>
int
main ()
{
printf("Size of Char %d\n", CHAR_BIT);
printf("Size of Char Max %d\n", CHAR_MAX);
printf("Size of Char Min %d\n", CHAR_MIN);
printf("Size of int min %d\n", INT_MIN);
printf("Size of int max %d\n", INT_MAX);
printf("Size of long min %ld\n", LONG_MIN); /* RB */
printf("Size of long max %ld\n", LONG_MAX); /* RB */
printf("Size of short min %d\n", SHRT_MIN);
printf("Size of short max %d\n", SHRT_MAX);
printf("Size of unsigned char %u\n", UCHAR_MAX); /* SF */
printf("Size of unsigned long %lu\n", ULONG_MAX); /* RB */
printf("Size of unsigned int %u\n", UINT_MAX); /* RB */
printf("Size of unsigned short %u\n", USHRT_MAX); /* SF */
return 0;
}
is wrong and a bit incomplete.
I think the correct one is:
#include <stdio.h>
#include <limits.h>
int main ()
{
printf("Size of Char %d\n", CHAR_BIT);
printf("Size of Char Max %d\n", CHAR_MAX);
printf("Size of Char Min %d\n", CHAR_MIN);
printf("Size of int min %d\n", INT_MIN);
printf("Size of int max %d\n", INT_MAX);
printf("Size of long min %ld\n", LONG_MIN); /* RB */
printf("Size of long max %ld\n", LONG_MAX); /* RB */
printf("Size of short min %d\n", SHRT_MIN);
printf("Size of short max %d\n", SHRT_MAX);
== printf("Size of unsigned char max %u\n", (unsigned) UCHAR_MAX);
== printf("Size of unsigned long max %lu\n", ULONG_MAX); /* RB */
== printf("Size of unsigned int max %u\n", UINT_MAX); /* RB */
== printf("Size of unsigned short max %u\n", USHRT_MAX); /* SF */
return 0;
}