This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
user:dsherbur:portfolio:cprogproject0 [2012/02/08 03:20] – [Code] dsherbur | user:dsherbur:portfolio:cprogproject0 [2012/02/08 04:07] (current) – [References] dsherbur | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ======Project: | ||
+ | |||
+ | 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/ | ||
+ | |||
+ | * 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===== | ||
+ | |||
+ | <code c> | ||
+ | /* | ||
+ | PROJECT 0 | ||
+ | DUSTIN SHERBURNE | ||
+ | DSHERBUR | ||
+ | CPROG | ||
+ | |||
+ | Range and size of data types | ||
+ | */ | ||
+ | #include < | ||
+ | #include < | ||
+ | int main() | ||
+ | { //char variables | ||
+ | unsigned long long int quantity=0; | ||
+ | unsigned char uc=0; | ||
+ | signed char sc=0; | ||
+ | //table header | ||
+ | printf(" | ||
+ | //unsigned char | ||
+ | printf(" | ||
+ | printf(" | ||
+ | quantity=(unsigned char)(uc-1)+1; | ||
+ | printf(" | ||
+ | //singed char | ||
+ | printf(" | ||
+ | quantity=(unsigned long long int)pow(2, | ||
+ | printf(" | ||
+ | printf(" | ||
+ | |||
+ | //short int variables | ||
+ | unsigned short int us=0; | ||
+ | signed short int ss=0; | ||
+ | //unsigned short int | ||
+ | printf(" | ||
+ | printf(" | ||
+ | quantity=(unsigned short int)(us-1)+1; | ||
+ | printf(" | ||
+ | //signed short int | ||
+ | printf(" | ||
+ | quantity=(unsigned short int)pow(2, | ||
+ | printf(" | ||
+ | printf(" | ||
+ | |||
+ | //int variables | ||
+ | unsigned int ui=0; | ||
+ | signed int si=0; | ||
+ | //unsigned int | ||
+ | printf(" | ||
+ | printf(" | ||
+ | quantity=(unsigned int)(ui-1); | ||
+ | printf(" | ||
+ | //signed int | ||
+ | printf(" | ||
+ | quantity=(unsigned long long int)pow(2, | ||
+ | printf(" | ||
+ | printf(" | ||
+ | | ||
+ | //long int variables | ||
+ | unsigned long int ul=0; | ||
+ | signed long int sl=0; | ||
+ | //unsigned long int | ||
+ | printf(" | ||
+ | printf(" | ||
+ | quantity=(unsigned long int)(ul-1); | ||
+ | printf(" | ||
+ | //signed long int | ||
+ | printf(" | ||
+ | quantity=(unsigned long long int)pow(2, | ||
+ | printf(" | ||
+ | printf(" | ||
+ | |||
+ | //long long int variables | ||
+ | unsigned long long int um=0; | ||
+ | signed long long int sm=0; | ||
+ | //unsigned long long int | ||
+ | printf(" | ||
+ | printf(" | ||
+ | quantity=(unsigned long int)(um-1); | ||
+ | printf(" | ||
+ | //signed long int | ||
+ | printf(" | ||
+ | quantity=(unsigned long long int)pow(2, | ||
+ | printf(" | ||
+ | printf(" | ||
+ | |||
+ | return(0); | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | =====Execution===== | ||
+ | |||
+ | <cli> | ||
+ | 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: | ||
+ | </ | ||
+ | |||
+ | =====Reflection===== | ||
+ | Comments/ | ||
+ | |||
+ | |||
+ | From doing this project, I have a greater understanding of the massive amount of capacity of memory. | ||
+ | =====References===== | ||
+ | In performing this project, the following resources were referenced: | ||
+ | |||
+ | * http:// | ||
+ | An " | ||
+ | * 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.) | ||