C Programming
C Programming
History
• In 1972 Dennis Ritchie at Bell Labs writes C and in 1978 the
publication of The C Programming Language by Kernighan
& Ritchie caused a revolution in the computing world
Terminologies of ‘C’
1. Keywords
2. Identifiers
3. Variables
4. Constants
5. Special Symbols
6. Operators
7. Character & String
1. Keywords
arena, s_count
marks40
class_one
Some erroneous identifier names are -
X
1stsst
oh!god
start….end
An identifier cannot be the same as a C keyword
3. Variables
Example - c=a+b;
• Arithmetic Operators
– They are used to perform Mathematical operations between
2 or more operands.
– It includes:
• + [Addition]
• - [Subtraction]
• * [Multiplication]
• / [Division]
• % [Modulus]
• ++ [Increment Operator]
• -- [Decrement Operator]
Comparison Operators
• A comparison operator is a symbol used to compare two or
more operands.
• It includes:
– == [Checks if the value of two operands is equal or not, if yes then condition becomes
true.]
– != [Checks if the value of two operands is equal or not, if values are not equal then
condition becomes true.]
– > [Checks if the value of left operand is greater than the value of right operand, if yes
then condition becomes true.]
– < [Checks if the value of left operand is less than the value of right operand, if yes then
condition becomes true.]
– >= [Checks if the value of left operand is greater than or equal to the value of right
operand, if yes then condition becomes true.s]
– <= [Checks if the value of left operand is less than or equal to the value of right operand,
if yes then condition becomes true.]
Logical Operators
• A logical operator is a symbol used to connect two or more
operands.
• It includes:
– && [Called Logical AND operator. If both the operands are non zero then
only condition becomes true.]
– | | [Called Logical OR Operator. If any of the two operands is non zero then
then condition becomes true.]
– ! [Called Logical NOT Operator. Use to reverse the logical state of its
operand. If a condition is true then Logical NOT operator will make false.]
7. Character & String
• The Characters can be used to form words, numbers
and expressions.
• The characters in C are grouped into the following
categories :
– Letters
– Digits
– Special characters
– White Spaces
• Remember that a character ‘a’ is not equivalent to the
string “a”.
Why use C?
• Mainly because it produces code that runs nearly as fast as
code written in assembly language. Some examples of the use
of C might be:
– Operating Systems
– Language Compilers
– Assemblers
– Text Editors
– Video Games
– Network Drivers
– Modern Programs, etc.
Why C Still Useful?
• C provides:
Efficiency, high performance and high quality
flexibility and power
many high-level and low-level operations middle level
Stability and small size code
Provide functionality through rich set of function libraries
Gateway for other professional languages like C C++ Java
• C is used:
System software Compilers, Editors, embedded systems
Also used in application programs.
A simple Program of C
/* Write a program to print a message */
#include<stdio.h>
#include<conio.h>
void main()
{
printf(“ C Programming”);
getch( );
}
Comment about the program should be enclosed within ‘/*’ &
‘*/’.
printf() is a function which is used to print messages on the
screen.
main() is a function from which execution of the program
starts.
Here stdio.h is a library file which contains standard
input/output functions , keywords etc.
#include< > is used to define the library file that is to be used
in the program for compiler information.
Escape Sequence
• \n new line
• \t tab
• \r carriage return
• \a alert
• \\ backslash
• \” double quote
Control FLOW Statements
• Simple If statement.
• If…..else statement.
• Else if ladder.
Simple if statement
if (test-expression)
{
statement-block;
}
If….Else statement