150 likes | 322 Views
Summary. Data Types. int A; I am declaring a variable A, which is an integer. Arrays. int A[50]; I am declaring an array A. This array has 50 elements , and each element is an integer . A[0] is the first element of the array A[49] is the last element of the array.
E N D
Data Types int A; I am declaring a variable A, which is an integer.
Arrays int A[50]; I am declaring an array A. Thisarray has 50 elements, andeach element is an integer. A[0] is thefirst element of thearray A[49] is thelast element of thearray
if, else if, else if ( statement) { yourcode here } else if ( statement) { yourcode here } else if (statement) { yourcode here } … else { yourcode here }
while while(statement) { yourcode here }
for for(initialcondition ; statement ; final operation) { yourcode here }
function intfoo(int A, int B) { int C; yourcode here return C; }
How tocallyourfunction void main() { int X; int Y; int Z; Z = foo (X, Y); printf(foo(%d, %d) = %d\n, X, Y, Z); }
Struct typedefstructtag_name { type element1; type element2; } tag_name;
StructExample #include<stdio.h> typedefstructStudent { intmidterm;//%40 inthw;//%20 intfinal;//%40 intaverage; } Student; void main() { StudentVeli; Veli.hw= 80; Veli.midterm= 90; Veli.final= 100; Veli.average= (Veli.hw*20 + Veli.midterm*40 + Veli.final*40)/100; printf("Veli has an average grade of %d \n", Veli.average); }
Base Arithmetic • Binarynumbers (base 2): Useonlydigits 0 and 1 • Decimalnumbers (base 10): Usedigits 0,1,2,3,4,5,6,7,8,9 • Hexadecimalnumbers (bas 16): Usedigits 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F • A = 10, B = 11, C = 12, D = 13, E = 14, F = 15
One’sandTwo’scomplement • 1’s complemenf of an N-bit number: Invertallthebits in binaryrepresentation. • 2’s complement of an N-bit number: subtractthenumberfrom 2N.