Posts

Showing posts from March, 2023

Constants in C

Image
  Constants in C Constants are fixed values, which do not change during the execution of a program. C supports several types of constants, which are as shown below:     Contents  [ hide ] 1  Integer Constants 2  Real Constants 3  Single Character Constants 4  String Literals or String Constants 5  Escape Sequences Integer Constants   An integer constant refers to a sequence of digits. Generally in programs, the number systems used are: decimal, octal and hexadecimal. Decimal integers consists of umbers from 0 to 9, preceded by an optional + or – sign.   Some valid examples of decimal integer constants are: 133, +45, -15, 0, 342332 etc. Embedded spaces and non-digit characters are cannot be used between digits.   An octal integer consists of numbers from 0 to 7. Octal integer numbers are always preceded by a zero. For example if we have to represent 35 in octal system, we must write it as 035 in the program. Some valid examples of octal integer constants are: 035, 02, 0435, +025 etc.  

C Tokens

Image
  C Tokens Contents   [ hide ] 1  Introduction 2  Character Set 3  C Tokens 3.1  Keywords 3.2  Identifiers Introduction   A programming language is designed to help process certain kinds of data consisting of numbers, characters and strings and to provide useful output known as information.   The task of processing data is achieved by writing instructions. These set of instructions is known as a program. Programs are written using words and symbols according to the rigid rules of the programming language known as syntax.     Character Set   The characters that can be used to form words, numbers and expressions depend upon the computer on which the program is run. The characters in C, are grouped into the following four categories: 1) Letters 2) Digits 3) Special Characters 4) Whitespaces   The compiler ignores the white spaces unless they are part of the string constants. White spaces are used to separate words from each other, but they cannot be used in between the characters of keywo

Structure of a C Program

Image
  Structure of a C Program Every program written in C follows a certain structure. That structure is as shown below:       Contents  [ hide ] 1  Documentation Section 2  Link Section 3  Definition Section 4  Global Declaration Section 5  main() Function Section 6  Subprogram Section 7  Example: HelloWorld Program Documentation Section   The documentation section is used to improve the readability and to understand various elements in the program. This section is used to provide help for the general users. This section consists of plain text written in English and includes information like author, purpose of the program, date on which the program was created etc. This section is included inside comments.   Example: /********************************* * Author: Name * Date: 7/10/2012 * Purpose: Theme of the program ********************************/   Link Section   The link section is used to include the external header files in which the pre-defined functions are available. To us
Image
  Creating and Running C Programs The steps for creating and running programs are: writing/editing, compiling, linking and execution. This can be viewed diagrammatically as shown below:     Writing/Editing:  The first step in creating programs is, writing or editing the program. A program can be written in any text editor like notepad. After writing a program, the program must be saved, In C language, the program is saved with the extension “.c”. This is the source program written in a high-level language.   Compilation:  After writing and saving the source program, the next step is compilation. Here we will use a software called as compiler, which converts a program written in high-level language into machine language. The resultant file is known as an object file in C. The extension of that file is “.obj”.   Linking:  After compilation the next step is linking. Here software called linker is used. The linker links the program with external library files which contains the code for pr