This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
user:jcavalu3:portfolio:cprogproject0 [2012/02/09 19:33] – [Objectives] jcavalu3 | user:jcavalu3:portfolio:cprogproject0 [2012/02/11 05:39] (current) – [Execution] jcavalu3 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ======Project: | ||
+ | A project for C/C++ Programming by Josh Cavaluzzi during the Spring 2012. | ||
+ | |||
+ | This project was begun on February 2, 2012 and is anticipated to take 5 days to complete. Project was completed on February 11, 2012, at 12:15 in the morning... I am tired! | ||
+ | =====Objectives===== | ||
+ | The objective of this project is to explore the different data types available for use in the C Programming 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===== | ||
+ | In this project, I will use programming to show the different data types available in the C Programming Language. A list of them are: | ||
+ | |||
+ | -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 | ||
+ | | ||
+ | Using this different data types allows programmers to use different amounts of space according to the size of the variable that they would like to represent. The smallest data type is the char (character) which has only one byte of memory available. The largest is the long long int (integer), which has 8 bytes of memory available. | ||
+ | =====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> | ||
+ | /* | ||
+ | * range.c - A program to display information for signed and unsigned data char types | ||
+ | * | ||
+ | * | ||
+ | * Compile with: gcc -o range range.c -lm | ||
+ | * Execute with: ./range | ||
+ | */ | ||
+ | |||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | // Signed Variables | ||
+ | signed char sc = 0; | ||
+ | signed short int ssint = 0; | ||
+ | signed int sint = 0; | ||
+ | signed long int slint = 0; | ||
+ | signed long long int sllint = 0; | ||
+ | |||
+ | // Unsigned Variables | ||
+ | unsigned char uc = 0; | ||
+ | unsigned short int usint = 0; | ||
+ | unsigned int uint = 0; | ||
+ | unsigned long int ulint = 0; | ||
+ | unsigned long long int ullint = 0; | ||
+ | |||
+ | // Junk Variable | ||
+ | unsigned long long int quantity = 0; | ||
+ | |||
+ | // Display information for unsigned char data type | ||
+ | printf(" | ||
+ | printf(" | ||
+ | quantity = (unsigned char)(uc-1); | ||
+ | printf(" | ||
+ | |||
+ | // Display information for signed char data type | ||
+ | printf(" | ||
+ | quantity = (unsigned long long int)pow(2, (sizeof(sc)*8)); | ||
+ | printf(" | ||
+ | printf(" | ||
+ | |||
+ | // Display information for unsigned int data type | ||
+ | printf(" | ||
+ | printf(" | ||
+ | quantity = (unsigned int)(uint-1); | ||
+ | printf(" | ||
+ | | ||
+ | // Display information for unsigned short int data type | ||
+ | printf(" | ||
+ | printf(" | ||
+ | quantity = (unsigned short int)(usint-1); | ||
+ | printf(" | ||
+ | | ||
+ | // Display information for signed int data type | ||
+ | printf(" | ||
+ | quantity = (unsigned int)pow(2, (sizeof(sint)*8)); | ||
+ | printf(" | ||
+ | printf(" | ||
+ | |||
+ | // Display information for signed short int data type | ||
+ | printf(" | ||
+ | quantity = (unsigned short int)pow(2, (sizeof(ssint)*8)); | ||
+ | printf(" | ||
+ | printf(" | ||
+ | |||
+ | // Display information for unsigned long int data type | ||
+ | printf(" | ||
+ | printf(" | ||
+ | quantity = (unsigned long int)(ulint-1); | ||
+ | printf(" | ||
+ | |||
+ | // Display information for signed long int data type | ||
+ | printf(" | ||
+ | quantity = (unsigned long int)pow(2, (sizeof(slint)*8)); | ||
+ | printf(" | ||
+ | printf(" | ||
+ | |||
+ | // Display information for unsigned long long int data type | ||
+ | printf(" | ||
+ | printf(" | ||
+ | quantity = (unsigned long long int)(ulint-1); | ||
+ | printf(" | ||
+ | |||
+ | // Display information for signed long long int | ||
+ | printf(" | ||
+ | quantity = (unsigned long long int)pow(2, (sizeof(sllint)*8)); | ||
+ | printf(" | ||
+ | printf(" | ||
+ | |||
+ | return(0); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | =====Execution===== | ||
+ | |||
+ | <cli> | ||
+ | An unsigned char is 1 bytes | ||
+ | The range of an unsigned char is 0 to 255 | ||
+ | An unsigned char can store 255 unique values | ||
+ | |||
+ | A signed char is 1 bytes | ||
+ | The range of a signed char is -128 to 127 | ||
+ | A signed char can store 256 unique values | ||
+ | |||
+ | An unsigned int is 4 bytes | ||
+ | The range of an unsigned int is 0 to 4294967295 | ||
+ | An unsigned int can store 4294967295 unique values | ||
+ | |||
+ | A signed int is 4 bytes | ||
+ | The range of a signed int is -2147483647 to 2147483646 | ||
+ | A signed int can store 4294967295 unique values | ||
+ | |||
+ | An unsigned short int is 2 bytes | ||
+ | The range of an unsigned short int is 0 to 65535 | ||
+ | An unsigned short int can store 65535 unique values | ||
+ | |||
+ | A signed short int is 2 bytes | ||
+ | The range of a signed short int is -32767 to 32766 | ||
+ | A signed short int can store 65535 unique values | ||
+ | |||
+ | An unsigned long int is 8 bytes | ||
+ | The range of an unsigned long int is 0 to 18446744073709551615 | ||
+ | An unsigned long int can store 18446744073709551615 unique values | ||
+ | |||
+ | A signed long int is 8 bytes | ||
+ | The range of a signed long int is -9223372036854775807 to 9223372036854775806 | ||
+ | A signed long int can store 18446744073709551615 unique values | ||
+ | |||
+ | An unsigned long long int is 8 bytes | ||
+ | The range of an unsigned long long int is 0 to 18446744073709551615 | ||
+ | An unsigned long long int can store 18446744073709551615 unique values | ||
+ | |||
+ | A signed long long int is 8 bytes | ||
+ | The range of a signed long long int is -9223372036854775807 to 9223372036854775806 | ||
+ | A signed long long int can store 18446744073709551615 unique values | ||
+ | </ | ||
+ | |||
+ | =====Reflection===== | ||
+ | The project really helped me begin learning how the different data types work and the sizes of each. Before the project, my thoughts of them were a little clouded by confusion, but now that I understand what is happening and how much memory they actually use, I find them very interesting. Also, I used a few debugging strategies when I ran into problems, which helped me fix them very quickly and effectively. My final thought is the ' | ||
+ | =====References===== | ||
+ | In performing this project, the following resources were referenced: | ||
+ | |||
+ | * http:// | ||
+ | |||
+ | I believe that is the only reference I used, and it really didn't help me with what I needed. |