APPENDIX A : KEYWORDS... 2 APPENDIX B : OPERATORS... 3 APPENDIX C : OPERATOR PRECEDENCE... 4 APPENDIX D : ESCAPE SEQUENCES... 5

Similar documents
APPENDICES. Introduction to C Programming Page: A-1 Copyright 2017 by James J. Polzin All Rights Reserved Printed: 1/24/18

Basic Types, Variables, Literals, Constants

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

Introduction to Programming

Variables. Data Types.

ME240 Computation for Mechanical Engineering. Lecture 4. C++ Data Types

Tokens, Expressions and Control Structures

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

6.096 Introduction to C++ January (IAP) 2009

Introduction to C++ Systems Programming

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.

The following are the data types used in the C programming language:

Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts

EEE145 Computer Programming

Non-numeric types, boolean types, arithmetic. operators. Comp Sci 1570 Introduction to C++ Non-numeric types. const. Reserved words.

IS 0020 Program Design and Software Tools

Chapter 15 - C++ As A "Better C"

CPS 104 Computer Organization and Programming Lecture-2 : Data representations,

Programming in C++ 4. The lexical basis of C++

Unit 3, Lesson 2 Data Types, Arithmetic,Variables, Input, Constants, & Library Functions. Mr. Dave Clausen La Cañada High School

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers

Chapter 2 - Control Structures

Data Representation and Binary Arithmetic. Lecture 2

Midterm CSE 131 Fall 2014

Appendix A Developing a C Program on the UNIX system

Basics of C++ // my first program in C++ Hello World! #include <iostream> using namespace std; int main () { cout << "Hello World!

Chapter 3. Information Representation

Assignment Operations

ASSIGNMENT 5 TIPS AND TRICKS

Chapter 8. Characters and Strings

Midterm CSE 131 Winter 2015

Chapter 2 - Control Structures

LEXICAL 2 CONVENTIONS

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

EXPERIMENT 7: Introduction to Universal Serial Asynchronous Receive Transmit (USART)

Chapter 2 - Control Structures

Compiler Construction. Lecture 10

Midterm CSE 131 Winter 2012

Final CSE 131 Winter 2012

EXPERIMENT 8: Introduction to Universal Serial Asynchronous Receive Transmit (USART)

Do not start the test until instructed to do so!

CMSC 313 Lecture 03 Multiple-byte data big-endian vs little-endian sign extension Multiplication and division Floating point formats Character Codes

Do not start the test until instructed to do so!

This tutorial adopts a simple and practical approach to describe the concepts of C++.

o Echo the input directly to the output o Put all lower-case letters in upper case o Put the first letter of each word in upper case

Final CSE 131 Fall 2014

Fundamentals of Programming (C)

Chapter 2 Bits, Data Types, and Operations

Number Representations

Midterm CSE 131 Winter 2014

Midterm CSE 131 Winter 2013

1.1. INTRODUCTION 1.2. NUMBER SYSTEMS

Programming with C++ Language

Week 1 / Lecture 2 8 March 2017 NWEN 241 C Fundamentals. Alvin Valera. School of Engineering and Computer Science Victoria University of Wellington

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

Chapter 2 Bits, Data Types, and Operations

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

CS 159 Credit Exam. What advice do you have for students who have previously programmed in another language like JAVA or C++?

Chapter 2 Bits, Data Types, and Operations

Bits and Bytes. Data Representation. A binary digit or bit has a value of either 0 or 1; these are the values we can store in hardware devices.

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Fundamentals of Programming

Exercises Software Development I. 03 Data Representation. Data types, range of values, internal format, literals. October 22nd, 2014

Final CSE 131 Winter 2010

Programming. C++ Basics

Lecture (09) x86 programming 8

CSE 30 Fall 2012 Final Exam

Practical C++ Programming

CS341 *** TURN OFF ALL CELLPHONES *** Practice NAME

Work relative to other classes

Variables and data types

Review of the C Programming Language for Principles of Operating Systems

Simple Data Types in C. Alan L. Cox

Connecting UniOP to Datalogic Barcode Readers

cs3157: c++ lecture #2 (mon-11-apr-2005) chronology of some programming languages... C++ vs Java identifiers.

Introduction to C# Applications

CS3157: Advanced Programming. Outline

1. Character/String Data, Expressions & Intrinsic Functions. Numeric Representation of Non-numeric Values. (CHARACTER Data Type), Part 1

In this session we will cover the following sub-topics: 1.Identifiers 2.Variables 3.Keywords 4.Statements 5.Comments 6.Whitespaces 7.Syntax 8.

C++ INDEX. Introduction: Instructions for use. Basics of C++: Structure of a program Variables. Data Types. Constants Operators Basic Input/Output

EP241 Computer Programming

Reminder. Sign up for ee209 mailing list. Precept. If you haven t received any from ee209 yet Follow the link from our class homepage

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Final CSE 131 Fall 2015

CS 376b Computer Vision

CSE 30 Fall 2013 Final Exam

PureScan - ML1. Configuration Guide. Wireless Linear Imager Wireless Laser scanner - 1 -

Fundamental Data Types

Numbers and Computers. Debdeep Mukhopadhyay Assistant Professor Dept of Computer Sc and Engg IIT Madras

CSE 30 Winter 2014 Final Exam

FUNCTIONS POINTERS. Pointers. Functions

Lecture 02 C FUNDAMENTALS

Chapter 2 Bits, Data Types, and Operations

Experiment 3. TITLE Optional: Write here the Title of your program.model SMALL This directive defines the memory model used in the program.

COMP322 - Introduction to C++ Lecture 02 - Basics of C++

EP578 Computing for Physicists

Transcription:

APPENDIX A : KEYWORDS... 2 APPENDIX B : OPERATORS... 3 APPENDIX C : OPERATOR PRECEDENCE... 4 APPENDIX D : ESCAPE SEQUENCES... 5 APPENDIX E : ASCII CHARACTER SET... 6 APPENDIX F : USING THE GCC COMPILER FOR C++... 7 APPENDIX G : RELATIONAL OPERATORS... 8 APPENDIX H : LOGICAL OPERATORS... 8 APPENDIX I : USING THE DEV C++ IDE... 9 APPENDIX J : USING OPENGL & GLUT... 16 APPENDIX K : SETTING THE SEARCH PATH... 20 APPENDIX L : USING COMMAND-LINE ARGUMENTS... 22 C++ for C Programmers Page: A-1 Copyright 2017 by James J. Polzin All Rights Reserved

APPENDIX A : KEYWORDS alignas continue friend register true alignof decltype goto reinterpret_cast try asm default if return typedef auto delete inline short typeid bool do int signed typename break double long sizeof union case dynamic_cast mutable static unsigned catch else namespace static_assert using char enum new static_cast virtual char_16t explicit noexcept struct void char_32t export nullptr switch volatile class extern operator template wchar_t const false private this while const_cast float protected thread_local constexpr for public throw C++ for C Programmers Page: A-2 Copyright 2017 by James J. Polzin All Rights Reserved

APPENDIX B : OPERATORS Arithmetic operators: multiplication/division/modulus addition/subtraction positive/negative sign (unary) increment/decrement (unary) Logical operators: AND OR NOT (unary) Relational operators: less than, less than or equal, greater than, greater than or equal equal to and not equal to Bit operators: left and right bit shift bitwise AND bitwise OR ^ bitwise exclusive or XOR bitwise NOT (unary) Assignment operators: ^ Address/Pointer operators: address of (unary) dereference (unary) Structure operators: structure member acccess member access thru a structure pointer. * member dereference ->* indirect member dereference Memory allocation operators: new, new[ ] allocation, allocation of array delete, delete[ ] de-allocation, de-allocation of array Other operators: scope resolution function call array access (type) type cast (unary) sizeof data object size in bytes (unary) conditional operator throw throw exception comma operator C++ for C Programmers Page: A-3 Copyright 2017 by James J. Polzin All Rights Reserved

APPENDIX C : OPERATOR PRECEDENCE Operators Associativity :: ( ) [ ] >. left to right {( ) function call}! ~ ++ + * & (type) sizeof new new[ ] delete delete[ ] right to left {All Unary}. * >* left to right * / % left to right + left to right << >> left to right < <= > >= left to right = =!= left to right & ^ left to right left to right left to right && left to right left to right?: right to left = += = *= /= %= &= ^= = <<= >>= right to left throw, left to right C++ for C Programmers Page: A-4 Copyright 2017 by James J. Polzin All Rights Reserved

APPENDIX D : ESCAPE SEQUENCES Escape value \n newline \t tab \f formfeed \a alarm \b backspace \r carriage return \v vertical tab \\ backslash \ Single quote \ double quote C++ for C Programmers Page: A-5 Copyright 2017 by James J. Polzin All Rights Reserved

APPENDIX E : ASCII CHARACTER SET 0 (nul) 16 (dle) 32 (sp) 48 0 64 @ 80 P 96 ` 112 p 1 (soh) 17 (dc1) 33! 49 1 65 A 81 Q 97 a 113 q 2 (stx) 18 (dc2) 34 " 50 2 66 B 82 R 98 b 114 r 3 (etx) 19 (dc3) 35 # 51 3 67 C 83 S 99 c 115 s 4 (eot) 20 (dc4) 36 $ 52 4 68 D 84 T 100 d 116 t 5 (enq) 21 (nak) 37 % 53 5 69 E 85 U 101 e 117 u 6 (ack) 22 (syn) 38 & 54 6 70 F 86 V 102 f 118 v 7 (bel) 23 (etb) 39 55 7 71 G 87 W 103 g 119 w 8 (bs) 24 (can) 40 ( 56 8 72 H 88 X 104 h 120 x 9 (tab) 25 (em) 41 ) 57 9 73 I 89 Y 105 I 121 y 10 (lf) 26 (eof) 42 * 58 : 74 J 90 Z 106 j 122 z 11 (vt) 27 (esc) 43 + 59 ; 75 K 91 [ 107 k 123 { 12 (np) 28 (fs) 44, 60 < 76 L 92 \ 108 l 124 13 (cr) 29 (gs) 45-61 = 77 M 93 ] 109 m 125 } 14 (so) 30 (rs) 46. 62 > 78 N 94 ^ 110 n 126 ~ 15 (si) 31 (us) 47 / 63? 79 O 95 _ 111 o 127 C++ for C Programmers Page: A-6 Copyright 2017 by James J. Polzin All Rights Reserved

APPENDIX F : USING THE GCC COMPILER FOR C++ Create a file using your favorite text editor or retrieve some file containing C++ source code from somewhere.{by convention your file should end in.cpp or.cc and the gcc compiler requires it.} To compile: g++ hello.cpp compiles and links the file hello.cpp and produces a file called a.exe that can be executed g++ -o hello hello.cpp compiles and links the file hello.cpp and produces an executable file called hello.exe g++ -c hello.cpp compiles only, the file hello.cpp is compiled into an object module hello.o g++ -Wall hello.cpp compiles and links and displays warnings on all things that are somewhat questionable There is documentation available for the gcc compiler. The gcc compiler can cross-compile for many different processors. C++ for C Programmers Page: A-7 Copyright 2017 by James J. Polzin All Rights Reserved

APPENDIX G : RELATIONAL OPERATORS Relational operators test a relationship and produce a true/false result. operator Function = = Equality < less than > greater than <= less than or equal >= greater than or equal!= not equal APPENDIX H : LOGICAL OPERATORS Logical operators work on logical values and produce a logical result. operator Function && AND OR! NOT C++ for C Programmers Page: A-8 Copyright 2017 by James J. Polzin All Rights Reserved

APPENDIX I : USING THE DEV C++ IDE The Dev-C++ Integrated Development Environment can be used to create, run and debug C programs on a PC. It has the following useful features: It is available free of charge on the Web It utilizes the gcc compiler cont Start Dev C++ C++ for C Programmers Page: A-9 Copyright 2017 by James J. Polzin All Rights Reserved

Open a C++ file cont C++ for C Programmers Page: A-10 Copyright 2017 by James J. Polzin All Rights Reserved

Go to the Execute menu and select compile cont C++ for C Programmers Page: A-11 Copyright 2017 by James J. Polzin All Rights Reserved

Go to the Execute menu and select Run cont C++ for C Programmers Page: A-12 Copyright 2017 by James J. Polzin All Rights Reserved

You can also select Compile & Run initially: cont C++ for C Programmers Page: A-13 Copyright 2017 by James J. Polzin All Rights Reserved

To view the output you have two choices: Alter the code as shown below Or// open a separate command window in your work directory and execute the.exe file directly cont C++ for C Programmers Page: A-14 Copyright 2017 by James J. Polzin All Rights Reserved

C++ for C Programmers Page: A-15 Copyright 2017 by James J. Polzin All Rights Reserved

APPENDIX J : USING OPENGL & GLUT OpenGL is an open source library of graphics routines available on many platforms. The Dev-C++ distribution comes with the OpenGL libraries. This means you can compile OpenGL code with Dev-C++. GLUT is the OpenGL Utility Toolkit. The library and include files for GLUT are not distributed with Dev-C++ but can be obtained on the Web. Visit: OpenGL.org on the Web for a vast assortment of code, examples, and tutorials relating to OpenGL and GLUT. Several GLUT related files are included in the examples/opengl/lib and examples/opengl/include/gl directory for the course, the three we will use are: glut.h a header file for the GLUT functions libfreeglut.a a library of the GLUT functions freeglut.dll a dynamic link library for executing the programs built with these libraries. It should be placed in the same directory as your program. The compile command should look as follows: g++ glutsource.cpp -I..\OpenGL\include -L..\OpenGL\lib -lfreeglut -lglu32 -lopengl32 libglu32.a and libopengl32.a are OpenGL files included with the Dev-C++ distribution. There are make files for the OpenGL examples in the OpenGL/Examples directory. These can be used to build the examples and also as a reference for the compile command, the libraries to use, and the order they are listed. Note: The order of the files & libraries matters. The dynamic link library file freeglut.dll must be on the search path for the programs to run. If the current working directory is the examples directory, or the examples directory is in the search path, things will run fine. C++ for C Programmers Page: A-16 Copyright 2017 by James J. Polzin All Rights Reserved

Recommended reading & information sources: OpenGL.org - on the web OpenGL Super Bible by Wright OpenGL Programming Guide by Woo OpenGL Reference Manual by Shreiner Building with make Command: H:\c \examples\opengl>make -f glutsource.mak g++ -c -I..\OpenGL\include glutsource.cpp g++ -L..\OpenGL\lib -o glutsource glutsource.o -lfreeglut -lglu32 -lopengl32 -mwindows Make file: # *********************************************************** # *** A make file to build the opengl, GLUT files **** # *********************************************************** glutsource.exe: glutsource.o g++ -L..\OpenGL\lib -o glutsource glutsource.o -lfreeglut -lglu32 -lopengl32 -mwindows glutsource.o: glutsource.cpp g++ -c -I..\OpenGL\include glutsource.cpp C++ for C Programmers Page: A-17 Copyright 2017 by James J. Polzin All Rights Reserved

Building within the Dev-C++ IDE: Under Tools select Compiler Options: In the Add... when calling the compiler field; check the box and type: -I..\OpenGL\include In the Add... when calling the linker field; check the box and type: -L..\OpenGL\lib -lfreeglut -lglu32 -lopengl32 -mwindows C++ for C Programmers Page: A-18 Copyright 2017 by James J. Polzin All Rights Reserved

C++ for C Programmers Page: A-19 Copyright 2017 by James J. Polzin All Rights Reserved

APPENDIX K : SETTING THE SEARCH PATH The operating system only looks in a few places for programs The current working directory The directories listed on the search path, PATH To change the directories the operating system will search you can modify the PATH environment variable: On the Windows OS: Use the set command set PATH=%PATH%;C:\Dev C++\bin - This will assign the previous value of PATH (indicated by %PATH%) to the PATH variable along with the C:\Dev C++\bin directory In this course the settings might be: H:\C++\examples> set PATH=%PATH%;C:\Program Files\ Dev C++\bin - For the GCC installed on the classroom machines You can alter the PATH environment variable permanently for the entire system by going to: Start -> Control Panel -> System -> Advanced System Settings -> Environment Variables and editing the PATH variable value. If installed properly, and your PATH is set properly, you should be able to type gcc and get an error message back from the compiler. If you can t, verify that the gcc.exe file is in fact in the /bin subdirectory you specified. If it is, try running it by typing the complete path to it. If the compiler is in fact on your machine, check your PATH variable setting. This can be done by typing PATH at the command prompt, to show your PATH variable setting, or by typing just set, to show all your environment variable settings. Your PATH variable must contain the complete path to the /bin directory that contains the gcc.exe file. Notes: The actual path to the /bin subdirectory will likely be different on different machines, depending on the installation directory and name of the particular program that was installed. C++ for C Programmers Page: A-20 Copyright 2017 by James J. Polzin All Rights Reserved

Generally, when setting the PATH value in a command window/shell; that setting is only good within that window/shell. o If you exit that window/shell the setting will be lost Check your /examples directory for a provided batch file or script that will set the PATH variable for you. C++ for C Programmers Page: A-21 Copyright 2017 by James J. Polzin All Rights Reserved

APPENDIX L : USING COMMAND-LINE ARGUMENTS Information is passed into a C++ program from the operating system s command line in the same manner as C program. The command-line arguments are packaged up into an array of strings, and the count of the number of strings and the array of strings are passed to main( ). The first line of the definition of main( ) will now look like: int main(int argc, char *argv[ ] ) argc is the argument count, argv is the array of strings. Each command-line argument can now be accessed within the program. Ex: /* FILE: cmdline1.cpp */ /* Program echoes all the command line arguments given. */ #include <iostream> using std::cout; using std::endl; int main(int argc, char *argv[ ]) { int i; for(i=0; i<argc; i++) cout << "argv[" << i << "] = " << argv[i] << endl; return 0; } /* OUTPUT: cmdline1.cpp COMMAND LINE: cmdline1 one two three argv[0] = cmdline1 argv[1] = one argv[2] = two argv[3] = three COMMAND LINE: cmdline1 one 1 two 2 three 3 argv[0] = cmdline1 argv[1] = one argv[2] = 1 argv[3] = two argv[4] = 2 argv[5] = three argv[6] = 3 */ COMMAND LINE: cmdline1 "Jim Polzin" "Teaches C++, sometimes." argv[0] = cmdline1 argv[1] = Jim Polzin argv[2] = Teaches C++, sometimes. C++ for C Programmers Page: A-22 Copyright 2017 by James J. Polzin All Rights Reserved