projects
- php0 (due 20150909)
Corning Community College
CSCS2320 Data Structures
~~TOC~~
To familiarize yourself with the available data types in C- the variations, the attributes, the ranges therein.
In order to successfully accomplish/perform this project, the listed resources/experiences need to be consulted/achieved:
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 (as accurately as possible) display the total quantity of values possible with each type.
The data types covered for this project will include signed and unsigned variations of:
The sizeof() and printf() functions, as well as arithmetic and logical operators, will be utilized in performing much of the work.
Here is the skeleton of a program you'll want to use for this project:
/* * datatypes.c - A program to derive and display information * for the signed and unsigned data types in C * * * A program by NAME for CSCS1320 COURSE (SEMESTER) * * Compile with: gcc -o datatypes datatypes.c * Execute with: ./datatypes */ #include <stdio.h> int main() { // Variables unsigned char uchr = 0; // Code for unsigned char // Code for signed char // Code for unsigned short int // Code for signed short int // Code for unsigned int // Code for signed int // Code for unsigned long int // Code for signed long int // Code for unsigned long long int // Code for signed long long int return(0); }
Following is provided code giving you the requested information for an unsigned char. Study it, implement it, and adapt it as needed to the other data types:
// Code for unsigned char fprintf(stdout, "TYPE: %13s, ", "unsigned char"); // What is happening here? fprintf(stdout, "bytes: %lu, ", sizeof(uchr)); // Why does sizeof() need %lu? fprintf(stdout, "low: %hhu, ", (uchr & 0x00)); // Why 2 zeros? fprintf(stdout, "high: %hhu, ", (uchr | 0xFF)); // Why 2 F's? uchr = uchr - 1; // What does this line do? fprintf(stdout, "qty: %hu\n", (uchr+1)); // What is going on here?
Note that by adapting, you'll need to declare and initialize additional variables, and you may “unroll” some of the logic here to do it in more discrete steps (in fact, it may enable you to solve a couple problems that crop up).
lab46:~/src/data$ ./datatypes TYPE: unsigned char, bytes: 1, low: 0, high: 255, qty: 256 TYPE: signed char, bytes: X, low: X, high: X, qty: X TYPE: unsigned short int, bytes: X, low: X, high: X, qty: X TYPE: signed short int, bytes: X, low: X, high: X, qty: X ... lab46:~/src/data$
This output includes some mock additional entries, actual values abstracted. Instead of displaying 'X', your program should display the actual values, and display a total of 10 lines, for the signed and unsigned variations of the five data types we are studying in this project.
Be sure to provide any commentary on your opus regarding realizations had and discoveries made during your pursuit of this project.
Also, answer the following questions:
To successfully complete this project, the following criteria must be met:
To submit this program to me using the submit tool, run the following command at your lab46 prompt:
$ submit data datatypes datatypes.c Submitting data project "datatypes": -> datatypes.c(OK) SUCCESSFULLY SUBMITTED
You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches.