User Tools

Site Tools


user:lburzyns:portfolio:datatypes

Project: DATA TYPE EXPLORATION

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.

Objectives

The objective of this project is to identify different data types, and learn how to use them properly when writing lines of code.

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

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.

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

/*--- 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);
}

Execution

lab46:~/src/cprog$ ./hello
Hello, World!
lab46:~/src/cprog$ 

Reflection

Comments/thoughts generated through performing the project, observations made, analysis rendered, conclusions wrought. What did you learn from doing this project?

References

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.)

user/lburzyns/portfolio/datatypes.txt · Last modified: 2011/09/26 17:46 by lburzyns