Appendix G C/C++ Notes. C/C++ Coding Style Guidelines Ray Mitchell 475
|
|
- Harold Foster
- 6 years ago
- Views:
Transcription
1 C/C++ Notes C/C++ Coding Style Guidelines -0 Ray Mitchell
2 C/C++ Notes NOTE G. C/C++ Coding Style Guidelines. Introduction The C and C++ languages are free form, placing no significance on the column or line where a token is located. This means that in the extreme a program could be written either all on one line with token separators only where required, or with each token on a separate line with blank lines in between. Such variations in programming style can be compared to accents in a spoken language. As an accent gets stronger the meaning of the conversation becomes less understandable, eventually becoming gibberish. This document illustrates some of the most commonly accepted conventions used in writing C/C++ programs, providing the consistent guidelines needed to write accentless code.. Implementation Files and Header Files Implementation files typically have a.c or.cpp extension and will minimally contain any needed non-inline function definitions and external variable definitions, although they often also contain many of same types of things contained in header files. Header files typically have a.h or no extension and are included in other files via a #include directive. They typically contain items like macro definitions, inline function definitions, function prototypes, external variable referencing declarations, templates, typedefs, and type definitions for classes, structures, unions, and enumerations. They also contain #include directives when necessary to support other items in the file. Header files must never contain function definitions, external variable definitions, using directives or statements, or run time code that is not part of a macro or an inline function. In applications where multiple implementation files include many of the same header files it is sometimes acceptable to place all of these #include directives in a single header file and include it instead. Standard header files are typically supplied with the compiler, while rd-party library vendors provide custom header files to support their products. In addition, programmers are always free to create their own custom header files to meet their needs. Header files must always be logically organized, includable in any order, and each must implement an Include Guard to prevent the multiple inclusion of its contents in another file, even if the header is included multiple times.. File Organization The suggested order for some common file items is as follows, with a blank line placed between each group. The most important consideration is that a something that relies on something be placed after it. Except for item, which is always required, not all files will contain all of these while some files may contain items not shown:. A block comment containing information about the contents and functionality of the file, the developer, the revision history, and anything that might be helpful in understanding and maintaining it;. #include directives;. using statements/directives (C++);. #define directives (C);. typedefs and custom data type definitions;. const variable declarations (C++);. External variable declarations;. Function prototypes;. Function definitions in some meaningful order, with a block comment before each describing its syntax and purpose. -0 Ray Mitchell
3 C/C++ Notes Appendix G NOTE G.. Comments Comments should be used wherever there might be a question about the workings or purpose of an algorithm, statement, macro definition, or anything that would not be obvious to a programmer unfamiliar with the code. It should never be necessary to reverse-engineer a program. Comments should explain algorithmic operations, not semantics. For example, an appropriate comment for the statement distance = rate * time; might be position of projectile, while something like multiply rate by time and assign to distance says nothing useful. With a wise choice of identifiers code can often be made somewhat self-documenting, thereby reducing the need for as many comments. The format of a comment is normally determined by its length. Comments occupying more than one line, such as a file title block or algorithm description, should be in block comment form. Except for partial-line comments, comments should be placed prior to and aligned with the code they comment as follows. Depending upon the compiler, C++ style comments could cause compatibility issues in C/C0 code. A C style block comment (also acceptable in C++): /* * Use a block comment whenever comments that occupy more than one line are needed. Note * the opening / is aligned with the code being commented, all asterisks are aligned with each * other, and that all comment text is left aligned. */ for (nextvalue = getchar(); nextvalue!= EOF; nextvalue = getchar()) An equivalent C++ style block comment (also acceptable in C since C): // // Use a block comment whenever comments that occupy more than one line are needed. Note // the opening / is aligned with the code being commented, all // are aligned with each other, and // that all comment text is left aligned. // for (nextvalue = getchar(); nextvalue!= EOF; nextvalue = getchar()) C and C++ style full-line comments: /* This is a full-line C style comment. */ // This is a full-line C++ style comment. for (nextvalue = getchar(); nextvalue!= EOF; nextvalue = getchar()) It is possible to over comment a program to the point of making it unreadable. This is especially true when code lines and comment lines are intermixed. Many comments can be reduced to the point of being small enough to fit to the right of the code being commented while still conveying meaning. To be most readable code should reside on the left side of a page with comments on the right, opposite the code they comment. Whenever possible all such comments should start in the same column as each other, as far to the right as possible. Deciding on the appropriate column is a compromise and there will usually be exceptions in any given program. Using tabs instead of spaces when positioning such comments reduces the effect of making minor code changes but may not be interpreted correctly by the printer. The following illustrates these partial-line comments: while ((nextvalue = getchar())!= EOF) /* while source file has characters */ if (nextvalue == '.') /* got sentence terminator */ break; /* don't read any more characters */ // must continue reading sentence ++charcount; // update characters read in sentence -0 Ray Mitchell
4 C/C++ Notes NOTE G. The following examples use exactly the same code but with the comments (if any) placed differently. Which programmer would you hire or be most willing to maintain code for? WRONG NO COMMENTS while ((nextvalue = getchar())!= EOF) if (nextvalue == '.') break; ++charcount; WRONG CLUTTERED & HARD TO READ while ((nextvalue = getchar())!= EOF)/* while source file has characters */ if (nextvalue == '.')/* got sentence terminator */ break; /* don't read any more characters */ /* must continue reading sentence */ ++charcount; /* update characters read in sentence */ CORRECT FULL LINE COMMENTS /* while source file has characters */ while ((nextvalue = getchar())!= EOF) /* got sentence terminator */ if (nextvalue == '.') /* don't read any more characters */ break; /* must continue reading sentence */ /* update characters read in sentence */ ++charcount; CORRECT PARTIAL LINE COMMENTS while ((nextvalue = getchar())!= EOF) /* while source file has characters */ if (nextvalue == '.') /* got sentence terminator */ break; /* don't read any more characters */ /* must continue reading sentence */ ++charcount; /* update characters read in sentence */ -0 Ray Mitchell
5 C/C++ Notes Appendix G NOTE G.. Literals A magic number is defined as any literal (numeric, character, or string) embedded in a program s code or comments. They usually make programs cryptic and difficult to maintain because their meaning is not obvious and, if they must be changed, the likelihood of missing one or changing the wrong one is high. There are a few cases, however, where magic numbers are acceptable, including: 0 & as array indices or loop start/end values, as an increment/decrement value, as way to double/halve a value or as a divisor to check for odd/even, coefficients in some mathematical formulae, some informational strings, cases dictated by common sense. In general, however, the #define directive (in C), const-qualified variables (in C++), or enumerated data (C and C++) should be used to associate meaningful names with literals. This permits values to be changed everywhere in a program by making a change in only one place. Avoid, however, the pitfall of choosing names that reflect the value they represent, such as #define SIX. This is as bad as directly coding itself. Would you ever define SIX to be anything other than? Because an implementation may define the macro NULL as a pointer type, it must never be used in other than pointer contexts.. Naming Conventions. Choose meaningful names that reflect usage whenever possible and practical.. Function & function-like macro names should be verbs or ask questions; all other names should be nouns or state facts.. To avoid conflicts with internal names, leading or trailing underscores should be avoided in application programs.. Object-like macro, const-qualified variable, and typedef names should be in upper case.. Function, function-like macro, and class/struct/union/enum tag names should be in Pascal case (i.e., PascalCaseName).. All other names should be in camel case, (i.e., camelcasename).. Compound Statements (Block Statements) A compound (block) statement is defined as zero or more statements enclosed in curly braces. Although initializer lists are also enclosed in braces they are not compound statements. Compound statements are a required part of function, structure, class, union, and enumeration definitions as well as switch statements, but they are optional with if,, for, while, and do statements unless more than one statement is to be associated with those statements. Here are some examples: Optional Compound Statement Not Used Optional Compound Statement Is Used Compound Statement Required for (...) for (...) for (...) velocity = ; acceleration = ; velocity = ; velocity = ; height = ; acceleration = ; acceleration = ; -0 Ray Mitchell
6 C/C++ Notes NOTE G.. Placement of Braces A point of contention among some C/C++ programmers is the placement of the braces used for compound statements and initializer lists. The two most popular formats are shown on the left and right below and are known as the brace under and brace after (K&R) styles, respectively. Choose one and use it exclusively and consistently. Do not intermix the two or use a different variation. The braces are sometimes omitted if only one statement is needed with if,, for, while, or do: int SomeFunction(void) int SomeFunction (void) (Both forms are the same!) declarations/statements declarations/statements if (...) if (...) declarations/statements declarations/statements if (...) declarations/statements if (...) declarations/statements declarations/statements declarations/statements for or while (...) for or while (...) declarations/statements declarations/statements do do declarations/statements declarations/statements while (...); while(...); switch (...) switch (...) declarations declarations case... : case... : statements statements break; break; struct or class or union or enum tag struct or class or union or enum tag declarations declarations ; ; double factors[] = double factors[] = initializer, initializer,... initializer, initializer,... ; ; 0-0 Ray Mitchell
7 C/C++ Notes Appendix G NOTE G. struct/class/union/enum type definitions and initialized variable declarations may be placed entirely on the same line if they will fit, but this is not appropriate for any of the other constructs: struct or class or union or enum tag declaration, declaration, ; double factors[] = initializer, initializer,... ;. Indenting Indenting is used strictly to enhance a program s human readability and is totally ignored by the compiler. An indent signifies the association of one or more statements with a previous, less indented construct, as in the following examples: if (...) for (...) int main(void) while (..) x = ; int ch = 'A'; printf(...); x = ; ++d; putchar(ch); if (...) return EXIT_SUCCESS; z = y; do y = ; int t = ; x = y + ; while (...); ++v; The rules for how and when to indent are simple:. Braces must be aligned according to the placement formats previously discussed.. All declarations and other statements associated with a construct must be indented equally from the left edge of that construct.. The width used for all indents must be consistent throughout any program. One final consideration is the width of each indent. A default tab stop is spaces wide on some systems, but this is too wide for most programs because the code ends up going off the right edge of the screen/paper or wrapping around. Because of this an indent width of or spaces (or at least / inch) is recommended instead. Widths smaller than this tend to be hard to discern while larger values run out of room more quickly. Actual spaces should be used instead of hard tab characters because the system printer often has no way of knowing the editor's tab setting. Thus, it often assumes that it is and produces a program listing whose indenting does not match that seen within the editor itself.. Multiple Statements on One Line Do not put more than one statement on a line. Similarly, put the body of an if,, for, while, do, or case on the next line. Chained assignments such as x = y = z = 0; are permissible as long as all operands are logically related. Multiple variables of the same type may be declared on the same line, comma separated, unless a comment is required. The following examples illustrate some acceptable and non-acceptable formats: -0 Ray Mitchell
8 C/C++ Notes NOTE G. Do Don't x = ; x = ; y = printf(...); Delete(); y = printf(...); Delete(); for (idx = 0; idx < MAX; ++idx) for (idx = 0; idx < MAX; ++idx) printf("%d", idx); printf("%d", idx); if (y < x) if (y < x) printf("%d\n", x); printf("%d\n", x); printf("%d\n", y); printf("%d\n", y); case 'A': case 'A': putchar('a'); break; (See below) putchar('a'); break; A common exception is where multiple switch cases are almost identical. Readability may actually be enhanced by grouping them as: case 'A': putchar('a'); break; case 'B': putchar('b'); break; case 'C': putchar('c'); break; case 'D': putchar('d'); break;. The if Convention If an if follows an, separated by only whitespace, the if should be placed on the line with the, thereby forming the standard C/C++ if construct. Do Don't if (a > b) if (a > b) ++a; ++a; if (a < x) ++b; if (a < x) ++b;. Functions Each function definition should be preceded by a block comment that describes its syntax and what it does. A function's return type must always be specified and never defaulted to type int by omitting it. Functions not returning a value must use the keyword void. Placing a return type on its own line in column is common. C functions with no parameters must use void as the parameter list. Although C++ functions with no parameters may also use void for this purpose, it is more common to leave their parameter lists empty. Either the definition of a function or its prototype must visible to the caller before the function is called. Explicitly declaring a function as external by using the keyword extern is obsolete. Prototypes for user functions needed by more than one file and all library functions, such as those in the standard library, must be kept in header files that are included by any files needing them. Do not duplicate the prototype in each file. In multi-file programs all functions not shared with other files should be declared static to limit their scope. -0 Ray Mitchell
9 C/C++ Notes Appendix G NOTE G.. External Variables Referencing declarations of external variables used by more than one file must be kept in header files that are included by any files needing them. Do not by duplicate the declaration in each file. In multi-file programs, all external variables (except const-qualified external variables in C++) not shared with other files should be declared static to limit their scope.. Automatic Variables Automatic variables should be declared as close to the point of use as is practical and, if initialization is required, also initialized as close to the point of use as is practical. A program that initializes automatic variables when declared but doesn't use them until much later is difficult to read. The use of extremely large automatic aggregate objects (i.e., arrays, structures, classes) can cause compiler/run-time problems due to the amount of stack space required, and initializing such objects can add significant run time overhead. For similar reasons functions should avoid the arbitrary passing/returning of aggregates. Instead, pass/return pointers or references to them. Making local objects static can sometimes solve stack size issues but can also result in more overall memory usage and can prevent the implementation of multi-threaded applications.. Operators All ternary and binary operators except class/structure/union member operators should be separated from their operands by spaces. Some judgment is called for in the case of complex expressions, which may be clearer if the inner operators are not surrounded by spaces and the outer ones are, for example: if (x=y && <t ++p) Spaces should be placed after, but not before, all commas and semicolons. They should also be placed after keywords that are followed by expressions in parentheses, with the exception of sizeof and return. On the other hand, macros with arguments must not and function calls should not have a space between the name and the left parenthesis. Unary operators should not be separated from their single operand. Compound assignments and pre/post increment/decrement expressions should always be used instead of their equivalent longer forms. The shorter expressions are evaluated as is and are not expanded to the longer forms. Parentheses around the entire right side of such expressions are not needed, as the following illustrates: Do Don't x += x = x + x++ or ++x x = x + or x += x >>= x = x >> x /= + y x = x / ( + y) or x /= ( + y) -0 Ray Mitchell
10 C/C++ Notes NOTE G.. Portability Beware of making assumptions about:. The number of bits in a data type;. Byte ordering (big endian vs. little endian);. Bit-field ordering (left-to-right vs. right-to-left);. The size of different pointer types;. The compatibility of pointers with arithmetic types;. The internal representation of negative integer numbers;. The internal representation of floating point numbers;. The operation of a right shift on negative integer numbers (arithmetic vs. logical);. The padding of structures/classes/unions;. The machine's character set (ASCII, EBCDIC, etc.);. The evaluation of expressions having side effects when used as macro arguments;. The order of evaluation of expressions not involving sequence point operators, including expressions used as function arguments. -0 Ray Mitchell
UNIT- 3 Introduction to C++
UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage
More informationReview of the C Programming Language for Principles of Operating Systems
Review of the C Programming Language for Principles of Operating Systems Prof. James L. Frankel Harvard University Version of 7:26 PM 4-Sep-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights
More informationReview of the C Programming Language
Review of the C Programming Language Prof. James L. Frankel Harvard University Version of 11:55 AM 22-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Reference Manual for the
More informationCSCI 171 Chapter Outlines
Contents CSCI 171 Chapter 1 Overview... 2 CSCI 171 Chapter 2 Programming Components... 3 CSCI 171 Chapter 3 (Sections 1 4) Selection Structures... 5 CSCI 171 Chapter 3 (Sections 5 & 6) Iteration Structures
More informationFeatures of C. Portable Procedural / Modular Structured Language Statically typed Middle level language
1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC
More informationRule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead.
Chapter 9: Rules Chapter 1:Style and Program Organization Rule 1-1: Organize programs for readability, just as you would expect an author to organize a book. Rule 1-2: Divide each module up into a public
More informationComputers Programming Course 5. Iulian Năstac
Computers Programming Course 5 Iulian Năstac Recap from previous course Classification of the programming languages High level (Ada, Pascal, Fortran, etc.) programming languages with strong abstraction
More informationINTRODUCTION 1 AND REVIEW
INTRODUTION 1 AND REVIEW hapter SYS-ED/ OMPUTER EDUATION TEHNIQUES, IN. Programming: Advanced Objectives You will learn: Program structure. Program statements. Datatypes. Pointers. Arrays. Structures.
More informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering
More informationCS201 - Introduction to Programming Glossary By
CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with
More informationShort Notes of CS201
#includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system
More informationLESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:
LESSON 1 FUNDAMENTALS OF C The purpose of this lesson is to explain the fundamental elements of the C programming language. C like other languages has all alphabet and rules for putting together words
More informationUNIT-2 Introduction to C++
UNIT-2 Introduction to C++ C++ CHARACTER SET Character set is asset of valid characters that a language can recognize. A character can represents any letter, digit, or any other sign. Following are some
More informationFull file at
Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class
More informationC Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites:
C Programming Code: MBD101 Duration: 10 Hours Prerequisites: You are a computer science Professional/ graduate student You can execute Linux/UNIX commands You know how to use a text-editing tool You should
More informationFundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University
Fundamental Data Types CSE 130: Introduction to Programming in C Stony Brook University Program Organization in C The C System C consists of several parts: The C language The preprocessor The compiler
More informationAPPENDIX A : Example Standard <--Prev page Next page -->
APPENDIX A : Example Standard If you have no time to define your own standards, then this appendix offers you a pre-cooked set. They are deliberately brief, firstly because standards
More informationUEE1302 (1102) F10: Introduction to Computers and Programming
Computational Intelligence on Automation Lab @ NCTU Learning Objectives UEE1302 (1102) F10: Introduction to Computers and Programming Programming Lecture 00 Programming by Example Introduction to C++ Origins,
More informationAbout Codefrux While the current trends around the world are based on the internet, mobile and its applications, we try to make the most out of it. As for us, we are a well established IT professionals
More information>B<82. 2Soft ware. C Language manual. Copyright COSMIC Software 1999, 2001 All rights reserved.
>B
More informationFundamentals of Programming. Lecture 12: C Structures, Unions, Bit Manipulations and Enumerations
Fundamentals of Programming Lecture 12: C Structures, Unions, Bit Manipulations and Enumerations Instructor: Fatemeh Zamani f_zamani@ce.sharif.edu Sharif University of Technology Computer Engineering Department
More informationA Fast Review of C Essentials Part I
A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types
More informationMakefiles Makefiles should begin with a comment section of the following form and with the following information filled in:
CS 215 Fundamentals of Programming II C++ Programming Style Guideline Most of a programmer's efforts are aimed at the development of correct and efficient programs. But the readability of programs is also
More informationObjectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program
Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates
More informationChapter 2: Basic Elements of C++
Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates
More informationChapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction
Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers
More informationObjectives. In this chapter, you will:
Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about
More informationC++ Style Guide. 1.0 General. 2.0 Visual Layout. 3.0 Indentation and Whitespace
C++ Style Guide 1.0 General The purpose of the style guide is not to restrict your programming, but rather to establish a consistent format for your programs. This will help you debug and maintain your
More information6.096 Introduction to C++ January (IAP) 2009
MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture
More informationEL6483: Brief Overview of C Programming Language
EL6483: Brief Overview of C Programming Language EL6483 Spring 2016 EL6483 EL6483: Brief Overview of C Programming Language Spring 2016 1 / 30 Preprocessor macros, Syntax for comments Macro definitions
More informationAppendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.
A Appendix Grammar There is no worse danger for a teacher than to teach words instead of things. Marc Block Introduction keywords lexical conventions programs expressions statements declarations declarators
More informationXC Specification. 1 Lexical Conventions. 1.1 Tokens. The specification given in this document describes version 1.0 of XC.
XC Specification IN THIS DOCUMENT Lexical Conventions Syntax Notation Meaning of Identifiers Objects and Lvalues Conversions Expressions Declarations Statements External Declarations Scope and Linkage
More informationFundamentals of Programming
Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables
More informationIECD Institute for Entrepreneurship and Career Development Bharathidasan University, Tiruchirappalli 23.
Subject code - CCP01 Chapt Chapter 1 INTRODUCTION TO C 1. A group of software developed for certain purpose are referred as ---- a. Program b. Variable c. Software d. Data 2. Software is classified into
More informationFlow Control. CSC215 Lecture
Flow Control CSC215 Lecture Outline Blocks and compound statements Conditional statements if - statement if-else - statement switch - statement? : opertator Nested conditional statements Repetitive statements
More informationChapter 2 Basic Elements of C++
C++ Programming: From Problem Analysis to Program Design, Fifth Edition 2-1 Chapter 2 Basic Elements of C++ At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion
More informationIMPORTANT QUESTIONS IN C FOR THE INTERVIEW
IMPORTANT QUESTIONS IN C FOR THE INTERVIEW 1. What is a header file? Header file is a simple text file which contains prototypes of all in-built functions, predefined variables and symbolic constants.
More informationC OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure
C Overview Basic C Program Structure C OVERVIEW BASIC C PROGRAM STRUCTURE Goals The function main( )is found in every C program and is where every C program begins speed execution portability C uses braces
More informationThe New C Standard (Excerpted material)
The New C Standard (Excerpted material) An Economic and Cultural Derek M. Jones derek@knosof.co.uk Copyright 2002-2008 Derek M. Jones. All rights reserved. 1456 6.7.2.3 Tags 6.7.2.3 Tags type contents
More informationProgramming in C++ 4. The lexical basis of C++
Programming in C++ 4. The lexical basis of C++! Characters and tokens! Permissible characters! Comments & white spaces! Identifiers! Keywords! Constants! Operators! Summary 1 Characters and tokens A C++
More informationCS Programming In C
CS 24000 - Programming In C Week Two: Basic C Program Organization and Data Types Zhiyuan Li Department of Computer Science Purdue University, USA 2 int main() { } return 0; The Simplest C Program C programs
More informationC Formatting Guidelines
UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING CMPE13/L: INTRODUCTION TO C PROGRAMMING SPRING 2012 C Formatting Guidelines Lines & Spacing 1. 100 character lines (tabs count
More informationBinghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program
Syntax What the Compiler needs to understand your program 1 Pre-Processing Any line that starts with # is a pre-processor directive Pre-processor consumes that entire line Possibly replacing it with other
More informationChapter 2: Introduction to C++
Chapter 2: Introduction to C++ Copyright 2010 Pearson Education, Inc. Copyright Publishing as 2010 Pearson Pearson Addison-Wesley Education, Inc. Publishing as Pearson Addison-Wesley 2.1 Parts of a C++
More informationC Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee
C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,
More informationChapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen
Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Copyright 2009 Publishing Pearson as Pearson Education, Addison-Wesley Inc. Publishing as Pearson Addison-Wesley
More informationUNIT - I. Introduction to C Programming. BY A. Vijay Bharath
UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been
More informationEDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION
EDIABAS Electronic Diagnostic Basic System BEST/2 LANGUAGE DESCRIPTION VERSION 6b Copyright BMW AG, created by Softing AG BEST2SPC.DOC CONTENTS CONTENTS...2 1. INTRODUCTION TO BEST/2...5 2. TEXT CONVENTIONS...6
More informationSyntax and Variables
Syntax and Variables What the Compiler needs to understand your program, and managing data 1 Pre-Processing Any line that starts with # is a pre-processor directive Pre-processor consumes that entire line
More informationTokens, Expressions and Control Structures
3 Tokens, Expressions and Control Structures Tokens Keywords Identifiers Data types User-defined types Derived types Symbolic constants Declaration of variables Initialization Reference variables Type
More informationPace University. Fundamental Concepts of CS121 1
Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction
More informationTypescript on LLVM Language Reference Manual
Typescript on LLVM Language Reference Manual Ratheet Pandya UNI: rp2707 COMS 4115 H01 (CVN) 1. Introduction 2. Lexical Conventions 2.1 Tokens 2.2 Comments 2.3 Identifiers 2.4 Reserved Keywords 2.5 String
More informationC Language Programming
Experiment 2 C Language Programming During the infancy years of microprocessor based systems, programs were developed using assemblers and fused into the EPROMs. There used to be no mechanism to find what
More informationControl Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003
Control Flow COMS W1007 Introduction to Computer Science Christopher Conway 3 June 2003 Overflow from Last Time: Why Types? Assembly code is typeless. You can take any 32 bits in memory, say this is an
More informationPart I Part 1 Expressions
Writing Program in C Expressions and Control Structures (Selection Statements and Loops) Jan Faigl Department of Computer Science Faculty of Electrical Engineering Czech Technical University in Prague
More informationThe C++ Language. Arizona State University 1
The C++ Language CSE100 Principles of Programming with C++ (based off Chapter 2 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University
More informationCharacter Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Uppercase Alphabets Lowercase Alphabets Character Set A, B, C, Y, Z a, b, c, y, z Digits
More informationB.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University
Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are
More information2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program
Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Parts of a C++ Program Parts of a C++ Program // sample C++ program
More information9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C
Overview The C Programming Language (with material from Dr. Bin Ren, William & Mary Computer Science) Motivation Hello, world! Basic Data Types Variables Arithmetic Operators Relational Operators Assignments
More informationC OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed
C Overview C OVERVIEW Goals speed portability allow access to features of the architecture speed C fast executables allows high-level structure without losing access to machine features many popular languages
More informationInformation Science 1
Information Science 1 Simple Calcula,ons Week 09 College of Information Science and Engineering Ritsumeikan University Topics covered l Terms and concepts from Week 8 l Simple calculations Documenting
More informationComputer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary
GATE- 2016-17 Postal Correspondence 1 C-Programming Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key concepts, Analysis
More informationLECTURE 02 INTRODUCTION TO C++
PowerPoint Slides adapted from *Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* Copyright 2012 Pearson Education Inc. COMPUTER PROGRAMMING LECTURE 02 INTRODUCTION
More informationThe C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)
The C Programming Language (with material from Dr. Bin Ren, William & Mary Computer Science) 1 Overview Motivation Hello, world! Basic Data Types Variables Arithmetic Operators Relational Operators Assignments
More informationProcedures, Parameters, Values and Variables. Steven R. Bagley
Procedures, Parameters, Values and Variables Steven R. Bagley Recap A Program is a sequence of statements (instructions) Statements executed one-by-one in order Unless it is changed by the programmer e.g.
More informationEE 382 Style Guide. March 2, 2018
EE 382 Style Guide March 2, 2018 This is a short document describing the coding style for this class. All code written in this class is assumed to follow this coding style. 1 Indentation Indentations should
More informationChapter 1 INTRODUCTION. SYS-ED/ Computer Education Techniques, Inc.
Chapter 1 INTRODUCTION SYS-ED/ Computer Education Techniques, Inc. Objectives You will learn: Facilities and features of PL/1. Structure of programs written in PL/1. Data types. Storage classes, control,
More informationBinghamton University. CS-120 Summer Introduction to C. Text: Introduction to Computer Systems : Chapters 11, 12, 14, 13
Introduction to C Text: Introduction to Computer Systems : Chapters 11, 12, 14, 13 Problem: Too Many Details For example: Lab 7 Bubble Sort Needed to keep track of too many details! Outer Loop When do
More informationWriting Program in C Expressions and Control Structures (Selection Statements and Loops)
Writing Program in C Expressions and Control Structures (Selection Statements and Loops) Jan Faigl Department of Computer Science Faculty of Electrical Engineering Czech Technical University in Prague
More informationC Fundamentals & Formatted Input/Output. adopted from KNK C Programming : A Modern Approach
C Fundamentals & Formatted Input/Output adopted from KNK C Programming : A Modern Approach C Fundamentals 2 Program: Printing a Pun The file name doesn t matter, but the.c extension is often required.
More informationQUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:
QUIZ 1. Explain the meaning of the angle brackets in the declaration of v below: This is a template, used for generic programming! QUIZ 2. Why is the vector class called a container? 3. Explain how the
More informationCOP 3275: Chapter 02. Jonathan C.L. Liu, Ph.D. CISE Department University of Florida, USA
COP 3275: Chapter 02 Jonathan C.L. Liu, Ph.D. CISE Department University of Florida, USA Program: Printing a Pun #include int main(void) { printf("to C, or not to C: that is the question.\n");
More informationCreating a C++ Program
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer. 1 Creating a C++ Program created using an
More informationFull file at C How to Program, 6/e Multiple Choice Test Bank
2.1 Introduction 2.2 A Simple Program: Printing a Line of Text 2.1 Lines beginning with let the computer know that the rest of the line is a comment. (a) /* (b) ** (c) REM (d)
More informationUnit 3. Operators. School of Science and Technology INTRODUCTION
INTRODUCTION Operators Unit 3 In the previous units (unit 1 and 2) you have learned about the basics of computer programming, different data types, constants, keywords and basic structure of a C program.
More informationc) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.
2.1 Introduction (No questions.) 2.2 A Simple Program: Printing a Line of Text 2.1 Which of the following must every C program have? (a) main (b) #include (c) /* (d) 2.2 Every statement in C
More informationQUIZ: What value is stored in a after this
QUIZ: What value is stored in a after this statement is executed? Why? a = 23/7; QUIZ evaluates to 16. Lesson 4 Statements, Expressions, Operators Statement = complete instruction that directs the computer
More informationThe New C Standard (Excerpted material)
The New C Standard (Excerpted material) An Economic and Cultural Derek M. Jones derek@knosof.co.uk Copyright 2002-2008 Derek M. Jones. All rights reserved. 1378 type specifier type-specifier: void char
More informationCSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018
CSE 1001 Fundamentals of Software Development 1 Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018 Identifiers, Variables and Data Types Reserved Words Identifiers in C Variables and Values
More informationC++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.
EEE-117 COMPUTER PROGRAMMING Basic Elements of C++ Objectives General Questions Become familiar with the basic components of a C++ program functions, special symbols, and identifiers Data types Arithmetic
More informationThe Design Process. General Development Issues. C/C++ and OO Rules of Thumb. Home
A l l e n I. H o l u b & A s s o c i a t e s Home C/C++ and OO Rules of Thumb The following list is essentially the table of contents for my book Enough Rope to Shoot Yourself in the Foot (McGraw-Hill,
More informationProgramming and Data Structures
Programming and Data Structures Teacher: Sudeshna Sarkar sudeshna@cse.iitkgp.ernet.in Department of Computer Science and Engineering Indian Institute of Technology Kharagpur #include int main()
More informationContents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual
Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual Contents 1 Introduction...2 2 Lexical Conventions...2 3 Types...3 4 Syntax...3 5 Expressions...4 6 Declarations...8 7 Statements...9
More informationA complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.
1.3a Expressions Expressions An Expression is a sequence of operands and operators that reduces to a single value. An operator is a syntactical token that requires an action be taken An operand is an object
More informationHigh Performance Computing in C and C++
High Performance Computing in C and C++ Rita Borgo Computer Science Department, Swansea University Summary Introduction to C Writing a simple C program Compiling a simple C program Running a simple C program
More informationVariables and Operators 2/20/01 Lecture #
Variables and Operators 2/20/01 Lecture #6 16.070 Variables, their characteristics and their uses Operators, their characteristics and their uses Fesq, 2/20/01 1 16.070 Variables Variables enable you to
More informationP.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above
P.G.TRB - COMPUTER SCIENCE Total Marks : 50 Time : 30 Minutes 1. C was primarily developed as a a)systems programming language b) general purpose language c) data processing language d) none of the above
More informationChapter 3: Operators, Expressions and Type Conversion
101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To
More informationIntroduction to C++ Introduction. Structure of a C++ Program. Structure of a C++ Program. C++ widely-used general-purpose programming language
Introduction C++ widely-used general-purpose programming language procedural and object-oriented support strong support created by Bjarne Stroustrup starting in 1979 based on C Introduction to C++ also
More informationC Language, Token, Keywords, Constant, variable
C Language, Token, Keywords, Constant, variable A language written by Brian Kernighan and Dennis Ritchie. This was to be the language that UNIX was written in to become the first "portable" language. C
More informationBITG 1233: Introduction to C++
BITG 1233: Introduction to C++ 1 Learning Outcomes At the end of this lecture, you should be able to: Identify basic structure of C++ program (pg 3) Describe the concepts of : Character set. (pg 11) Token
More informationC Programming Language (Chapter 2 of K&R) Variables and Constants
C Programming Language (Chapter 2 of K&R) Types, Operators and Expressions Variables and Constants Basic objects manipulated by programs Declare before use: type var1, var2, int x, y, _X, x11, buffer;
More informationFormatting & Style Examples
Formatting & Style Examples The code in the box on the right side is a program that shows an example of the desired formatting that is expected in this class. The boxes on the left side show variations
More informationVariables Data types Variable I/O. C introduction. Variables. Variables 1 / 14
C introduction Variables Variables 1 / 14 Contents Variables Data types Variable I/O Variables 2 / 14 Usage Declaration: t y p e i d e n t i f i e r ; Assignment: i d e n t i f i e r = v a l u e ; Definition
More informationCSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York
CSc 10200! Introduction to Computing Lecture 2-3 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 2 Problem Solving Using C++ 2 Objectives In this
More informationDeclaration Syntax. Declarations. Declarators. Declaration Specifiers. Declaration Examples. Declaration Examples. Declarators include:
Declarations Based on slides from K. N. King Declaration Syntax General form of a declaration: declaration-specifiers declarators ; Declaration specifiers describe the properties of the variables or functions
More informationOperators. Java operators are classified into three categories:
Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.
More informationfrom Appendix B: Some C Essentials
from Appendix B: Some C Essentials tw rev. 22.9.16 If you use or reference these slides or the associated textbook, please cite the original authors work as follows: Toulson, R. & Wilmshurst, T. (2016).
More informationARG! Language Reference Manual
ARG! Language Reference Manual Ryan Eagan, Mike Goldin, River Keefer, Shivangi Saxena 1. Introduction ARG is a language to be used to make programming a less frustrating experience. It is similar to C
More information