CIS Logo SVC Logo

   Computing & Information Systems


Schoology Facebook        Search CIS Site      Tutorials

Software Design Using C++

Useful Tables: Precedence Chart, Data Types, and Library Functions

Operator Precedence Chart

We need to know which operator comes first when writing arithmetic expressions in our C++ programs. The most common arithmetic operators follow the same precedence rules as in algebra. However, C++ includes additional operators not found in ordinary algebra. The following table shows many (but not all) of the C++ operators for arithmetic, logical operations, etc. Those with priority 1 are handled before all of those with a larger precedence number. Those with priority 2 come after those with priority 1 but before all of the others. Those with the same priority are generally handled in a left to right fashion. Parentheses can be used to group items so that whatever is inside is handled before other items. If there are parentheses inside of parentheses it is the innermost set of parentheses that is handled first.

Operator Description Precedence
() function call 1
[] array indexing 1
++ after a variable postincrement 1
-- after a variable postdecrement 1
! Boolean NOT 2
++ before a variable preincrement 2
-- before a variable predecrement 2
- before an expression unary minus 2
* multiply 3
/ divide 3
% remainder (mod) 3
+ add 4
- subtract 4
< less than 5
> greater than 5
<= less than or equal 5
>= greater than or equal 5
== equal 6
!= not equal 6
&& Boolean AND 7
|| Boolean OR 8
= assignment 9
+= (and similar) add and assign 9

Data Types

There are many data types available in C++, and the programmer can also define new ones by setting up appropriate classes (as covered in the Intermediate and Advanced sections of these Software Design Using C++ web pages. The table below lists many of the data types commonly available to the C++ programmer. Note that you can find more information about most of these types by looking up certain articles in the Visual Studio help system. Also, notice that the "Section" column indicates in what section of these C++ web pages each data type is covered, thus giving a rough idea of the level of difficulty.

Type Description Section Visual Studio Help System Articles Further Information
int integer introductory Fundamental Types, Data Type Ranges discussion, example
char character introductory Fundamental Types, Data Type Ranges discussion, example
float floating point number introductory Fundamental Types, Type float, Data Type Ranges discussion, example
long long integer intermediate Fundamental Types, Data Type Ranges discussion, more
double double precision float not covered Fundamental Types, Type float, Data Type Ranges  
bool Boolean introductory Fundamental Types discussion
char array C-style char array string introductory   discussion, more, example, security
Class string a string class advanced string discussion, example
Class CString another string class advanced Basic CString Operations discussion

Library Functions

Lots of built-in library functions are available for your use. The table below presents summary information about some of the most commonly-used ones. The "header" column indicates what header file (if any) needs to be included in order to use each function. Note that this can vary somewhat from compiler to compiler.

Function Description Header
double pow(double, double) returns first parmeter to power of second parameter cmath
int abs(int) returns absolute value of parameter cstdlib
double abs(double) returns absolute value of parameter cmath
double sqrt(double) returns square root of parameter cmath
double exp(double) returns e to power of parameter cmath
double log(double) returns base e log of parameter cmath
double log10(double) returns base 10 log of parameter cmath
double sin(double) returns sine of parameter cmath
double cos(double) returns cosine of parameter cmath
double tan(double) returns tangent of parameter cmath
double asin(double) returns Arcsine of parameter cmath
double acos(double) returns Arccosine of parameter cmath
double atan(double) returns Arctangent of parameter cmath
int srand(unsigned int) seeds random number generator with parameter cstdlib
int rand() returns a pseudorandom int between 0 and RAND_MAX cstdlib
strcat(char_array_variable, char_array_expression) appends second parameter to end of first parameter cstring
strcpy(char_array_variable, char_array_expression) copies second parameter to first parameter cstring
strcmp(char_array_expression, char_array_expression) returns 0 if equal, negative if first less than second, positive otherwise cstring
integer strlen(char_array_expression) returns number of characters in parameter cstring
bool isalpha(char) returns true if parameter is a letter cctype
bool isdigit(char) returns true if parameter is a digit cctype
bool isalnum(char) returns true if parameter is letter or digit cctype
bool isupper(char) returns true if parameter is a uppercase letter cctype
bool islower(char) returns true if parameter is a lowercase letter cctype
int toupper(char) returns uppercase version of parameter cctype
int tolower(char) returns lowercase version of parameter cctype
int atoi(const char_array) returns parameter converted to an integer cstdlib
double atof(const char_array) returns parameter converted to a double cstdlib

Back to the main page for Software Design Using C++

Author: Br. David Carlson with contributions by Br. Isidore Minerd
Last updated: August 27, 2009