|
Next Page
1.1 Introduction
C was developed by Dennis Ritchie at the
Bell Laboratories in the early 1970s. C was initially used
for system programming. Operating Systems, Interpreters,
Editors, Assembly programs are usually called systems
programs. The Unix Operating System was developed using C.
There are C compilers available for all computers.
- C is a middle level language
- C is a structured language
- C allows compartmentalization of code & data.
1.2 The C Program Structure
C has very few keywords, 32 to be precise. Some rules,
which hold for all programs in C, are as follows:
- All keywords use lower case letters.
- C is case sensitive, India is different from INDIA.
- main() is always first function called.
main()
{
/* This is sample C program */
int a=0;
a = a + 1;
}
1.2.1 Function Definition
C programs divided into units called functions. The
sample code has only one function main(). The function name
is always followed by parenthesis. The parenthesis may
contain parameters.
1.2.2 Delimiters
The function definition is always followed by an open
curly brace({) and end with closing curly(})
brace. These curly braces are known as delimiters.
1.2.3 Statement Terminator
Semicolon (;) is known as Statement Terminator.
It is used for terminate any statement.
1.2.4 Comment Lines
/* and */ is known as comment lines in C
program. As in example.
1.3 The C Library
All C compilers provide a standard library
of functions that perform the common tasks. In some
implementations of C, the library exists in one large file
while in others it is contained a numerous small files .A
function written by a programmer can be placed in the
library and be used in programs as and when required.
1.4 Data Types in C
C has four basic data types.
- char type holds one character and occupies one byte
of space. (%c)
- int is an integer, typically representing the
natural size of integers. (%d)
- float and double are used for floating point
numbers. float occupies 4 bytes and can hold numbers with 6
digit of precision, whereas double occupies 8 bytes and can
hold numbers with ten digits of precision. (%f)
- void is also a data type which holds empty set of
values.
1.4.1 Modifiers used with Basic Types
- signed/unsigned type
- long/short type
1.5 Identifier Names
The name of variables, functions, labels,
and various other user defined objects are called
identifiers. The identifiers can contain one or more
characters. It is compulsory that the first character of the
identifier is a letter or an underscore. Identifiers are
also case sensitive.
1.6 Variables
Variables are the named location in memory
that are used to hold a value that may be modified by the C
program. Variable should be declared before they can be
used.
type variable_name;
where type is a valid data type and variable name is a valid
name.
1.7 Assignment Operator
variable_name = expression;
(=) is known as assignment operator and is used to assign a
value in to variable. For e.g
a = 2;
a = b = c = 2; (Multiple assignment)
1.8 Arithmetic Operators
Arithmetic operators are classified into
unary and binary operators.
1.8.1 Unary Operator
Unary operators work on only single
operand.
- Unary minus
++ Increment Operator
-- Decrement Operator
1.8.2 Binary Operator
Binary operators work on two operands.
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
1.9 Arithmetic Expressions
a * (b+c/d) * 22
++i % 7
1.9.1 Precedence of Operators
Unary - ++ -- Right to Left
Binary * / % Left to Right
Binary + - Left to Right
Binary = Right to Left
1.10 Relational & Logical Operators
> Greater than
<= Greater than or equal
< Less than
<= Less than or equal
== Equal
! = Not Equal
Logical Operators
&& AND
|| OR
! NOT
Next Page
|