A project for CPROG by Lauren Burzynski during the Fall of 2011.
This project was begun on September 19, 2011 and is anticipated to take 1 week to complete. Project was completed on MONTH DAY, YEAR.
The objective of this project is to identify different data types, and learn how to use them properly when writing lines of code.
In order to successfully accomplish/perform this project, the listed resources/experiences need to be consulted/achieved:
The purpose of this project is to learn the basics of writng code. When it comes to different variables, it is important to learn each one and the meaning behind them in order to properly execute lines of code and write programs. I am attempting to write some simple lines of code using each different data type properly, while defining what each variable means to the compiler.
http://rajkishor09.hubpages.com/hub/Data-Types-in-C-Language This website suppiles great information about several different types of data types, as well as including different sizes for each type. A program usually contains different types of data types in order to run properly, and the user needs to list the data types at the beginning of the code, then list the values for each data type being used in the program.
http://www.exforsys.com/tutorials/c-language/c-programming-language-data-types.html This website clarifies the differences between signed and unsigned variables, as well as explains the difference between data types (such as the difference between an integer and a character). This website also shows a sample code of all of these different data types being used in a program.
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:
The sizeof() and printf() functions, as well as arithmetic operators, will be utilized in performing much of the work.
/*--- range.c begin --- * Compile with: gcc -o range range.c -lm * Execute with: ./range */ #include <stdio.h> #include <math.h> int main() { // Variables unsigned long long int quantity = 0; unsigned char uc = 0; signed char sc = 0; // Display information for unsigned char data type printf("An unsigned char is %d bytes\n", sizeof(uc)); printf("The range of an unsigned char is %hhu to %hhu\n", uc, (uc-1)); quantity = (unsigned char)(uc-1) + 1; // What does this line do? printf("An unsigned char can store %llu unique values\n\n", quantity); // Display information for signed char data type printf("A signed char is %d bytes\n", sizeof(sc)); quantity = (unsigned long long int)pow(2, (sizeof(sc)*8)); // What is happe$ printf("The range of a signed char is %hhd to %hhd\n", (sc-(quantity/2)), ($ printf("A signed char can store %llu unique values\n\n", quantity); return(0); }
lab46:~/src/cprog$ ./hello Hello, World! lab46:~/src/cprog$
Comments/thoughts generated through performing the project, observations made, analysis rendered, conclusions wrought. What did you learn from doing this project?
In performing this project, the following resources were referenced:
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.)