Presentation is loading. Please wait.

Presentation is loading. Please wait.

Pemrograman C Risanuri Hidayat. Why C  Compact, fast, and powerful  “Mid-level” Language  Standard for program development (wide acceptance)  It is.

Similar presentations


Presentation on theme: "Pemrograman C Risanuri Hidayat. Why C  Compact, fast, and powerful  “Mid-level” Language  Standard for program development (wide acceptance)  It is."— Presentation transcript:

1 Pemrograman C Risanuri Hidayat

2 Why C  Compact, fast, and powerful  “Mid-level” Language  Standard for program development (wide acceptance)  It is everywhere! (portable)  Supports modular programming style  Useful for all applications  C is the native language of UNIX  Easy to interface with system devices/assembly routines  C is terse

3 Structure in C  C is case sensitive. All commands in C must be lowercase.  C has a free-form line structure. End of each statement must be marked with a semicolon. Multiple statements can be on the same line. White space is ignored. Statements can continue over many lines. #include main() { /* My first program */ printf("Hello Sayang…. \n"); } Listing 1. hello.c

4 Structure in C  The C program starting point is identified by the word main().  The two braces, { and }, signify the begin and end segments of the program.  #include is used to allow the printf statement to provide program output.  printf() is actually a function (procedure) in C that is used for printing variables and text. Where text appears in double quotes "", it is printed without modification, with some exceptions.

5 Structure in C  Keluaran layar: Hello Sayang….  Comments can be inserted into C programs by bracketing text with the /* and */ delimiters. /* My first program */  Header files contain definitions of functions and variables which can be incorporated into any C program by using the pre-processor #include statement.  To use any of the standard functions, the appropriate header file should be included. This is done at the beginning of the C source file. For example, to use the function printf() in a program, the line #include

6 Structure in C  #include  #include "mylib.h"  The use of angle brackets <> informs the compiler to search the compiler’s include directories for the specified file.  The use of the double quotes "" around the filename informs the compiler to start the search in the current directory for the specified file.

7 Structure in C  Identifiers in C must begin with a character or underscore, and may be followed by any combination of characters, underscores, or the digits 0-9. –summary exit_flag i –Jerry7 Number_of_moves _id

8 Structure in C  Keywords are reserved identifiers that have strict meaning to the C compiler. C only has 29 keywords. Example keywords are: –if, else, char, int, while  Names given to values that cannot be changed. Implemented with the –#define preprocessor directive. –#define N 3000 –#define FALSE 0 –#define PI 3.14159 –#define FIGURE "triangle"

9 Structure in C  Preprocessor statements begin with a # symbol, and are NOT terminated by a semicolon. Traditionally, preprocessor statements are listed at the beginning of the source file.  Preprocessor statements are handled by the compiler (or preprocessor) before the program is actually compiled. Once this substitution has taken place by the preprocessor, the program is then compiled.  In general, preprocessor constants are written in UPPERCASE. This acts as a form of internal documentation to enhance program readability and reuse.  In the program itself, values cannot be assigned to symbolic constants.

10 Example #include #define TAXRATE 0.10 main () { float balance; float tax; balance = 72.10; tax = balance * TAXRATE; printf("The tax on %.2f is %.2f\n",balance, tax); } The tax on 72.10 is 7.21


Download ppt "Pemrograman C Risanuri Hidayat. Why C  Compact, fast, and powerful  “Mid-level” Language  Standard for program development (wide acceptance)  It is."

Similar presentations


Ads by Google