C Is a Structured Language

Chapter C Is a Structured Language

C++ Complete Reference Book 3rd Edition
Pages 1041
Views 18,203
Downloads : 20 times
PDF Size : 10.8 MiB

Summary of Contents

C++ Complete Reference Book 3rd Edition

  • C is special in that it allows the direct manipulation of bits, bytes, words, andpointers. This makes it well suited for system-level programming, where theseoperations are common.Another important aspect of C is that it has only 32 keywords (27 from theKernighan and Ritchie de facto standard, and five added by the ANSI standardizationcommittee), which are the commands that make up the C language. High-levellanguages typically have several times more keywords. As a comparison, considerthat most versions of BASIC have well over 100 keywords!C Is a Structured LanguageIn your previous programming experience, you may have heard the term block-structured applied to a computer language. Although the term block-structuredlanguage does not strictly apply to C, C is commonly referred to simply as astructured language. It has many similarities to other structured languages, suchas ALGOL, Pascal, and Modula-2.The reason that C (and C++) is not, technically, a block-structured language is thatblock-structured languages permit procedures or functions to be declared insideother procedures or functions. Since C does not allow the creation of functionswithin functions, it cannot formally be called block-structured.The distinguishing feature of a structured language is compartmentalization of codeand data. This is the ability of a language to section off and hide from the rest of theprogram all information and instructions necessary to perform a specific task. Oneway that you achieve compartmentalization is by using subroutines that employ local(temporary) variables. By using local variables, you can write subroutines so that theevents that occur within them cause no side effects in other parts of the program. Thiscapability makes it very easy for programs to share sections of code. If you developcompartmentalized functions, you only need to know what a function does, not how itdoes it. Remember, excessive use of global variables (variables known throughout theentire program) may allow bugs to creep into a program by allowing unwanted sideeffects. (Anyone who has programmed in standard BASIC is well aware of thisproblem.)The concept of compartmentalization is greatly expanded by C++. Specifically, inC++, one part of your program may tightly control which other parts of yourprogram are allowed access.A structured language allows you a variety of programming possibilities. Itdirectly supports several loop constructs, such as while, do-while, and for.Inastructured language, the use of gotois either prohibited or discouraged and is not thecommon form of program control (as is the case in standard BASIC and traditional6C++: The Complete ReferenceNoteNotewww.freepdf-books.com