C programming language – Introduction6 min read

History of C programming

The C programming language was invented in 1972 by Dennis Ritchie, a system programmer at AT&T’s Bell Laboratories of the United States. It grew out of two previous languages, BCPL (Basic Combined Programming Language) by Martin Richards and Ken Thomson, and B language, which was also developed at Bell Laboratories.

Applications of C programming language

  • ‘C’ is a programming language, suitable for writing an operating system that manages the input device and output device of a computer, allocates its storage, and schedules the running of other programs.
  • Portability is one of the major reasons for the increasing use of ‘C’ in commercial software.
  • The programs that are written in ‘C’ utilize the power of preprocessor directives and control/branching statements.
  • The ‘C’ programming language is designed to support structured programming techniques.
  • ‘C’ language is relatively simple and orderly. Hence ‘C’ compiler can make to run on a small computer.
  • ‘C’ language is Middle Level and Free-form Language. Generally, all programming languages can be divided into 2 categories,
    1. Problem-oriented or High-Level Language (HLL).
    2. Machine-oriented or Low-Level Language.
  • The ‘C’ language possesses the powerful low-level features of 2nd generation language like pointers, memory allocation, bit manipulation, etc. It also supports conditional constructions, loop constructions, a rich list of operators, and a variety of data structures as in 3rd generation language.
  • These features of the C language make it possible to use the language for system programming like the development of compiler, interpreter, operating system, graphics, and general utilities.
  • The ‘C’ language was designed to have both relatively good programming and relatively good machine efficiency, and therefore, it is referred to as a Middle-level Language. Many databases, word processors, spreadsheets, and software are written in the ‘C’ language, as is the majority of the code for the UNIX operating system. Because there are no specific rules for the position at which different parts of a program statement must be written in the ‘C’ language, it is frequently referred to as a free-form language or Format Free language.
  • ‘C’ is classified as 3rd generation language and is more procedural in nature. A program in 3rd generation language (3GL) implements a step-by-step algorithm to solve the problem.
  • ‘C’ language is also called block-structured language due to its compound statement structure. A compound statement is a sequence of two or more statements enclosed between pair of braces { } and is usually called a block.

C programming basics

Keywords

Keywords are those words that have a significant meaning to the compiler and cannot be used as a variable or identifier name. C Supports a total of 32 reserved words as shown below –

Keywords
autobreakcasechar
constcontinuedefaultdo
doubleelseenumextern
floatforgotoif
intlongregisterreturn
shortsignedsizeofstatic
structswitchtypedefunion
unsignedvoidvolatilewhile
Keywords in C programming

Operators

An operator is a symbol that tells the compiler to perform specific mathematical or logical functions. C language is rich in built-in operators and provides the following types of operators –

SymbolDescription
+Addition
Subtraction
*Multiplication
/Division
%Mod Operator
<Less than
>Greater than
=Equal to
!=Not equal to
~Complement Operator
Operators in C language

If you want to learn more about “C” Operators in detail, click here.

Data types

  • The data type tells the program what kind of data the variable stores.
  • The memory of the computer is simply a group of bits, during any operation; a bit in memory is a combination of O’s and 1’s.
  • A byte is an 8-bit group. All the data must be stored in computer memory but it is difficult for a programmer to remember the memory address or location hence every high language provides a data type to store the kind of value in a variable so that it can access the address of memory instead of remembering address or location.

Thus a data type specifies,

  • What amount of memory is required?
  • What kind of value (Numeric, Character, etc) it can hold?
  • Range of data value.
  • And most important, it helps the compiler to check compatibility and legality during computation.

Data types are classified into different categories as shown in the fig, below,

Data types in C programming language
Data types supported in c programming

C-Statements

A statement in a computer program carries out some action. We can categorize C-Statements into the following types

  1. Simple Statements
  2. Compound Statements
  3. Type Declaration Statements
  4. Assignment Statements
  5. I/O Statements
  6. Flow Control Statements

Types of Statements

  1. Simple Statements: A simple statement consist of any statement followed by a semicolon (;)
    • Example:
      • a = 7;
      • b = a + 6;
  2. Compound Statements: Compound statements or statement blocks are created when a group of statements is enclosed by a pair of left and right curly braces {}. All user-defined functions are basically a compound statements.
  3. Type declaration Statements: Declaring variables before using them.
  4. Assignment Statements: Assigning different constants or assigning expression results.
  5. Input/output Statements: Accepting the data from the user through the keyboard or data file and displaying the useful result on the screen.
  6. Flow-Control Statements: Flow control statements are statements that cause the execution of another statement to change.

Variable

A variable is an entity whose value may change during the execution of a program. When the compiler encounters a variable declaration, a well-defined location in memory is reserved under that name.

Like constants, variables can be declared as integer, real, character, etc. Thus if the variable is of integer type then the corresponding memory location can accommodate only integer value. The term “scalar variable” refers to a variable that has only one value. The rules for naming variables are the same as that of identifiers i.e. –

  1. A variable must start with an alphabet or underscore ( ).
  2. While declaring a variable, no special characters except ‘_’ i.e. underscore are allowed.
  3. There must be at least one character or number associated with an underscore character in order for a variable to exist.
  4. A variable name should not be a reserved word or standard function name.
  5. The length of variables is compiler-dependent.
  6. Variables are case sensitive i.e. Upper and lowercase letters are distinct.

Declaration of a variable

Before using a variable in a program, it is necessary to instruct the compiler about the type of that variable i.e. all variables must be declared before their use. A variable is said to be declared when we indicate the following,

  1. The name of the variable and
  2. It’s type specifier i.e. data type.

SYNTAX :- Storage_Class Data_Type Variable List(s);

Here, Storage_class can be auto, register, static or extern. When storage class is not specified then by default variables are of type storage class auto. The data type may be one of the basic or derived data types. The variable list consists of one or more variable names each separated from the next one by comma (,). Finally, the declaration statement must be terminated with a semi-colon (;)

Example:

  • char name[20];
  • char sex;
  • unsigned long;
  • int principal_amount;
  • short int year;
  • float rate, simple_interest;

Download Turbo C++


Share:

Leave a Reply