Programming C/C++ on Eclipe C Training Trình bày : Ths HungNM
Training C/C++Ecosoftware 2 Programming C Overview cource
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
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
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; : }
Training C/C++Ecosoftware 6 2. C Program Structure 1
Training C/C++Ecosoftware 7 2. C Program Structure 2
Training C/C++Ecosoftware 8 2. C Program Structure 3
Training C/C++Ecosoftware 9 2. C Program Structure 4
Training C/C++Ecosoftware C Program Structure 5
Training C/C++Ecosoftware C Development Environment o Six phases : Edit Preprocess Compile Link Load Execute
Training C/C++Ecosoftware C Development Environment o Six phases : Edit Preprocess Compile Link Load Execute
Training C/C++Ecosoftware Eclipse Environment o Step 1 : Create a project o Step 2 : Reviewing the code and Building project o Step 3 : Run a Program
Training C/C++Ecosoftware Eclipse Environment o Step 1 : Create a project
Training C/C++Ecosoftware 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…
Training C/C++Ecosoftware 16 Example o Write simple example with Eclipse.
Training C/C++Ecosoftware 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
Training C/C++Ecosoftware 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
Training C/C++Ecosoftware Keywords autoenumrestrictunsigned breakexternreturnvoid casefloatshortvolatile charforsighedwhile continuegotosizeof_Bool defaultIfstatic_Complex doinlinestructure_Imaginary doubleintswitch elselongtypedef unionregister
Training C/C++Ecosoftware 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
Training C/C++Ecosoftware 21 Value types
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*/ }
Training C/C++Ecosoftware 23 Pointer types main () { int number = 5; int *p = &number ; } How a pointer works
Training C/C++Ecosoftware 24 Example o Example with basic data types o Example with pointers
Training C/C++Ecosoftware 25 Example o Example with basic data types
Training C/C++Ecosoftware 26 Example o Example with Pointers
Training C/C++Ecosoftware 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
Training C/C++Ecosoftware Type Statement o Selection statements If, else, switch and case o Iteration statements do, for, while o Jump statements Break, continue, goto, return
Training C/C++Ecosoftware Operators o Arithmetic operators
Training C/C++Ecosoftware 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…
Training C/C++Ecosoftware 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
Training C/C++Ecosoftware Operators o Example Bitwise Logical Operators
Training C/C++Ecosoftware Operators o Conditional Operators #define True = 1; #define False = 0;
Training C/C++Ecosoftware Operators o Increment and Decrement Operators Increment operator (++) use to increment the value by 1 Decrement operator (--) use to decrement the value by 1
Training C/C++Ecosoftware Operators o Assignment operation Simple assignment operation. Compound assignment operation.
Training C/C++Ecosoftware 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
Training C/C++Ecosoftware Operators o Precedence of operators 2 - Example
Training C/C++Ecosoftware Operators o Type conversion
Training C/C++Ecosoftware 39 Example o Example with Operator
Training C/C++Ecosoftware C Programming Construct o Selection construct o Loop construct o Jump statements
Training C/C++Ecosoftware Selection contruct o if else constructs o if..else if constructs o Nested if constructs o switch statements
Training C/C++Ecosoftware Loop contructs o while o do while o for
Training C/C++Ecosoftware 43 Example o Example Selection
Training C/C++Ecosoftware 44 Example o Example with Loop contructs
Training C/C++Ecosoftware 45 8.Array o Introduction Array o One-Dimensional o Multi-Dimensional
Training C/C++Ecosoftware 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
Training C/C++Ecosoftware 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
Training C/C++Ecosoftware 48 Example One-Dimensional
Training C/C++Ecosoftware 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
Training C/C++Ecosoftware 50 Example Multi-Dimensional
Training C/C++Ecosoftware 51 Thank You End