1 / 17

Strengths :

Chapter 1. Strengths :. 1. Efficiency. 2. Portability. 3. Power. 4. Flexibility. 5. Standard library. 6. Integration with UNIX. Weaknesses:. 1. C programs can be error-prone. 2. C programs can be difficult to understand. 3. C programs can be difficult to modify. Chapter 2.

Download Presentation

Strengths :

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. Chapter 1 Strengths: 1. Efficiency 2. Portability 3. Power 4. Flexibility 5. Standard library 6. Integration with UNIX Weaknesses: 1. C programs can be error-prone 2. C programs can be difficult to understand 3. C programs can be difficult to modify

  2. Chapter 2 The General Form of a Simple Program #include <stdio.h> main() { printf("To C/ or not to C: that is the question.\n"); return 0; } directives statements main() is a function. Functions are like "procedures" or "subroutines“. They are the building blocks from which programs are constructed. The main() function returns a status code when the program terminates

  3. Compiling and Linking • Preprocessing. The program is first given to a preprocessor, • which obeys commands that begin with # (known as directives). • #include <stdio.h> (include the info in <stdio.h> before compiling) 2. Compiling. The modified program now goes to a compiler, which translates it into machine instructions (object code). 3. Linking. A linker combines the object code produced by the compiler with any additional code needed to yield a complete executable program. test.c ---> (compiled) ---> test.obj (linked) --->executable file

  4. C Fundamentals 1. C requires that each statement end with a semicolon ; The semicolon shows the compiler where the statement ends printf (“hello world\n”); 2. Directives do not end with a semicolon #include <stdio.h> #include <stdio.h> /* Putting it all together in a program */ main () { printf(“hello world\n”); return 0; }

  5. Printing Strings print f is a function that displays a series of characters enclosed in double quotation marks. printf("that is the question.\n"); Writes that is the question, and advances to the next line.

  6. Comments The symbol /* marks the beginning of a comment and the symbol */ marks the end of a comment. /* This is a comment */ Every program should contain identifying information, for example: /* the program name the date written the author the purpose of the program */ In C, this information is placed in comments.

  7. Variables and Assignment Most programs need to perform a series of calculations before producing output. They need a way to store data temporarily during program execution. In C, as in most programming languages, these storage locations are called variables. Every variable must have a type, which specifies what kind of data it will hold. For example, int (integer) and float (floating point).

  8. Variables and Assignment Variables must be declared, described for the compiler, before they can be used. For example, we declare variables height and profit as follows: int height; float profit; The first declaration states that height is a variable of type int, thus height can store an integer value. The second declaration says that profit is a variable of type float.

  9. Variables and Assignment When main contains declarations, these must precede the statements: main() { declarations statements }

  10. Variables and Assignment A variable can be given a value by means of assignment. For example, the statements height = 8; length = 12 ; width = 10; Assigns the values 8, 12, and 10 to height, length, and width.

  11. Variables and Assignment Once a variable has been assigned a value, it can be used to help compute the value of another variable. volume = height * length * width * represents the multiplication operator, this statement multiplies the values stored in height, length, and width, then assigns the result to the variable volume.

  12. Printing the Value of a Variable Use printf to display the current value of a variable To display the values of both the height and length variables, we use the following call of printf: printf("Height: %d Length: %d\n", height, length); %d is a placeholder indicating where the value of height and length is to be filled in during printing. %d works only for int variables; to print a float variable, use %f

  13. Initialization Some variables are automatically set to zero when a program begins to execute, but most are not. We can not predict what the value of a variable will be initially; it might be 2568, -30891, or some equally strange number. Put the initial value of the variable in its declaration. We can declare the height variable and initialize it in one step: int height = 8 ; The value 8 is said to be an initializer.

  14. Reading Input To obtain input, we'll use the scanf function f stands for "formatted"; in both scanf and printf scanf needs to know what form the input data will take, just as printf needs to know how to display output data They require the use of a format string to specify the appearance of the input or output data. To read an int value, use scanf as follows: scanf("%d", &i); /* reads an integer; stores into i */ The " %d" string tells scanf to read input that represents an integer; i is an int variable into which we want scanf to store the input. The & symbol is required when using scanf.

  15. Defining Constants When a program contains constants—values that don't change during execution— it is a good idea to give them names. Using a feature known as macro definition, we can name constants. # define is a preprocessor directive, just as #include is, so there is no semicolon at the end of the line. #define CUBIC_IN_PER_LB 166 When a program is compiled, the preprocessor replaces each macro by the value that it represents.

  16. Identifiers As we're writing a program, we'll have to choose names for variables, functions, macros, and other entities. These names are called identifiers. In C, an identifier may contain letters, digits, and underscores, but must begin with a letter or underscore. C is case-sensitive: it distinguishes between upper-case and lower-case letters in identifiers.

  17. Keywords In Standard C, the keywords in Table 2.1 have special significance to the compiler and therefore can not be used as identifiers. Table 2.1 - Keywords auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void default goto sizeof volatile do if static while

More Related