User Tools

Site Tools


Sidebar

projects

pct0 (bonus; due 20190821)
cci0 (due 20190821)
wcp1 (due 20190821)
dtr0 (bonus; due 20190828)
pct1 (due 20190828)
wcp2 (due 20190828)
pct2 (due 20190904)
wcp3 (due 20190904)
sof0 (due 20190911)
pct3 (due 20190911)
wcp4 (due 20190911)
dow0 (due 20190918)
pct4 (due 20190918)
wcp5 (due 20190918)
mtf0 (due 20190925)
pct5 (due 20190925)
wcp6 (due 20190925)
mtf1 (due 20191002)
pct6 (due 20191002)
wcp7 (due 20191002)
bcf0 (due 20191010)
epf1 (due 20191010)
pct7 (due 20191009)
wcp8 (due 20191009)
cnv0 (due 20191023)
pct8 (bonus; due 20191023)
pct9 (due 20191023)
wcp9 (due 20191023)
cnv1 (due 20191030)
pctA (due 20191030)
wcpA (due 20191030)
fwf0 (due 20191106)
pctB (due 20191106)
wcpB (due 20191106)
cos0 (due 20191113)
pctC (due 20191113)
wcpC (due 20191113)
eoce (due 20191211 by 172959)
haas:fall2019:c4eng:projects:dtr0info

This is an old revision of the document!


dtr0 tips and tricks

Declaring variables

A variable is defined as: an element, feature, or factor that is liable to vary or change.

On the computer, a variable is memory location containing binary data. Often times, additional rules of interpretation will be applied to the binary data, pertaining to a certain format (integer data, floating point data, memory address data)

In C, variables need to be declared and ideally initialized before we use them. All variables need to be identified with some data format (otherwise known as a data type).

As talked about in class, and on the dtr0 project, there are a number of possible data types to choose from. For dtr0, we will be focusing on the integer types:

  • char
  • short int
  • int
  • long int
  • long long int

Each of these can store whole numbers, of differing ranges. The idea is to use the data type that “best fits” the scenario you are using it for.

ie, if you know you will ONLY need to use the values 0-100, while ALL of these integer types can accommodate such a request, there's one which can accommodate it while wasting the least amount of storage.

There is an additional qualifier we can associate with each of the integer types, and that is the indication of whether or not we wish to interact with negative numbers. The two qualifiers are:

  • signed - allow positive AND negative numbers
  • unsigned - no negative numbers at all

If you omit the signedness qualifier, it will likely default to a signed type.

To declare a short integer type named number with unsigned qualities:

unsigned short int number;

It is good programming practice to be as specific as possible. As such, when we declare variables, it is also a good idea to then initialize them to a known starting value (don't assume!). Here, we will initialize number to 0:

number  = 0;

We can combine both of these steps into one:

unsigned short int number  = 0;
haas/fall2019/c4eng/projects/dtr0info.1566574456.txt.gz · Last modified: 2019/08/23 15:34 by wedge