quick.c

/*
 * showing some things about signed and unsifned int
 * printing floats or doubles
 * and signed and unsigned chars
 *
 * Matt Bishop, ECS 36A
 * April 4, 2024	original version
 */
#include 

/*
 * main routine
 */
int main(void)
{
	unsigned int i, k;
	double f, g;
	int j;
	char c;

	/* show what a signed looks like when unsigned */
	i = -1;
	j = -1;

	printf("-1 stored in an int is %d\n", j);
	printf("-1 stored in an unsigned int is %u\n", i);

	/* show what happens with integer overflow */
	k = -1;
	k += 1;

	printf("Add 1 to %u when it is stored in an unsigned int: %u\n", i, k);

	/* now show how printing a float or double works */
	f = 9.0030005;
	g = 9.003;
	printf("By default, floats or doubles are printed with 6 decimal places\n");
	printf("Here is 9.003: %f\n", g);
	printf("It rounds to 6 decimal places if needed; ");
	printf("here is 9.0030005: %f\n", g);

	/* now show signed, unsigned char */
	c = 'X';
	printf("You can print a char as a character: %c\n", c);
	printf("or you can print it as the number that represents it: %d\n", c);

	i = (unsigned int) -53;
	printf("unsigned -53 is %u\n", i);

	/* return all is well */
	return(0);
}

UC Davis sigil
Matt Bishop
Office: 2209 Watershed Sciences
Phone: +1 (530) 752-8060
Email: mabishop@ucdavis.edu
ECS 36A, Programming & Problem Solving
Version of April 8, 2024 at 9:31AM

You can get the raw source code here.

Valid HTML 4.01 Transitional Built with BBEdit Built on a Macintosh