A program can fail to make sense fail to be correct fail to stop and it can

A program can fail to make sense fail to be correct

This preview shows page 9 - 14 out of 23 pages.

A program can fail to make sense, fail to be correct, fail to stop, and it can crash; this will be experienced more often than wished. . . We have made our first acquaintance with pointers , claimed to be the most difficult aspect of the C language. We have a very simple but powerful enough model of memory that is essential to understanding fundamental programming concepts. This model is necessary, and in many ways sufficient, to develop strong C programming skills. COMP9021 (Principles of Programming) Notes 1.0: Introduction to programming in C 2014 session 1 9 / 23
Image of page 9

Subscribe to view the full document.

Programs, inputs, outputs We will study the activity of: writing programs , making use of and for use by a computer; providing data —the input —to the computer; letting the computer code the input and the program into sequences of bits , namely, 0s and 1s, and store those sequences into memory ; letting the computer execute the program and perform various operations on bits; letting the computer decode some sequences of bits that represent computation results —the output ; having the output displayed or stored. 1 76134 a 0 76134 b 1 76134 c 1 76134 d 0 76134 e 1 76134 f 1 76134 g 0 76134 h 0 76135 a 1 76135 b A simple abstraction of memory COMP9021 (Principles of Programming) Notes 1.0: Introduction to programming in C 2014 session 1 10 / 23
Image of page 10
Dealing with input and output (1) Input can come from: the keyboard, in two possible ways: when the user starts the program and provides command line arguments ; after the program has been started and stopped execution, usually prompting the user to enter some information; a file. Output can be sent to: the screen; a file. Some programs do not need any input, or do not produce any output. The program input_output.c , together with the interaction described next, gives a flavour of how a program will be compiled and run , getting input and yielding output in all possible ways just mentioned. COMP9021 (Principles of Programming) Notes 1.0: Introduction to programming in C 2014 session 1 11 / 23
Image of page 11

Subscribe to view the full document.

Dealing with input and output (2) $ ls input_file.txt input_file.txt $ cat input_file.txt There is only line in this file. $ ls output_file.txt ls: output_file.txt: No such file or directory $ gcc -std=gnu99 -Wall input_output.c $ ./a.out v Enter a character please: X I have seen the characters v, X and T $ ls output_file.txt output_file.txt $ cat output_file.txt I have kept track of the characters v, X and T COMP9021 (Principles of Programming) Notes 1.0: Introduction to programming in C 2014 session 1 12 / 23
Image of page 12
Two worlds, close up to a point where they diverge. . . (1) Often programs deal with numbers and operations on numbers. Basic mathematical functions, such as multiplication between integers, are already implemented and ready for use. The output of the program two_worlds.c suggests that the relationship between the world of computing and the usual world of numbers and operations on numbers is not as simple as one might expect, as both worlds closely correspond to each other up to a point where they diverge.
Image of page 13

Subscribe to view the full document.

Image of page 14
  • Fall '19
  • 11

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes