User Tools

Site Tools


user:abrunda1:portfolio:datatypes

Project: DATA TYPE EXPLORATION

A project for CPROG by Andrew Brundage during the Fall 2011.

Objectives

State the purpose of this project. What is the point of this project? What do we hope to accomplish by undertaking it?

To find out how much space each data type typically takes up of the ones specified below.

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.

Attributes

  • variables: A variable for each of the stated data types will be declared and manipulated.
  • I/O: To ascertain the properties of the data types, important values will be displayed to STDOUT.

Code

#include <stdio.h>
#include <stdlib.h>
 
int main()
{
	unsigned char unchar;
	signed char sichar;
	unsigned short int unshoint;
	signed short int sishoint;
	unsigned int unsint;
	signed int sigint;
	unsigned long int unlonint;
	signed long int silonint;
	unsigned long long int unllint;
	signed long long int sillint;
	printf("%3d bytes: unsigned char\n", sizeof(unchar));
	printf("%3d bytes: signed char\n", sizeof(sichar));
	printf("%3d bytes: unsigned short int\n", sizeof(unshoint));
	printf("%3d bytes: signed short int\n", sizeof(sishoint));
	printf("%3d bytes: unsigned int\n", sizeof(unsint));
	printf("%3d bytes: signed int\n", sizeof(sigint));
	printf("%3d bytes: unsigned long int\n", sizeof(unlonint));
	printf("%3d bytes: signed long int\n", sizeof(silonint));
	printf("%3d bytes: unsigned long long int\n", sizeof(unllint));
	printf("%3d bytes: signed long long int\n", sizeof(sillint));
	return 0;
}

Execution

lab46:~/src/projects/datatypes$ ./datatypes 
  1 bytes: unsigned char
  1 bytes: signed char
  2 bytes: unsigned short int
  2 bytes: signed short int
  4 bytes: unsigned int
  4 bytes: signed int
  8 bytes: unsigned long int
  8 bytes: signed long int
  8 bytes: unsigned long long int
  8 bytes: signed long long int
lab46:~/src/projects/datatypes$ 

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/abrunda1/portfolio/datatypes.txt · Last modified: 2011/12/16 00:33 by abrunda1