User Tools

Site Tools


notes:cprog

This is an old revision of the document!


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
notes/cprog.1504122008.txt.gz · Last modified: 2017/08/30 15:40 by KJONES35