DASL130 C Course Week 1
DASL130 C Course Week 1
DASL130 C Course Week 1
Lecture 1
Compiler
A compiler turns C code into machine code, in other words an executable file Dev-C++
http://www.bloodshed.net/devcpp.html
Basic Program
Hello World Code:
#include <stdio.h>
Variables
Format:
Type name = value; Variable names: start with a letter, can not be a keyword Convention is lowercase for variables, uppercase for constants
Types
Char 1 byte
Signed is -128 to 127 Unsigned is 0 to 255 ASCII Table converts char values to characters Escape sequences:
\n new line \r line return \t tab \ \ - quotes
Types
Int
short int at least 16 bits int no larger than long, no shorter than short long int at least 32 bits (-2 billion to 2 billion) long long int at least 64 bits Escape sequences
Octal - \000 Hex - \x00
Types
Float and Double
Float 6 digit precision Double 12 digit precision Precision is number of digits
sizeof() returns size of a variable in bytes
Type Casting
Allows conversion of variable types float test = (float)5
Operators
Arithmetic
+ , - , * , / , % (modulus) ++ , -- (prefix and postfix incrementation) += , -= , *= , /= , %=
Logical
&& , || , == , !=
Bit Shifting
<< , >> , | , & , ^
Standard I/O
Basic Output printf()
printf(An integer is %d\n, int var); d/i = int, f = floating point, e = exponential notation, c = single char, s = string, o = octal, x/X = hex, u = unsigned int