c basics course material_version1.3_updated
TRANSCRIPT
1. Tell the students why we need to know about programming ( machine language ) 2. Show them a simple compilation flow from c file to hex file ( IDE integrated
development environment)preprocessor (txt.c) – compiler (txt.o , .asm) – linker ( txt.exe , .hex)
1. Show them the Structure of the C file from #include to functions bodies if any
5
Naming Convention: You have to stick to a clear naming convention in order to make your code readable, for example:Char u8NumOfEmployessLong u16Salaryint _myAge
11
For Example If (x==y) depends on if x really equals to y, but in the other hand if (x=y) it will depend on the value of y if it is equal to 0 so the evaluation is false else it is true.int x = 1; int y = 0; if (x=y) False, int x = 1; int y = 10; if (x=y) True.
19
Short circuit: The evaluation of an expression is discontinued if the value of a conditional expression can be determined early. Be careful of any side effects in the code.Examples:(3==3) || ((c=getchar())==’y’). The second expression is not evaluated. (0) && ((x=x+1)>0) . The second expression is not evaluated.
20
Notes: - AND is true only if both operands are true. - OR is true if any operand is true. - XOR is true if only one of the operand is true. - Shift Left by x equal multiplication by 2 power to x- Shift Right by x equal divide by 2 power to x
22
As a rule, the compiler promotes each term in an binary expression to the highest precision operand.
25
Show the student a simple program that takes a number from the Keyboard and then display it back on the screen (Echo)
35
Show the student a simple program that takes a number from the Keyboard and then display it back on the screen (Echo)
36
Show the student a simple program that takes a number from the Keyboard and then display it back on the screen (Echo)
37
A common pattern in C (and in most programming) languages is the following: if ( cond ) x=<expra >; else x=<exprb >;
38
Give the Students a program that has al logical error and tell them to debug and know the error source :
#include <stdio.h>#include <stdlib.h>
int main(){
int value,i;
printf("value before for loop is %d \n",value);for(i=0;i<10;i++);{
value++;}
printf("value before for loop is %d \n",value);
return 0;}
64
The compiler always reference the variable from the private scope first then the outer scopeSo first it will print 10, and then 25 line is printed.
101
The preprocessor operation : is a stage before compilation to handle the preprocess keywords like #define, #include, #ifdef, and #ifndef.Simply it does some text replacement, addition, deletion on the code depending of the used keywords before the compilation.
Other keywords will be explained later with the convenient context.
141