Lesson 3

Cards (36)

  • C Compiler Pre-Processor The use of #define and #include
  • The C compiler has a preprocessor built into it.
  • Lines that begin with a # are called preprocessing directives.
  • The #define-line can occur anywhere in a program. It affects only the lines in the file that come after it.
  • The identifier LIMIT and PI are called symbolic constants.
  • The use of symbolic constants in a program makes it more readable.
  • More importantly, if a constant has been defined symbolically by means of #define facility and used throughout a program, it is easy to change later, if necessary.
  • The # include – (commonly known as macro include) is a preprocessing directive that causes a copy of the file to be included at this point in the file when compilation occurs. A #include line can occur anywhere in a file, though it is typically at the head of the file. The quotes surrounding the name of the file are necessary.
  • An include file, is also called “header file”, can contain # define lines and other #include lines. By convention, the names of header files end in .h.
  • The C system provides a number of standard header files. For example, stdio.h, string.h and math.h. These files contain the declarations of functions in the standard library, macros, structure templates and other programming elements that are commonly used.
  • The function printf() is used for output. The “f” in printf() stands for “formatted”. Technically, these functions are not part of the C Language, but rather are part of the C system. They exist in a library and available for use whenever a C system resides.
  • ANSI C has introduced a new and improved kind of function declaration called function prototype. This is one of the most important changes introduced into the language by ANSI C.
  • Both printf() and scanf() are passed as list of arguments that can be though of as control string and other arguments where Control string is a string and may contain conversion specifications or formats.
  • A conversion specification begins with a percent character (%) and ends with a conversion character.
  • %c as a character
  • %d as a decimal integer
  • %e as a floating point number in scientific notation
  • %f as a floating point
  • %lf as double
  • %g in the e-format of f-format which ever is shorter
  • %s as a string
  • When an argument is printed, the place where it is printed is called field and the number of characters in its fields is called its field width. The field width can be specified in a format as an integer occurring between the percent character (%) and the conversion character.
  • The function scanf() is analogous to the function printf() but is used for input rather than output.
  • C programs consists of one or more “functions,” which are the basic modules of a C program. This program consists of one function called main.
  • You can use the symbols /* and */ to enclose comments.
  • All statements in C program should be terminated with a semicolon.
  • gets() This function takes the name of the string as an argument and reads characters from the keyboard until ENTER key is pressed. ENTER key is not stored byte is replaces be the null terminator.
  • getche() reads a character without echo. Does not wait for carriage return or ENTER key.
  • getch() reads a character with echo. Does not wait for carriage return or ENTER key.
  • getchar() reads a single individual character from the keyboard and waits for the carriage return or ENTER key.
  • puts() writes a string to the screen, followed by a newline. It can only output a string of characters. It cannot output numbers or do format conversion. It takes up less space and run faster.
    1. C Compiler Pre-Processor The use of #define and #include
  • The C compiler has a preprocessor built into it. Lines that begin with a # are called preprocessing directives.
  • The #define-line can occur anywhere in a program. It affects only the lines in the file that come after it.
  • The identifier LIMIT and PI are called symbolic constants. The use of symbolic constants in a program makes it more readable.
  • The # include – (commonly known as macro include) is a preprocessing directive that causes a copy of the file to be included at this point in the file when compilation occurs.