Lab 4 - FL13 - ECE 198 JL - University of Illinois - Engineering Wiki

Lab 4 - FL13 - ECE 198 JL - University of Illinois - Engineering Wiki

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Lab 4 - FL13 Lab 4 assignment is due on Wednesday, September 18, by 7pm in your svn repository. It is highly recommended that you complete this lab prior to the first midterm. Introduction to C In this exercise you are going to work with different data types of the C programming language. You will see the effect of using different data types on the same computation and will understand when to use a particular data type. Also, you will operate with different logical constructs available in C. You will learn about the while and the for looping constructs which can be used to iterate and do a job for a number of times. Along the way you will also learn about the various input and output mechanisms available in C. Don't fret, we are sure you will have lots of fun! Data Types in C C has a concept of ' data types ' which are used to define a variable before its use. The definition of a variable will assign storage for the variable and define the type of data that will be held in the location. There are several integral data types, floating point data types for holding real numbers and more. In addition you can define your own data types using aggregations of the native types (you'll learn more about that in future labs). Some of these that you will be using are int The int data type represents a signed integer. For most of your simple computations, this will be your go-to data type. On the lab machines running on 64-bit Intel x86 processors, the int type is 32 bits, so it represent any integer between -2147483648 and 2147483647. Notice that we say on 64-bit Intel x86 processors . This is because the size of the integer data types can vary from processor to processor. For example, on the LC-3 (a 16-bit processor), an int is 16 bits. In this author's opinion, lack of consistency of integer data types is a significant deficiency of the C language, and is something to be aware of if you write code that you want to run on different processors. (Floating point types are consistent and don't have this problem). For exercises in this class, we can assume that ints are 32-bits. The interested reader can also learn about a header <inttypes.h> , which provides a set of types that are guaranteed to be consistent across platforms. float float data type allows you to store floating point numbers which the int data type cannot handle. Remember the IEEE 754 floating point representation of numbers? float denotes the 32-bit, single precision format, which has a range of -3.4 × 10 38 to +3.4 × 10 38 . Many real world computations result in a floating point result. If you use the int data type to hold such results, you will not get accurate answers. This is because the int data type truncates everything after the decimal position. So if your answer is 3.14 and you try to hold this in a variable defined as int , you will get 3 as your answer. The 0.14 part will be truncated thereby resulting in inaccurate results.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 10

Lab 4 - FL13 - ECE 198 JL - University of Illinois - Engineering Wiki

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online