2. Introducing of C
• C is a programming language
developed at AT & T Bell Laboratories
of USA in 1972, designed and written
by Dennis Ritchie.
• C is highly portable i.e., software
written for one computer can be run
on another computer.
• An important feature of C is its ability
to extend itself. A C program is basically
a collection of functions.
3. Reasons to use C
• Easy to learn & write programs.
• Structured language.
• Many common programs are written in C.
• Programs that are created with C run very quickly.
• It allows you direct control over the very low level aspects of the
computer.
• It was (and still is in some circumstances) the language of choice in
Operating System Development (including all of Unix).
4. Facts about C
• C was invented to write an operating system called UNIX.
• C is a successor of B language which was introduced around the early 1970s.
• The language was formalized in 1988 by the American National Standard
Institute (ANSI).
• The UNIX OS was totally written in C.
• Today C is the most widely used and popular System Programming Language.
• Most of the state-of-the-art software have been implemented using C.
• Today's most popular Linux OS, Oracle and RDBMS MySQL have been written
in C.
5. History of C
Year Language Developed by Remarks
1960
ALGOL 60 (Algorithmic
Language)
International Committee Too general, too abstract
1963
CPL (Combined
Programming Language)
Cambridge University
Hard to learn, difficult to
implement
1967
BCPL (Basic Combined
Programming Language)
Martin Richards at Cambridge
University
Could deal with only specific
problems
1970 B Ken Thompson at AT & T Bell Labs
Could deal with only specific
problems
1972 C Dennis Ritchie in AT & T Bell Labs Structured Programing
Martin Richards Ken Thompson Dennis Ritchie Ken Thompson & Dennis Ritchie
6. What is Computer Programming
• A computer program is just a collection of the instructions
necessary to solve a specific problem.
• A program is a set of instruction that tell a computer what to
do.
• Computer Programming is the process of creating computer
programs.
• A program is creating using a programming language.
• A programming language is a language that can be used to
communicate with a computer.
• So for as programming language concern these are of two
types.
1) Machine Oriented (Low/Middle level language)
2) Problem Oriented (High level language)
But C is considered as a Middle level Language. C is modular,
portable, reusable.
7. Getting Started with C
Steps in learning English language:
Steps in learning C:
Alphabets Words Sentence Paragraphs
Alphabets, Digits &
Special Symbols
Constants, Variables &
Keywords Instructions Program
8. C Tokens
• A token is an atomic unit (smallest invisible units) in a
program.
• The most basic elements in a C program recognized by the
compiler are a single character or a group of characters called
C tokens.
• The compiler cannot breakdown the token any further. For
example, the words main, ‘{’ (brace), ‘(’ (parenthesis) are all
tokens of C program.
10. The C Character Set
The C character set includes the upper case letters A to Z, the
lower case a to z, the decimal digits 0 to 9 and certain special
characters.
Alphabets
Digits
Special Symbols
A, B, C,…,X, Y, Z
A, b, c,…,x,y,z
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
~ ! @ # % ^ & * ( ) _ - + = | { } [ ] ; :
“ ‘ < > , . ?/
11. Special Symbols
Character/ Symbol Meaning Character/ Symbol Meaning
~ Tilde , Comma
. Period ; Semicolon
? Question mark : Colon
“ Double quote ‘ Single quote
( Left parenthesis ) Right parenthesis
[ Left bracket ] Right bracket
{ Left brace } Right brace
/ Slash Back slash
< Less than > Greater than
= Equal to ! Exclamatory mark
- Minus + Plus
# Hash $ Dollar sign
& Ampersand * Asterisk
% Percent ^ Carat
_ Underscore | Vertical bar
12. Identifiers in C
• Identifiers are the name used to identify a constant, variable, function, or any other
user defined item.
• An identifier starts with a letter A to Z, a to z, or an underscore ‘_’ followed by zero
or more letters, underscores, and digits (0 to 9).
• No commas or blank space are allowed within a variable name.
• C does not allow punctuation characters such as @, $, and % within identifiers.
• C is a case-sensitive programming language. Thus, Manpower and manpower are
two different identifiers in C.
Mohd zara abc move_name a_123
Myname50 _temp j a23b9 retVal
13. Keywords in C
• Keywords are predefined tokens in C. These are also called reserved words.
• Keywords have special meaning to the C Compiler. These keywords can be used only
for their intended action; they cannot be used for any other purpose.
• C has 32 keywords.
auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
contiune for signed void
default goto sizeof volatile
do if static while
14. Data Types
•A data type defines a set of values and the operations
that can be performed on them.
•Every datatype item (constant, variable etc.) in C
program has a datatype associated with it.
•C also has a special datatype called void, which,
indicates that any data type, i.e., no data type, does not
describe the data items.
15. Primitive Data Type
auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
contiune for signed void
default goto sizeof volatile
do if static while
16. Primitive Data Type
Data types Description Size (No. of Bytes) Range
Char Single Character 1 0 to 255
Int An Interger 2 -32,768 to +32,767
Float Float point number 4
-2,147,483,648 to
+2,147,483,647
Double Float point number 8
Approx. 15 digits of
Precision
Void No data type 0
Signed char Character 1 -128 to 127
Unsigned char Unsigned character 1 0 to 255
Short signed int Short signed integer 2 -32,768 to +32,767
Short unsigned int
Short unsigned
interger
3 0 to 65,535
Long singned int Long signed integer 4
-2,147,483,648 to
+2,147,483,647
17. Constants in C
A constant is a literal, which remain unchanged during the execution of
a program.
A constant is a fixed value that cannot be altered during execution of
program.
C constants can be classified into two categories:
Primary Constants Secondary Constants
Integer Constants Array
Real Constants Pointer
Character Constants Structure
Union
Enum
18. Rules for Construction Integer Constants
An integer constant must have at least one digit.
It should not contain either a decimal point or exponent.
If a constant is positive, it may or not be preceded by a plus sign. If it is
a negative, it must be preceded by minus sign.
Commas, blanks and non-digit characters are not allowed in integer
constants.
The value of integer constant cannot exceed specified limits.
The valid range is
-32,768 to +32,767
19. Real Constants
Real values are often called floating-point constants. There are two
ways to represent a real constant decimal form and 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.
20. Rules for Construction Real Constants
The mantissa part and the exponential part should be separate by a
letter ‘e’.
The mantissa part may have a positive or negative sign.
Default sign of mantissa part is positive.
The exponent must have at least one digit, which must be a positive or
negative integer. Default sign is positive.
Range of real constants expressed in exponential form is
-3.4e38 to 3.4e38.
21. Rules for Construction Character Constants
A character constant is a single alphabet, a single digit or a single
special symbol enclosed within single inverted commas. Both the
inverted commas point to the left. For example, ‘A’ is valid charcter
constant whereas A is not.
The maximum length of a character constant can be 1 character.
Note: Every character has its ASCII (American Standard Code for
Information Interchange) value. That means every character is
interchange with integer constant. For example, ‘A’ value is 65 and ‘a’
value is 97.
22. String Constants
A string constant is a sequence of character enclosed in double quotes.
The character may be letter, number, blank space or special character.
Note that “” is null string or empty string. And the single string
constant is “A” is not equivalent to the single character constant ‘A’.
Each String constant must end with a special character ‘o’. This
character is called null character and used to terminate the string. The
compiler automatically places a null ‘o’ character at the end of every
string constant.
23. Escape sequence
Some non-printing characters and some other character such as double
quote (“), single quote (‘), question mark (?) and backslash (), required
an escape sequence. A list of commonly used backslash character
constants is given below:
Escape
Sequence
Meaning ASCII Value
Escape
Sequence
Meaning ASCII Value
a Bell 7 r Carriage return 13
b Back Space 8 ” Double quote 34
t Tab 9 ’ Single quote 39
n New line 10 ? Question mark 63
v Vertical tab 11 Back slash 92
f Form feed 12 0 Null 0
24. Variables in C
• A variable can be considered as a name given to the location
in memory.
• The term variable is used to denote any value that is referred
to a name instead of explicit value.
• A variable is able to hold different value during execution of a
program, where as a constant is restricted to just one value.
• For example, in the equation 2x+3y=10; since x and y can
change, they are variables, where as 2, 3 and 10 cannot
change, hence they are constants. The total equation is known
as expression.
25. Rules for Construction Variable Names
The name of a variable is composed of one to several characters, the
first of which must be a letter .
No special characters other than letters, digits, and underscore can be
used in variable name. Some compilers permit underscore as the first
character.
Commas or Blanks are not allowed with in a variable name.
Upper case and Lower case letters are significant. That is the variable
“income” is not same as “INCOME”.
The variable name should not be a C key word. Also it should not have
the same name as a function that is written either by user or already
exist in the C library.
26. C Instructions
There are basically four types of instructions in C:
Type Declaration Instruction
Input/Output Instruction
Arithmetic Instruction
Control Instruction
27. The purpose of each instructions
Type Declaration instruction To declare the type of variables used in
a C program
Input/Output instruction To perform the function of supplying
input data to a program and obtaining
the output results from it.
Arithmetic instruction To perform arithmetic operations
between constants and variables.
Control instruction To control the sequence of execution of
various statement in a C program.
28. Operations & Expressions
An operator is a symbol that tells the computer to perform
certain mathematical or logical manipulations.
Operators are used in program to manipulate data and
variables. The data items that operators act upon are called
operands.
Some operators require two operands, while others act upon
only one operand. The operators are classified into unary,
binary and ternary depending on whether they operate on
one, two or three operands respectively.
29. Types of operators
C has four classes of operators
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Bit-wise Operators
In addition, C has some special operators, which are unique to
C, they are
1. Increment & Decrement Operators
2. Conditional Operators
3. Assignment Operators, etc.
30. Arithmetic Operators
There are five arithmetic operators in C.
The following table lists the arithmetic operators allowed in C:
Operator Meaning
+ Addition
- Subtraction; also for unary minus
* Multiplication
/ Division
% Modulo division (remainder after integer division)
31. Structure of C Program
1. Documentation Section (Comment Line)
1. // Single line Comment
2. /* Multiple line Comment */
2. Link Section (Header files means Predefined Fuctions)
1. #include <stdio.h>
2. #include <conio.h>
3. #include <math.h>
4. #include <graphics.h>
32. Structure of C Program
3. Definition Section (Symbolic Constant)
1. #define MAX 50
4. Global Declaration Section (Global Variables)
1. PI= 3.14159,
2. A=10, B=20;
5. Main Function
1. Declaration Part (Local Variable)
2. Executable Part (Statements)
33. Structure of C Program
6. Sub-Program Section (User Defined Functions)
1. Function-1
2. Function-2
3. Function-3
4. Function-n
34. Structure of C Program
1. Comment line
2. Preprocessor directive
3. Global variable declaration
4. main function( )
{
Local variables;
Statements;
}
User defined function
{
}
35. First Program in C
#include<stdio.h> // standard input output header
#include<conio.h> // console input output header
main() // start of main function
{
clrscr(); // predefined function for clear screen
printf(“Hello World”); // predefined function for print
getch(); // for hold screen till user response
} // end of main function
Save the source file with extension filename.c