Brief introduction to C Language:-
Languages like B, Combined Programming Language (CPL) and Basic CPL were used popularly.
The B language used earlier was added with basic functionality of BCPL to create C language.
Dennis Ritchie developed C in 1972 while working with Bell Laboratories.
C was developed on unix operating system.
UNIX operating system was re-written using the C language.
When UNIX was re-written, only a part of the original assembly language was retained.
Most universities used UNIX and this helped make C a popular language among students.
To avoid compatibility problems arising from the variations of C language developed by different companies, ANSI set the guidelines for standardising C. This is called ANSI C.
Applications of C Language:-
- The most popular example of C application is the re -creation of UNIX operating system.
- C is used to develop compilers, interpreters, graphic and general utilities.
- C has been used in the development of various databases, word processors and spread sheets.
- Power and flexibility has prompted the use of C language in the development of custom – made applications like railway ticket vending machines and applications in the banking and insurance sector.
There are four files associated when a C program is compiled
1. Source code – with ‘.c’ as the extension. It is the file where the program instructions are written.
2. Header File – contains the declaration of functions and the pre-processor commands. It has ‘.h’ as its extension.
3. Object Files – these are the files created by the compiler and have a extension either as ‘.o’ or ‘.obj’.
4. Binary Executables – output from the linking process. The extension of these files is ‘.exe’.The linker is a program that collects all the related object files and creates an executable file.
1. Source code – with ‘.c’ as the extension. It is the file where the program instructions are written.
2. Header File – contains the declaration of functions and the pre-processor commands. It has ‘.h’ as its extension.
3. Object Files – these are the files created by the compiler and have a extension either as ‘.o’ or ‘.obj’.
4. Binary Executables – output from the linking process. The extension of these files is ‘.exe’.The linker is a program that collects all the related object files and creates an executable file.
Constants: A quantity or a value that does not change is called a constant.
There are two types of constants.
There are two types of constants.
- Integer
- Character
Rules for creating an Integer constants
- It needs at least one digit.
- No decimal point is present in an Integer constant
- It can be a positive or negative number.
- It does not have commas or blanks
- +31, 56, -75 are instances of Integer constants
Variable:-A value that can vary or can be altered during the execution of the program or instruction is called a variable.
Points to remember when creating a variable:
- The length of the variable name should not exceed more than 8 characters.
- The variable name can be made up of A- Z, a-z, 0-9 or underscores ( _ ), and combination of all these can also be used to create a variable name.
- Precaution should be taken that variable name must begin with an alphabet.
- Special characters (%, # ), commas and blanks are not allowed in variable names.
Syntax to create a variable : int a, b, c; [three variables of integer type]
Data Types in C Language:
- int [Integer]
- char [character or string]
- float [floating point numbers]
- double [double values]
Operators :- C has a powerful set of operators, Combination of operators and operands in a statement is called an expression.
Operands can be either variables or constants.
An expression must result in a value.
Types of operators are :
- Arithmetic
- Assignment
- Relational
- Logical
- Arithmetic operators are the basic mathematical operators used for addition, subtraction, multiplication or division.
- An order of precedence is followed when these operators are applied together in an expression.
- sizeof operator returns the size occupied by the variable.
getChar() and putChar():- getchar() function reads a character entered from the keyboard.
The function automatically echoes the character entered.
Tab or Esc keys are considered to be valid inputs using this structure.
putchar() function prints the argument passed on to the screen.
Operator Precedence:-
Name Operator
Parentheses
|
()
|
Increment/Decrement
|
++/–
|
Multiplication
Division
Modulus
|
*
/
%
|
Addition
Subtraction
|
+
–
|
Less than
Less than or equal to
Greater than
Greater than or equal to
|
<
<=
>=
>
|
Equal to
Not equal to
|
==
!=
|
Logical AND
Logical OR
Logical !
|
&&
||
!
|
Assignment Operator
|
= += *= /= -=
|