1 / 160

Data Structures

Data Structures. C/C++ Review Prof A Alkhorabi أ. د / عـبدالله علي الخــوربي. -. -. Data Structures. C Review Prof A Alkhorabi أ. د / عـبدالله علي الخــوربي. -. -. C Characteristics. Size Type conversion Modern control constructs Bitwise control Pointer implementation

olina
Télécharger la présentation

Data Structures

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Data Structures C/C++ Review Prof A Alkhorabi أ.د/ عـبدالله علي الخــوربي - -

  2. Data Structures C Review Prof A Alkhorabi أ.د/ عـبدالله علي الخــوربي - -

  3. C Characteristics • Size • Type conversion • Modern control constructs • Bitwise control • Pointer implementation • Structure

  4. C Program Parts C Program constitutes from 2 parts: • Definition, Inclusion & Declaration Part • Functions Part

  5. 1. Definition, Inclusion & Declaration Part This part have two main sections: • C Preprocessor • Declaration part

  6. A. C Preprocessor Before compilation the C preprocessor (part of the C compiler) looks for directives (preceded by #), and execute the required task according to the directive type. There are 3 types of directives: • include Directive • define Directive • conditional compilation Directive

  7. include Directive Includes files to the including file. include <filename>#

  8. define Directive #define SymbolicName constant or #define SymbolicName simple calculation operation

  9. Conditional Compilation Directive ِAllows writing programs to more than one operating system #ifdef

  10. B.Declaration part • Allow declarations of Global Variables and Functions used later in the program.

  11. 2. Functions Part • Consists of one or more functions, one of which must be the main() function. • The C program starts execution from the main() function, and stops execution by the main() function end. • The main() function calls other functions, each can call other functions.

  12. C Programs Execution • C program passes through a number of phases starting from the written program by the programmer (Source File) till it became executable (Executable File). • This is normally established by Software Systems that are known as Integrated Development Environment (IDE) provided by specialized Software Companies.

  13. IDE • Program Editor • Preprocessor • Compiler • Assembler • Linker • IDE’s may include other facilities like Debugging.

  14. Typing طبع Editor المحرر Source (ASCII) code Preprocessor المُعد Assembler المُجمع Assembly code Compiler المُترجم Object code Linker المُدمج Libraries المكتبات executable code مراحل تطوير برنامجسي C Program Developing Phases

  15. C Program Structure /* (1) Inclusion, Definition & Global declarations part */ Inclusion part Definition part global declarations part /* (2) Functions part */ return_value main (arguments list) } local declaration part function executable statements { return_value function_2 (arguments list) } local declaration part function executable statements returned value { : :

  16. 1 /* Sum3.c - Program to sum 3 integers */ 2 /* 1- inclusion, definition & glbal vars and functions declaration part */ 3 # include “stdio.h” /* a- inclusion part */ 4 # define TEN 10 /* b- definition part */ 5 6 int sum; /* c-Global Variable & Functions Part */ 7 8 /* 2- Functions Part */ 9 void main(void) /* main Function */ 10 { /* Function opening brace */ 11 int num_1, num_2, num_3; /* Local Variables Declaration Part*/ 12 13 num_1 = 5; num_2 = 2; num_3 = num_2*TEN; 14 sum=num_1 + num_2 + num_3; /*Function’s Executable Stateent */ 15 printf(“The sum of the 3 numbers is %d \n”, sum); /* I/O Lib Func*/ 16 } /* Closing Brace */

  17. C Reserved Words • Used within a C program for a specific purposes and according to the language rules, and can not be used in other purposes ( as identifiers for example) • Consists of two main parts and one sub-part.

  18. Reserved Words: 1st main part • 28 words accompanied the C language from the beginning: autobreak case char continuedefault do double elseextern floatfor gotoif int long register return short sizeof static struct switch typedef union unsigned while entry

  19. Reserved Words: 2nd main part • 5 words added by ANSI (American National Standardization Institute): const enum signed void volatile

  20. ٍ Reserved Words: Sub-part • Added by some C Compilers manufacturers: Asm far _cs fortran huge near pascal

  21. Reserved Words: Note • All reserved words written using lower-case letters.

  22. Identifies Used to name and identify: • constants • variables • functions . • An identifier should not be a reserved word. • Small letters identifiers differ than that written as large letters. Ex: #define ONE 1 int sum; float real(void);

  23. Data Types • Basic Data Types أنواع البيانات الأساسية • Derived Data Types أنواع البيانات المشتقة • Data Structures تراكيب البيانات

  24. C Language Have 4 basic data types: Basic Data Types • Integers int. • Single-precision floating numbers float. • Double-precision floating numbersdouble. • Characters char.. • Void is used to define no type function argument or returned value. • Ex: void fn(void);

  25. Integer Variables Types

  26. Integer Operations Assignment operation Arithmetic operations Relational operations Logical operations Bitwise operations Conditional operator

  27. أسبقيات تنفيذ عوامل العمليات للأعداد الصحيحةInteger Operators Precedence

  28. أسبقيات تنفيذ عوامل العمليات للأعداد الصحيحةInteger Operators Precedence

  29. Floating-point Variables • The floating-point number 246.66 can be written in one of the following forms:

  30. Floating point Variables • Single precession real number “float”, 4 bytes. • Double precession real number “double”, 8 bytes. • Long single precession real number“long float”, 8 byes. • Long double precession real number “long double”, 10 bytes. • longfloatand double have the same properties.

  31. Floating point operations • Addition uses the operator + • Subtraction uses the operator- • Multiplication uses the operator* • Division uses the operator/

  32. Characters • Characters in C Language includes: • Alphabet letters • Lower case (a,b,c,..) • Upper case (A,B,C,…) • Digits (0,1,2,...) • Symbols (?,, > , # (,) • Formatting characters,(space, horizontal tabulation, vertical tabulation).

  33. Characters • Characters in C are according to ASCII(American National Standard Code for Information Interchange). • ASCII code also includes transmission characters used for computer network communications (ETX,SYN,...(

  34. /* AsciiCharacters.c ASCII Characters Program Example */ #include <stdio.h> #include <conio.h> void main(void) {int x; for(x = 0; x < 128; x++) { if (x % 20 == 0) getch(); printf("%d\t%c\n",x,x);} getch(); }

  35. Characters Character variables char ch; ch = ‘H’;

  36. Character Functions in the Standard Library • These functions return non-zero integers if it accomplishes their tasks positively, otherwise it returns zeros.

  37. وظائف الحروف في المكتبة القياسية

  38. Character strings • “This is string 1”

  39. Control In programming languages control is used to determine next statement to be executed. Normally control can be one of the following types: Sequential control . Conditional control. Iterative control. Jumping control.

  40. Conditional Control • Conditional control is accomplished by one of the following constructs: • if-else-if • switch

  41. Conditional Control • The if-else-ifis used as one of the following forms: • if • if-else • if-else-if

  42. شرط if F T تعبير او مجموعة تعابير if التعبير التالي if if (expression) /* تعبير جبري*/ executable_statement(s); /* تعبير أو مجموعة تعابير*/ next_statement; if ( x == 5 || y < 8) printf (“The if conditions that x= 5 OR y < 8 is TRUE” );

  43. F شرط if T تعبير else تعبير if التعبير التالي if- else if (expression) executable_statements_1; else executable_statements_2; next_statement;

  44. if الشرط الأول F T F else-if الشرط الثاني التعبير الأول التعبير الثاني F else else-if الشرط الثالث تعبير الاختيار النهائي النهائي التعبير الثالث التعبير التالي if-if- else if ( expression_1) statements_1 ; else if (expression_2) statements_2 ; else if (expression_3) statements_3; : else statements_n ; next_statement;

  45. /* ifelseif.c if-else-if Example Program*/ #include <stdio.h> #include <conio.h> void main(void) { int answer, i = 1; printf("What is the Capital of Yemen (y), UK (u), or Saudia Arabia (s) \n"); answer = getche(); if (answer == 'y' || answer == 'Y' ) printf ( "\n The Capital of Yemen is Sana'a\n\n"); else if (answer == 'u' || answer == 'U' ) printf ( "\n The Capital of UK is London\n\n"); else if (answer == ‘s' || answer == ‘S' ) printf ( "\n The Capital of Saudia Arabia is Riyadh\n\n"); else printf ( "\n No information is available about this country\n\n"); }

  46. switch switch (expression) { case constant_1 : statements_1; break; case constant_2: statements_2; break; . : default: statements_n; } next_statement;

  47. switch (تعبير جبري) تعبير الاختبار النهائي default y هل تطابق الحالة الأولى تعبابير break N y هل تطابق الحالة الثانية break تعابير N التعبير التالي switch

  48. /* switch.c switch Example Program */ #include <stdio.h> #include <conio.h> void main(void) { int answer, i = 1; printf("What is the Capital of Yemen (y), UK (u), or Saudia Arabia (s). \n"); answer = getche(); switch ( answer ) { case 'y' : printf ( "\nThe Capital of Yemen is Sana'a\n\n"); break; case 'Y' : printf ( "\nThe Capital of Yemen is Sana'a\n\n"); break; case 'u' : printf ( "\nThe Capital of UK is London\n\n"); break; case 'U' : printf ( "\nThe Capital of UK is London\n\n"); break; case ‘s' : printf ( "\The Capital of Saudia Arabia is Riyadh\n\n"); break; case ‘S' : printf ( "\The Capital of Saudia Arabia is Riyadh\n\n"); break; default : printf ( "\nNo information is available about this country\n\n"); } }

More Related