User Tools

Site Tools


user:mowens3:portfolio:cprogproject0

Project: DATA TYPE EXPLORATION

A project for COURSENAME by YOUR NAME during the SEMESTER YEAR.

This project was begun on DATE and is anticipated to take TIME UNIT 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?

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

To determine the possible values for each data type

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

#include <stdio.h>
#include <math.h>
 
int main()
{
        unsigned long long int quantity = 0;
        unsigned char uc = 0;
        signed char sc = 0;
        unsigned short int usi = 0;
        signed short int ssi = 0;
        unsigned int ui = 0;
        signed int si = 0;
        unsigned long int uli = 0;
        signed long int sli = 0;
        unsigned long long int ulli = 0;
        signed long long int slli = 0;
        printf("An unsigned char is %d bytes\n", sizeof(uc));
        printf("the range of an unsigned char is %hhu to %hhu\n", sc, (sc-1));
        quantity = (unsigned char)(uc -1) +1;
        printf("An unsigned char can store %llu unique values\n\n", quantity);
 
        printf("A signed char is %d bytes\n", sizeof(sc));
        quantity = (unsigned char)pow(2, sizeof(sc)*8);
        printf("The range of a signed char is %hhd to %hhd\n", (sc -(quantity/2)),(sc+(qu$
        printf("A signed char can store %llu unique values\n\n", quantity);
 
        printf("An unsigned short int is %d bytes\n", sizeof(usi));
        printf("the range of an unsigned short int is %hu to %hu\n", si, (si-1));
        quantity = (unsigned short int)(usi -1) +1;
        printf("An unsigned char can store %llu unique values\n\n", quantity);
 
 
        printf("A signed short int is %d bytes\n", sizeof(ssi));
        quantity = (unsigned short int)pow(2, sizeof(ssi)*16);
        printf("the range of a signed short int is %hd to %hd\n", (ssi - (quantity/2)),(s$
        printf("A signed short int can store %llu unique values\n\n", quantity);
 
        printf("An unsigned int is %d bytes\n", sizeof(ui));
        printf("the range of an unsigned int is %u to %u\n", si, (si-1));
        quantity = (unsigned int)(ui -1);
        printf("An unsigned int can store %llu +1 unique values\n\n", quantity);
 
        printf("A signed int is %d bytes\n", sizeof(si));
        quantity = (unsigned int)pow(2, sizeof(si)*32);
        printf("the range of a signed int is %d to %d\n",(si-(quantity/2)), (si+(quantity$
        printf("A signed int can store %llu unique values\n\n", quantity);
 
        printf("An unsigned long int is %d bytes\n", sizeof(uli));
        printf("the range of an unsigned long int is %lu to %lu\n", sli, (sli-1));
        quantity = (unsigned long int)(uli -1);
        printf("An unsigned long int can store %llu +1 unique values\n\n", quantity);
 
        printf("A signed long int is %d bytes\n", sizeof(sli));
        quantity = (unsigned long int)pow(2, sizeof(sli)*64);
        printf("the range of a signed long int is %ld to %ld\n", (sli-(quantity/2)),(sli+$
        printf("A signed long int can store %llu unique values\n\n", quantity);
 
        printf("An unsigned long long int is %d bytes\n", sizeof(ulli));
        printf("the range of a unsigned long long int is %llu to %llu\n", slli, (slli-1));
        quantity = (unsigned long long int)(ulli -1);
        printf("A unsigned long long int can store %llu +1 unique values\n\n", quantity);
 
        printf("A signed long long int is %d bytes\n", sizeof(slli));
        quantity = (unsigned long long int)pow(2, sizeof(slli)*64);
        printf("the range of a signed long long int is %lld to %lld\n", (slli-(quantity/2$
        printf("A signed long long int can store %llu unique values\n\n", quantity);
 
        return(0);
}

Execution

An unsigned char is 1 bytes
the range of an unsigned char is 0 to 255
An unsigned char can store 256 unique values

A signed char is 1 bytes
The range of a signed char is -127 to 126
A signed char can store 255 unique values

An unsigned short int is 2 bytes
the range of an unsigned short int is 0 to 65535
An unsigned char can store 65536 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 int is 4 bytes
the range of an unsigned int is 0 to 4294967295
An unsigned int can store 4294967295 +1 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 long int is 8 bytes
the range of an unsigned long int is 0 to 18446744073709551615
An unsigned long int can store 18446744073709551615 +1 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 a unsigned long long int is 0 to 18446744073709551615
A unsigned long long int can store 18446744073709551615 +1 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

lab46:~/src/cprog$ 

Reflection

I learned the sizes of the data types for this specific computer setup, but nothing much else.

References

In performing this project, the following resources were referenced:

  • URL1
  • 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/mowens3/portfolio/cprogproject0.txt · Last modified: 2012/02/09 17:08 by mowens3