Book contents
- Frontmatter
- Contents
- Preface
- 1 Introduction
- 2 Computer Programming
- 3 Types, Operators, and Expressions
- 4 Control Flow
- 5 Type Conversion, Functions, and Scope
- 6 Pointers, Arrays, and Structures
- 7 File Operations
- 8 Case Studies
- Appendix A C Language Summary
- Appendix B Fortran Program Language Summary
- Appendix C ASCII Tables
- Appendix D C Preprocessor Directives
- Appendix E Precedence Tables
- Glossary
- Annotated Bibliography
- Index
5 - Type Conversion, Functions, and Scope
Published online by Cambridge University Press: 05 June 2012
- Frontmatter
- Contents
- Preface
- 1 Introduction
- 2 Computer Programming
- 3 Types, Operators, and Expressions
- 4 Control Flow
- 5 Type Conversion, Functions, and Scope
- 6 Pointers, Arrays, and Structures
- 7 File Operations
- 8 Case Studies
- Appendix A C Language Summary
- Appendix B Fortran Program Language Summary
- Appendix C ASCII Tables
- Appendix D C Preprocessor Directives
- Appendix E Precedence Tables
- Glossary
- Annotated Bibliography
- Index
Summary
Interpretation of data is an important element in the process of describing how the computer acts upon data. If this interpretation is faulty, control structures will not operate properly or data will be misrepresented on output. The definitions of Fortran and C types were explained in Chapter 3; however, the underlying assumption was that types of variables would not be mixed. In other words, calculations involving real variables would only use real variables, and those involving integers would only use integers. Also, the size of variables, or how large a value a variable can hold, was not considered in any detail other than the observation that a double variable is twice the size of a float, and so forth. This chapter will explore the nature of type mixing and the importance of knowing the usage rules for type conversion.
As you know, a program is a set of instructions to perform a task. Large tasks can require programs of huge scope and size; thus, it is useful to be able to partition programs into logical segments. Subroutines or functions represent a useful way to achieve the partitioning of programs to add readability, manageability, and overall structure to a program. This is not all that functions allow us to achieve, for they also save the programmer from useless repetition of program code that is used often and in various places in a program. Finally, they allow for an elegant and efficient way to include mathematical functions in computer programs.
- Type
- Chapter
- Information
- Fundamentals of Engineering Programming with C and Fortran , pp. 106 - 135Publisher: Cambridge University PressPrint publication year: 1998