You are on page 1of 22

―LET US C‖ GETTING STARTED CHAPTER # 1 LECTURE # 1

Programming

The basic operations of a computer system form what is known as the computer’s instruction set. A computer program is just a collection of the instructions necessary to solve a specific problem. The approach or method that is used to solve the problem is known as an algorithm.

e.. . e.. must be converted or translated into binary for computer to implement it.Levels of Computer Languages    Low Level: at the level of the computer basic hardware.g. i.e.g. Assembler. in binary (0-1) format Computer can only execute a binary form of a program Intermediate Level: close to the computer but uses English words (or mnemonics). that is converted directly into binary High Level: at the level of the programmer using English words and clearly defined syntax..

then learn to combine these alphabets to form words. . The classical method of learning English is to first learn the alphabets used in the language.C-Language   There is close similarity between learning English language and learning C language. which in turn are combined to form sentences and sentences are combined to form paragraphs.

Programming   Learning C is similar and easier. numbers and special symbols are used in C. and finally how are these combined to form an instruction. . then how using them constants. Instead of straight-away learning how to write programs. variables and keywords are constructed. we must first know what alphabets. A group of instructions would be combined later on to form a program.

Programming .

Figure 1. .2 shows the valid alphabets.numbers and special symbols allowed in C. digit or special symbol used to represent information.The C Character Set   A character denotes any alphabet.

Like human memory the computer memory also consists of millions of cells. Variables and Keywords      The alphabets. A constant is an entity that doesn‘t change whereas a variable is an entity that may change. numbers and special symbols when properly combined form constants. . variables and keywords. The calculated values are stored in these memory cells.Constants. The results of all the calculations are stored in computers memory.

Constants. Variables and Keywords   To make the retrieval and usage of these values easy these memory cells (also called memory locations) are given names. . ―Named memory locations are known as variables‖.

Constants. since a memory location can hold only one value at a time. If we assign a new value 5 to the same memory location x earlier value 3 will be overwritten. Variables and Keywords   Example:3 is stored in a memory location and a name x is given to it. .

Against this. Variables and Keywords   The location whose name is x can hold different values at different times x is known as a variable. . hence are known as constants. 3 or 5 do not change.Constants.

Types of C Constants    C constants can be divided into two major categories: (a) Primary Constants (b) Secondary Constants .

It can be either positive or negative. It must not have a decimal point. No commas or blanks are allowed within an integer constant. If no sign precedes an integer constant it is assumed to be positive. The allowable range for integer constants is -32768 to 32767. .Rules for Constructing Integer Constants       An integer constant must have at least one digit.

For a 32bit compiler the range would be even greater. For a 16-bit compiler like Turbo C or Turbo C++ the range is –32768 to 32767.Rules for Constructing Integer Constants   Truly speaking the range of an Integer constant depends upon the compiler. .

e. o and 1) .Compiler  Compiler : A special computer program that translates the statements of the program in the higher-level language into a form that the computer can understand (i.

Till that time it would be assumed that we are working with a 16-bit compiler. what range of an Integer constant has to do with the type of compiler and such questions are discussed in detail in Chapter 16.Rules for Constructing Integer Constants   What exactly do you mean by a 16-bit or a 32bit compiler. .

Rules for Constructing Integer Constants      Examples: 426 +782 -8000 -7605 .

. It could be either positive or negative. Default sign is positive. Following rules must be observed while constructing real constants expressed in fractional form: A real constant must have at least one digit. The real constants could be written in two forms—Fractional form and Exponential form. It must have a decimal point.Rules for Constructing Real Constants        Real constants are often called Floating Point constants.

5792 .Rules for Constructing Real Constants      Ex.: +325.76 -48.34 426.0 -32.

Following rules must be observed while constructing real constants expressed in exponential form: The mantissa part and the exponential part should be separated by a letter e. Default sign of mantissa part is positive.constructing real constants expressed in exponential form      In exponential form of representation. . the real constant is represented in two parts. The part appearing before ‗e‘ is called mantissa. whereas the part following ‗e‘ is called exponent. The mantissa part may have a positive or negative sign.

2e-5 .2e+3 -3.constructing real constants expressed in exponential form        The exponent must have at least one digit. which must be a positive or negative integer.4e38 to 3.2e-5 4.4e38. Range of real constants expressed in exponential form is -3. Default sign is positive. Ex.1e8 -0.: +3.

Rules for Constructing Character Constants         A character constant is a single alphabet.: 'A' 'I' '5' '=' . Both the inverted commas should point to the left. For example. ‘A‘ is a valid character constant whereas ‗A‘ is not. Ex. The maximum length of a character constant can be 1 character. a single digit or a single special symbol enclosed within single inverted commas.