Lab 1: printf, scanf, pointers, parms

To write a basic C program we need to know how to use printf to create formatted output and how to use scanf to get input.
In addition this week we will look at how pointers are used, and will see an overview of how to implement reference parameters using pointers (to help with program 1).

Reading

Read the items listed below to prepare for this first week's lab. The reading will be the basis for a short quiz at the beginning of your lab.

As you read, remember to write down the main points in an outline (about a written half-page total, or 260+ words), which you will use with a partner in lab to help you create a tutorial. You will turn in this outline by the end of Monday, at midnight, using the Reading Outline form. In the outline you will also need: 1. A proposed catchy title, 2. An overview of how today's topic is useful, 3. Ideas of what kinds of sample code might help you demonstrate the concepts, and 4. A list of 4+ resources (besides the ones already given on the course web site).

1. programiz.com/c-programming/c-input-output Web page overview of basic input and output in a C program, using printf and scanf.

2. Understanding and Using C Pointers: Ch 1 pp 1-15 (Intro) This is the first part of Chapter 1 from the 2013 O'Reilly book: Understanding And Using C Pointers, by Richard Reese. This book is available for free through UIC's Safari, as described on the CS 211 Resources page. The above-linked excerpt of Ch1 pages 1-15 is stored on the Piazza Resources page.

3. Understanding... Ch 2 pp 61-63 (Parms) Also excerpted from the Understanding...Pointers book by Reese, and stored in Piazza. These few pages show you how to implement reference parameters, where you pass a variable to a function, change that value, and have the changed value reflected back to the calling code. You will need to know how to do this to write the first program.

Concepts / Questions to Address in your Tutorial

Remember that your audience for this tutorial is your classmates at this point in the semester. Imagine a student misses this week's reading, discussion, and lab. What is important for them to know? How might you best explain it to them, using original sample code and the corresponding input / output? Be sure to feature insightful explanations of your code examples.

  1. What does a simple C program look like? (Consider using your favorite saying/bumper sticker/quote).
    I suggest you use this Replit starter code (sharable with a partner!) as an environment in which to work, though there are other options you will see in the reading and also available on the CS 211 Resources page.

  2. What are the most-often used format types in printf and scanf? What are typical mistakes made, that we should guard against?

  3. What type should we use in printf to display a pointer, and what problem might arise if we just used %d?

  4. What happens if we use an uninitialized variable, where it is declared but no initial value is given? Use different online programming environments (listed on the CS 211 Resources page) to show how the same code with an uninitialized variable might work in one environment, but not in another, in some meaningful context. How might this cause a problem in situations using loops, parameters, or arrays?