C Language

C Language

  1. INTRODUCTION:
    • C is a high-level and general-purpose programming language that is ideal for developing firmware or portable applications. Originally intended for writing system software.
    • C was developed at Bell Labs by Dennis Ritchie for the Unix Operating System (OS) in the early 1970s.
    • In the late seventies C began to replace the more familiar languages of that time like PL/I, ALGOL, etc
    • No one pushed C. It wasn’t made the ‘official’ Bell Labs language.
    • Thus, without any advertisement C’s reputation spread and its pool of users grew.
    • Ritchie seems to have been rather surprised that so many programmers preferred C to older languages like FORTRAN or PL/I, or the newer ones like Pascal and APL. But, that's what happened.

  2. GETTING STARTED:
    • The C Character Set:
    • A character denotes any alphabet, digit or special symbol used to represent information.

    • Constants, Variables and Keywords:
      • The alphabets, numbers and special symbols when properly combined form constants, variables and keywords. Let us see what are ‘constants’ and ‘variables’ in C. A constant is an entity that doesn’t change whereas a variable is an entity that may change.
      • In any program we typically do lots of calculations. The results of these calculations are stored in computers memory. Like human memory the computer memory also consists of millions of cells. The calculated values are stored in these memory cells. To make the retrieval and usage of these values easy these memory cells (also called memory locations) are given names. Since the value stored in each location may change the names given to these locations are called variable names. Consider the following example.
      • Here 3 is stored in a memory location and a name x is given to it. Then we are assigning a new value 5 to the same memory location x. This would overwrite the earlier value 3, since a memory location can hold only one value at a time.
      • Since the location whose name is x can hold different values at different times x is known as a variable. As against this, 3 or 5 do not change, hence are known as constants.
      • Types of C Constants:
      • C constants can be divided into two major categories:
        1. Primary Constants
        2. Secondary Constants
      • These constants are further categorized as shown below

    • C Keywords:
      • Keywords are the words whose meaning has already been explained to the C compiler (or in a broad sense to the computer). The keywords cannot be used as variable names because if we do so we are trying to assign a new meaning to the keyword, which is not allowed by the computer. Some C compilers allow you to construct variable names that exactly resemble the keywords. However, it would be safer not to mix up the variable names and the keywords. The keywords are also called ‘Reserved words’.
      • There are only 32 keywords available in C.

  3. THE FIRST C PROGRAM:
    • The "hello, world" example, which appeared in the first edition of K&R, has become the model for an introductory program in most programming textbooks, regardless of programming language. The program prints "hello, world" to the standard output, which is usually a terminal or screen display.
    • The original version was:
    • main()
      {
          printf("hello, world\n");
      }
       
    • A standard-conforming "hello, world" program is:
    • #include <stdio.h>
      
      int main(void)
      {
          printf("hello, world\n");
      }
       

  • Share: