User Tools

Site Tools


user:dsherbur:portfolio:cprogproject0

Project: DATA TYPE EXPLORATION

A project for C/C++ Programming by Dustin Sherburne during the Spring of 2012.

This project was begun on Tuesday, February 7th, 2012 and is anticipated to take an hour or two to complete. Project was completed on MONTH DAY, YEAR.

Objectives

State the purpose of this project. What is the point of this project? What do we hope to accomplish by undertaking it?

It is expected that we learn more about data types, the size of data types, and what they have to do with programming in C. We hope to gain a greater understanding of what programs do, thereby bringing us one step closer to mastering the language.

Prerequisites

In order to successfully accomplish/perform this project, the listed resources/experiences need to be consulted/achieved:

  • ability to log into Lab46
  • ability to edit text files
  • ability to compile C source code
  • ability to read and appropriately react to compiler messages during compilation
  • ability to execute compiled code
  • knowledge of the size of a byte, how many combinations are possible therein

Background

State the idea or purpose of the project. What are you attempting to pursue?

Upon approval, you'll want to fill this section out with more detailed background information. DO NOT JUST PROVIDE A LINK.

Providing any links to original source material, such as from a project page, is a good idea.

You'll want to give a general overview of what is going to be accomplished (for example, if your project is about installing a web server, do a little write-up on web servers. What is it, why do we need one, how does it work, etc.)

Scope

This project will be exploring the nature of some of the data types available to us in the C Programming Language. How much space is allocated to each type, how many numbers can exist within each type, and what are the ranges available for each type?

A program will be written that will display (to STDOUT) the size (in bytes), the lower and upper bounds of each studied type, and display the total quantity of values possible with each type.

The data types covered for this project will include:

  • unsigned char
  • signed char
  • unsigned short int
  • signed short int
  • unsigned int
  • signed int
  • unsigned long int
  • signed long int
  • unsigned long long int
  • signed long long int

The sizeof() and printf() functions, as well as arithmetic operators, will be utilized in performing much of the work.

Code

/*
PROJECT 0
DUSTIN SHERBURNE
DSHERBUR
CPROG
 
Range and size of data types
*/
#include <stdio.h>
#include <math.h>
int main()
{	//char variables
	unsigned long long int quantity=0;
	unsigned char uc=0;
	signed char sc=0;
	//table header
	printf("\n\n\t RANGE AND SIZE OF DATA TYPES\n\n\n");
	//unsigned char
	printf("CHAR (unsigned) is %d byte\n",sizeof(uc));
	printf("The range of an unsigned char is %hhu to %hhu\n",uc,(uc-1));
	quantity=(unsigned char)(uc-1)+1;
	printf("An unsigned char can store %llu unique values\n\n",quantity);
	//singed char
	printf("CHAR (signed) is %d byte\n",sizeof(sc));
	quantity=(unsigned long long int)pow(2,(sizeof(sc)*8));
	printf("The range of a signed char is %hhd to %hhd\n",(sc-(quantity/2)), (sc+(quantity/2)-1));
	printf("A signed char can store %llu unique values\n\n",quantity);
 
	//short int variables
	unsigned short int us=0;
	signed short int ss=0;
	//unsigned short int
	printf("SHORT INT (unsigned) is %d bytes\n",sizeof(us));
        printf("The range of an unsigned char is %hu to %hu\n",us,(us-1));
        quantity=(unsigned short int)(us-1)+1;
        printf("An unsigned short int can store %llu unique values\n\n",quantity);
	//signed short int
	printf("SHORT INT (signed) is %d bytes\n",sizeof(ss));
	quantity=(unsigned short int)pow(2,(sizeof(ss)*16));
	printf("The range of a signed short int is %hd to %hd\n",(ss-(quantity/2)), (ss+(quantity/2)-1));
	printf("A signed short int can store %llu unique values\n\n",quantity);
 
	//int variables
	unsigned int ui=0;
	signed int si=0;
	//unsigned int
	printf("INT (unsigned) is %d bytes\n",sizeof(ui));
        printf("The range of an unsigned int is %u to %u\n",ui,(ui-1));
        quantity=(unsigned int)(ui-1);
        printf("An unsigned int can store %llu unique values\n\n",quantity);
	//signed int
        printf("INT (signed) is %d bytes\n",sizeof(si));
        quantity=(unsigned long long int)pow(2,(sizeof(si)*8));
        printf("The range of a signed int is %d to %d\n",(si-(quantity/2)),(si+(quantity/2)-1));
        printf("A signed int can store %llu unique values\n\n",quantity);
 
	//long int variables
	unsigned long int ul=0;
	signed long int sl=0;
	//unsigned long int
	printf("LONG INT (unsigned) is %d bytes\n",sizeof(ul));
        printf("The range of an unsigned long int is %lu to %lu\n",ul,(ul-1));
        quantity=(unsigned long int)(ul-1);
        printf("An unsigned long int can store %llu unique values\n\n",quantity);
	//signed long int
        printf("LONG INT (signed) is %d bytes\n",sizeof(sl));
        quantity=(unsigned long long int)pow(2,(sizeof(sl)*8));
        printf("The range of a signed long int is %ld to %ld\n",(sl-(quantity/2)),(sl+(quantity/2)-1));
        printf("A signed long int can store %llu unique values\n\n",quantity);
 
	//long long int variables
	unsigned long long int um=0;
	signed long long int sm=0;
	//unsigned long long int
	printf("LONG LONG INT (unsigned) is %d bytes\n",sizeof(um));
        printf("The range of an unsigned long int is %lu to %lu\n",um,(um-1));
        quantity=(unsigned long int)(um-1);
        printf("An unsigned long int can store %llu unique values\n\n",quantity);
        //signed long int
        printf("LONG LONG INT (signed) is %d bytes\n",sizeof(sm));
        quantity=(unsigned long long int)pow(2,(sizeof(sm)*8));
        printf("The range of a signed long long int is %lld to %lld\n",(sm-(quantity/2)),(sm+(quantity/2)-1));
        printf("A signed long long int can store %llu unique values\n\n",quantity);
 
	return(0);
}

Execution

	 RANGE AND SIZE OF DATA TYPES


CHAR (unsigned) is 1 byte
The range of an unsigned char is 0 to 255
An unsigned char can store 256 unique values

CHAR (signed) is 1 byte
The range of a signed char is -128 to 127
A signed char can store 256 unique values

SHORT INT (unsigned) is 2 bytes
The range of an unsigned char is 0 to 65535
An unsigned short int can store 65536 unique values

SHORT INT (signed) is 2 bytes
The range of a signed short int is -32767 to 32766
A signed short int can store 65535 unique values

INT (unsigned) is 4 bytes
The range of an unsigned int is 0 to 4294967295
An unsigned int can store 4294967295 unique values

INT (signed) is 4 bytes
The range of a signed int is -2147483648 to 2147483647
A signed int can store 4294967296 unique values

LONG INT (unsigned) is 8 bytes
The range of an unsigned long int is 0 to 18446744073709551615
An unsigned long int can store 18446744073709551615 unique values

LONG INT (signed) is 8 bytes
The range of a signed long int is -9223372036854775807 to 9223372036854775806
A signed long int can store 18446744073709551615 unique values

LONG LONG INT (unsigned) is 8 bytes
The range of an unsigned long int is 0 to 18446744073709551615
An unsigned long int can store 18446744073709551615 unique values

LONG LONG INT (signed) is 8 bytes
The range of a signed long int is -9223372036854775807 to 9223372036854775806
A signed long int can store 18446744073709551615 unique values


lab46:~/src/cprog$ 

Reflection

Comments/thoughts generated through performing the project, observations made, analysis rendered, conclusions wrought. What did you learn from doing this project?

From doing this project, I have a greater understanding of the massive amount of capacity of memory. The capabilities and potential of that vast space just fucking tickle me. I have observed, seen, but a small fraction of the inner workings of the machine. I have knocked upon the doors of a handful of houses among billions. I have seen containers the size of a closet, and have realized the possibility of containers of incredible depth. We have briefly grazed upon only a small part of the machine as a whole, however. This is by no means a defining experience, and yet so enlightening. Invoking Moore's Law and pondering the future is an exiting and painful task for the wait. I conclude that managing this memory and having control over it will be a very important skill to develop.

References

In performing this project, the following resources were referenced:

An “informative” data type chart, showing ranges for many different types of integer data. I Googled “int range” and it was one of the first links. Helped me panic.

  • URL2
  • URL3 (provides useful information on topic)
  • URL4

Generally, state where you got informative and useful information to help you accomplish this project when you originally worked on it (from Google, other wiki documents on the Lab46 wiki, etc.)

user/dsherbur/portfolio/cprogproject0.txt · Last modified: 2012/02/07 23:07 by dsherbur