Friday 3 January 2014

Once upon a time when your computer registered to a domain controller

Your computer behaveour; your windows component behaviour can be controlled. For instances,

C

1. Datatypes 

Datatypes determine the size, layout of the variable's memory, the range of values that can be stored within that memory, and the set of operations that can be applied to the variable.

2. Variables
A name given to a storage area that our programs can manipulate.

Styles:
1.type variable_list;
2.type variable_name = value;




Type can be: {int, char, float, double, void}
Note: void is bencong (absence of type)

Integer

Floating point

Components:
1. storage size
2. value ranges
3. the precision (berapa dijit dibelakang koma yang dimunculkan)

Contoh:


3. Constants and literals: 
Constants: fixed values that the program may not alter during the execution of a program.
Programming practice use all capslock word as constant name

Literals:


Styles defining constant:
1. Using #define preprocessor
#define name value
example:
#define LENGTH 10

2. Using const keyword
const type variable = value;

example:
cons int LENGTH = 10;



4. Storage class
Define scope (visibility) and lifetime of variables.
Storage class: {auto, register, static, extern}

auto storage class is default, can only be used within a function
register storage class define a local variable that should be stored in register instead in RAM. This means the variable has a maximum value size equal to the register size(usually one word) and doesn't have unary operator (&) applied to it (as it does not have a memory location)
static storage class
extern storage class is used to give a reference of a global variable that is visible to all the program files. Can't be initialized




5. Operators
An operator is a symbol, symbol that tells the compiler to perform specific mathematical manipulation or logical manipulation.

Arithmetic = {+. -. /, *}
Relational = {==, !=, <, >, >=, <=}
Logic = {And, Or, Not}
Bitwise = {
Unary = & = give memory address of a variabel
Sizeof(type) or sizeof(variable): return the size of type/variable






6. Decision making
Components:
1. Conditionals to be evaluated
2. Statements to be evaluated

Styles:
1. If
if there is another if then use elseif


2. Switch



7. Loops
Components:
1.
2.
3.

Styles:
1.
2.

8. Functions
Function is a group of statements. Divide your code so each function performs a specific task.

C at least having 1 function that is main() function.

The type of a function specifies the type of function's return value.

For functions that require parameters, you can pass parameters by reference or by value.
For functions that not require parameters, you shall not pass parameters by reference or by value.

Alias
A function = a method = a sub-routine = a procedure

Components:
1. Function name
2. Function's return type value
3. Function's argument/parameter
4. What function do

Examples:
main()


9. Scope rules
Scope is a region, a region of where variable can be accessed (local/interlocal?)
Scope in Bahasa is Batasan, daerah mana variabel itu bisa diakses.
Scope = [local, global, formal]

Local variabel = variabels that declared inside a function or block. They can be used only by statements that are inside that function or inside that block of code. Local variables are not known to functions outside their own.




10. Arrays

Array is a data structure.
Array is a collection of variable of the same type.


11. Pointers
Untuk menyimpan alamat memori suatu variabel.
Trus apa gunanya kalau kita sudah simpan alamat memori suatu variabel? Yah, lo bisa munculinnya.


Styles:
type *variable_name

Example:
Int *aloha


12. Strings
The string in C programming language is actually a one-dimensional array of characters and terminated by null character.

13. Structure
Array is same data type but structure variabel can save many different data type.

You can access a variabel attribute with (.),example: variabel1.name, variabel1.memory_address,

1st. Define structure format
- define structure name
- define attributes

2nd. Assign a variable as member of  a structure
-

3rd.

14. Unions
Unions: "One (unity) for all"
Imagine that you want to build a variabel that not restricted to only one data type, how you do that?
It is using unions

1st. Define the variabel that would be used as unions
2nd.
3rd.

Unions is a special data type.


Unions allow us to store different data types in the same memory location.

Unions provide an efficient way of using the same memory location for multi-purpose.



15. Bitfields


16. Typedef
Typedef is to give a type a new name.
 


17. Input & Output
When we are saying Input that means

C treat all device as file. So display is addresses the same way as files.




18. File I/O
How to open/create, close, read and write a file.

File represent a sequence of bytes.

Open file
fopen()

Closing file
fclose()

Writing file
fputc()

Reading file
fgetc()


19. Preprocessors (something that compiler do before compiling our program)
CPP as C preprocessor.

All preprocessor commands begin with a pound system (#)

The most common examples:
#include <stdio.h>


20. Header Files
File header adalah sebuah file yang berekstensi .h yang memuat deklarasi-deklarasi fungsi C dan defenisi-defenisi macro dan untuk dibagi antara file-file source.

Ada 2 tipe dari file-file header: file header buatan sendiri atau file header bawaan.

Contoh file header bawaan: stdio.h

Kedua tipe file header di ikut sertakan dengan menggunakan # atau directive include.
Contoh:
#include <stdio.h>



21. Type Casting (converting)
Type casting is a way to convert a variable from one data type to another data type.

For example, if you want to store a long value into simple integer then you can type cast to long to int.


22. Error Handling (Nanganin error)

Error is not what we expected.

We can define

23. Recursion
Calling a function inside a function.

When? Very useful when used to solve mathematical problems like to calculate factorial of a number, generating fibonacci sequence, etc.
 




24. Variable Arguments
#include stdarg.h

25. Memory Management
#include stdlib.h

Components:
1. void malloc
2. 

 
26. Command Line Arguments
Components:
1. Argc
2. Argv



API (Application Programming Interfaces)

Allowing us to access arrays of function and method that an Operating System or other application (DLL) expose.

Operation such as shutting down a computer or listing the current running processes.




Pointer C

pointer(*) expecting/supposed to receive a memory address (room number) and return the value inside that memory address.
Notation: *p

while ampersand(&) expecting a variable


MPLS

"use labels instead of ip address"

read www.ilmukomputer.com

Modulus

What can I say about modulus?

Modulus is an advancement of divide.

Cozy Environment to build a C program

1. Download codeblocks
2. Install codeblocks
3. Add codeblocks to system environment. Contoh: punya gue: C:/programfiles/codeblocks/bin
4. Open notepad, write your code there, save ke folder yang lo suka, punya gue: e:/C
5. Open cmd, type e:, type c,
6. type gcc <your filename> -o <your exe filename>
contoh: gcc aloha -o alohabin.exe
7. back to cmd, type alohabin
8. Finish

Component:
1. CMD
2. C file
3. C exe file