C/C++ Programming Course Notes Wiki

For help with wiki syntax:

25 August

#include <stdio.h> -This is called a preprocessor directive, it aids the compiler in the early stages of compilation.

Comments can be added to computer programs to increase their readability. These can take the form of multiline comments which start with /*. This leads the processor to ignore all information until a */ set of tokens is reached.

// are single line comments, adopted from C++ that allow for short commentsto be make easily.

All c programs contain the following function: int main() {

In this function int is the return value or data type. There are several types of data types, these include char, short int, int,long int and long long int. Main is the name of the function, and the parenthesis following that name indicate that this is indeed a function. A parameter, if a function operates on a certain parameter, could be put inside the parenthesis.

Programs should end with a return(0); This is a sort of check. If the program returns 0 it is running correctly.

C understands several logical operators, such as -& or bitwise and which implies that both parts of a given statement are true or the statement is not true. -| or bitwise or which implies that for a statement to be true one part of a given statement must be true.

» is a bitwhise right shift. « is a bitwise left shift. These are useful in multiplying and dividing as a computer is incapable of understanding even basic mathematical operations. ! is a bitwise not. This implies the converse of the following statement.

How to do Twos Complement


Say you want to do -3.
Write positive 3 first:0011
Invert the bits:1100
Add 1:1101
1101 is -3. Will be read as 13 unless you specify it needs to look for a signed value!

Operators

Relational Operators
== is equal to
!= is not equal to
< is less than
> is greater than
<= is less than or equal to
>= is greater than or equal to
Basic Math Operators
= set equality (thing on right to thing on left)
+ add
- minus
* mult
/ divide
% remainder of division (called modulus in some languages)
Logical Operators
& bitwise and
| bitwise ior (pipe in unix)
^ bitwise XOR
>> bitwise right shift
<< bitwise left shift
! bitwise not
Condition Chaining
&& and join
|| or join
examples: 
if((a==2)&&(b>7)) Both need to be true

if(a=7)||(b>7)) Any piece or both need to be true

September 6th 2017

There are four basic data types. Floating point numbers (or numbers which may include decimals), Integers, ASCII characters and Memory data/addresses. ASCII characters can be represented as integers. Memory data are also called “pointers.”

There are 3 types of floating points. They are called float double and long double.

A keyword called typedef can be used to replace longer keywords with a shorthand to add brevity to code. (An example would be typedef long double ldubs; A code that has this line at the beginning could use ldubs in place of the key phrase long double).

There are two types of division on a computer. There is integer and floating point processing. Floating point is the division we are familiar with which involves decimals. Integer processing is the sort of division we were taught as children which deals only with whole numbers and remainders. So 10 divided by 3 equals 3.3 repeating in floating point processing. Its exactly 3 (with one discarded remainder) in integer processing.