Download presentation
Presentation is loading. Please wait.
Published byFay Malone Modified over 9 years ago
1
Programming C/C++ on Eclipe C Training Trình bày : Ths HungNM
2
Training C/C++Ecosoftware 2 Programming C Overview cource
3
Training C/C++Ecosoftware 3 Introduction C o 1. Introduction C o 2. C Program Structure o 3. C Development Environment o 4. Eclipse Environment o 5. Variable and Data types o 6. Statement and Operator o 7. C Programming Construct o 8. Array
4
Training C/C++Ecosoftware 4 1. Introduction C o C was initially used for systems programming o Middle Level Language High language Level Assembly language o Structured Language C
5
Training C/C++Ecosoftware 5 Introduction C o C has 32 keywords o These keywords combined with a formal syntaxform a C programming language o Rules to be followed for all programs written in C: All keywords are lowercased C is case sensitive, do while is different from DO WHILE Keywords cannot be used as a variable or function name main() { /* This is a sample Program*/ int i,j; i=100; j=200; : }
6
Training C/C++Ecosoftware 6 2. C Program Structure 1
7
Training C/C++Ecosoftware 7 2. C Program Structure 2
8
Training C/C++Ecosoftware 8 2. C Program Structure 3
9
Training C/C++Ecosoftware 9 2. C Program Structure 4
10
Training C/C++Ecosoftware 10 2. C Program Structure 5
11
Training C/C++Ecosoftware 11 3. C Development Environment o Six phases : Edit Preprocess Compile Link Load Execute
12
Training C/C++Ecosoftware 12 3. C Development Environment o Six phases : Edit Preprocess Compile Link Load Execute
13
Training C/C++Ecosoftware 13 4. Eclipse Environment o Step 1 : Create a project o Step 2 : Reviewing the code and Building project o Step 3 : Run a Program
14
Training C/C++Ecosoftware 14 4. Eclipse Environment o Step 1 : Create a project
15
Training C/C++Ecosoftware 15 4. Eclipse Environment o Step 2 : Reviewing the code and Building project Choose source code Save for change Build your project (using gcc or ctrl+B) Read through the build message in the console view o Step 3: Choose run application Run > Run Configurations…
16
Training C/C++Ecosoftware 16 Example o Write simple example with Eclipse.
17
Training C/C++Ecosoftware 17 5. Variables and Data types o Variables allow to provide a meaningful name for the location in memory Data Memory Each location in the memory is unique 15 Data in memory 15
18
Training C/C++Ecosoftware 18 5.1 Identifier Variables o The names of variables, functions, labels, and various other user defined objects are called identifiers o Some correct identifier names arena s_count marks40 class_one o Examples of erroneous identifiers 1sttest oh!god start... end o Identifiers can be of any convenient length, but the number of characters in a variable that are recognized by a compiler varies from compiler to compiler o Identifiers in C are case sensitive
19
Training C/C++Ecosoftware 19 5.2 Keywords autoenumrestrictunsigned breakexternreturnvoid casefloatshortvolatile charforsighedwhile continuegotosizeof_Bool defaultIfstatic_Complex doinlinestructure_Imaginary doubleintswitch elselongtypedef unionregister
20
Training C/C++Ecosoftware 20 5.3 Data types o Value types Variable of value type store actual values o Pointer types Variables that can store addresses are called pointers The address that’s stored in a pointer is usually that of another variable
21
Training C/C++Ecosoftware 21 Value types
22
Training C/C++Ecosoftware 22 Simple Declaration main () { char abc; /*abc of type character */ int xyz; /*xyz of type integer */ float length; /*length of type float */ double area; /*area of type double */ long liteyrs; /*liteyrs of type long int */ short arm; /*arm of type short integer*/ }
23
Training C/C++Ecosoftware 23 Pointer types main () { int number = 5; int *p = &number ; } How a pointer works
24
Training C/C++Ecosoftware 24 Example o Example with basic data types o Example with pointers
25
Training C/C++Ecosoftware 25 Example o Example with basic data types
26
Training C/C++Ecosoftware 26 Example o Example with Pointers
27
Training C/C++Ecosoftware 27 6. Statement and Operator o Type Statement Selection statements Iteration statements Jump statements o Operators Arithmetic operators Relational Operators Logical Operators Conditional Operators Increment and Decrement Operators Assignment operators
28
Training C/C++Ecosoftware 28 6.1 Type Statement o Selection statements If, else, switch and case o Iteration statements do, for, while o Jump statements Break, continue, goto, return
29
Training C/C++Ecosoftware 29 6.2 Operators o Arithmetic operators
30
Training C/C++Ecosoftware 30 6.2 Operators o Relational Operators o Logical Operators Logical OperatorsDescriptionExample &&Return 1 if both the expression are evaluated to 1 ||Return 1 if at least one of the expression is evaluated to 1 !Return 1 if only one of the expression is evaluated to 1…
31
Training C/C++Ecosoftware 31 6.2 Operators o Bitwise Logical Operators Bitwise Logical Operators AND ( NUM1 & NUM2) Return 1 if both the operands are 1 OR ( NUM1 | NUM2 ) Returns 1 if bits of either of the operand are 1 NOT ( ~ NUM1) Reverses the bits of its operand ( from 0 to 1 and 1 to 0) XOR ( NUM1 ^ NUM2) Returns 1 if either of the bits in an operand is 1 but not both
32
Training C/C++Ecosoftware 32 6.2 Operators o Example Bitwise Logical Operators
33
Training C/C++Ecosoftware 33 6.2 Operators o Conditional Operators #define True = 1; #define False = 0;
34
Training C/C++Ecosoftware 34 6.2 Operators o Increment and Decrement Operators Increment operator (++) use to increment the value by 1 Decrement operator (--) use to decrement the value by 1
35
Training C/C++Ecosoftware 35 6.2 Operators o Assignment operation Simple assignment operation. Compound assignment operation.
36
Training C/C++Ecosoftware 36 6.2 Operators o Precedence of operators 1. Operator ClassOperatorsAssociativity Unary- ++ --Right to Left Binary^Left to Right Binary* / %Left to Right Binary+ -Left to Right Binary=Right to Left
37
Training C/C++Ecosoftware 37 6.2 Operators o Precedence of operators 2 - Example
38
Training C/C++Ecosoftware 38 6.2 Operators o Type conversion
39
Training C/C++Ecosoftware 39 Example o Example with Operator
40
Training C/C++Ecosoftware 40 7. C Programming Construct o Selection construct o Loop construct o Jump statements
41
Training C/C++Ecosoftware 41 7.1 Selection contruct o if else constructs o if..else if constructs o Nested if constructs o switch statements
42
Training C/C++Ecosoftware 42 7.2 Loop contructs o while o do while o for
43
Training C/C++Ecosoftware 43 Example o Example Selection
44
Training C/C++Ecosoftware 44 Example o Example with Loop contructs
45
Training C/C++Ecosoftware 45 8.Array o Introduction Array o One-Dimensional o Multi-Dimensional
46
Training C/C++Ecosoftware 46 8.1 Introduction Array o Each member of an array is identified by unique index or subscript assigned to it. o The dimension of an array is determined by the number of indices needed to uniquely identify each element o An index holds integer values starting with zero o An index is a positive integer enclosed in [ ] placed immediately after the array name
47
Training C/C++Ecosoftware 47 8.2 One-Dimensional o Declaring Array type array-Name[array-size]; int c[12]; // c is array of 12 integers o Init element of array int c[5] = {}; // init element of integer for 0 int c[5] = {1,3,5,7,10}; // o Interaction with array Using loop statement : for, while, do-while
48
Training C/C++Ecosoftware 48 Example One-Dimensional
49
Training C/C++Ecosoftware 49 8.3 Multi-Dimensional o Declaring Array type array-Name[array-size]; int c[4][3]; // c is array 2 dimensions of integers o Init element of array int c[2][2] = {{1,1},2,4}; // init element for array o Using nested loop for interaction with array
50
Training C/C++Ecosoftware 50 Example Multi-Dimensional
51
Training C/C++Ecosoftware 51 Thank You End
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.