User Tools

Site Tools


user:dmckinn2:portfolio:cprogproject0

Project: DATA TYPE EXPLORATION

A project for cscs 1320 by Daniel McKinney during the Spring semester.

This project was begun on 2/8/12 and is anticipated to take till 2/10/12 complete. Project was completed on 2/10/12.

Objectives

Writing a program that will show the ranges of the different data types.

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

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

        #include<stdio.h>
        #include<math.h>
        int main()
        {
 
         //Variables
         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 quanity = 0;
         signed long long int slli = 0;
 
         // 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));
         quanity = (unsigned char)(uc-1) +1;
         printf("An Unsigned char can store %llu unique values\n\n", quanity);
 
         //Signed char data type
         printf("A signed char is %d bytes\n", sizeof(sc));
         quanity = (unsigned long long int)pow(2, (sizeof(sc)*8));
         printf("The range of a signed char is %hhd to %hhd\n", (sc-(quanity/2)), (sc+(quanity/2)-1));
         printf("A signed char can store %llu unique values\n\n", quanity);
 
         //Unsigned short int data type
         printf("An unsiged short int is %d bytes\n", sizeof(usi));
         printf("The range of an unsigned int is %hu to %hu\n", usi, (usi-1));
         quanity = (unsigned long long int)pow(2, (sizeof(usi)*8));
         printf("An unsigned int can store %llu unique values\n\n", quanity);
 
         //Signed short int data type
         printf("A signed short int is %d bytes\n", sizeof(ssi));
         quanity = (unsigned long long int)pow(2, (sizeof(ssi)*8));
         printf("The range of an signed short int is %d to %d\n", (ssi-(quanity/2)), (ssi+(quanity/2)-1));
         printf("A signed short int can store %llu unique values\n\n", quanity);
 
         //Unsigned int data type
         printf("An unsigned int is %d bytes\n", sizeof(ui));
         quanity = (unsigned long long int)pow(2, (sizeof(ui)*8));
         printf("The range of an unsigned int is %u to %u\n", ui, (ui-1));
         printf("An unsigned int can store %llu unique values\n\n", quanity);
 
         //Signed int data type
         printf("A signed int is %d bytes\n", sizeof(ui));
         quanity = (unsigned long long int)pow(2, (sizeof(ui)*8));
         printf("The range of an signed short int is %d to %d\n", (ui-(quanity/2)), (ui+(quanity/2)-1));
         printf("A signed int can store %llu unique values\n\n", quanity);
 
         //Unsigned long int data type
         printf("An unsigned long int is %d bytes\n", sizeof(uli));
         quanity = (unsigned long long int)pow(2, (sizeof(uli)*8));
         printf("The range of an unsigned long int is %llu to %llu\n", uli, (uli-1));
         printf("An unsigned long int can store %llu unique values\n\n", quanity);
 
         //Signed long int data type
         printf("A signed long int is %d bytes\n", sizeof(uli));
         quanity = (unsigned long long int)pow(2, (sizeof(uli)*8));
         printf("The range of an signed long int is %llu to %llu\n", (uli-(quanity/2)), (uli+(quanity/2)-1));
         printf("A signed long int can store %llu unique values\n\n", quanity);
 
        //Unsigned long long int data type
         printf("An unsigned long long int is %d bytes\n", sizeof(sli));
         quanity = (unsigned long long int)pow(2, (sizeof(sli)*8));
         printf("The range of an unsigned long long int is %lld to %llu\n", sli, (sli-1));
         printf("An unsigned long long int can store %llu unique values\n\n", quanity);
 
         //Signed long long int data type
         printf("A signed long long int is %d bytes\n", sizeof(sli));
         quanity = (unsigned long long int)pow(2, (sizeof(sli)*8));
         printf("The range of an signed long long int is %lld to %llu\n", (sli-(quanity/2)), (sli+(quanity/2)-1));
         printf("A signed long long int can store %llu unique values\n\n", quanity);
         return(0);
        }

Execution

lab46:~/src/cprog$./range

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 -128 to 127
A signed char can store 256 unique values

An unsigned short int is 2 bytes
The range of an unsigned short int is 0 to 65535
An unsigned int can store 65536 unique values

A signed short int is 2 bytes
The range of a signed short int is -32768 to 32767
A signed short int can store 65536 unique values

An unsigned int is 4 bytes
The range of an unsigned int is 0 to 4294967295
An unsigned int can store 4294967296 unique values

A signed int is 4 bytes
The range of a signed int is -2147483648 to 2147483647
A signed int can store 4294967296 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 -9223372036854775809 to 9223372036854775806
A signed long int can store 18446744076709551615 unique values

An unsigned long long int is 8 bytes
The range of a unsigned long long int it 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 in can store 18446744073709551615 unique values

Reflection

long long int can store a lot of unique values. The project was eye numbing but over all easy.

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/dmckinn2/portfolio/cprogproject0.txt · Last modified: 2012/02/17 11:40 by dmckinn2