SlideShare a Scribd company logo
1 of 55
Download to read offline
Basics of C Programming
C. P. Divate
Features of C Language
C is the widely used language. It provides many features that are given below.
• Simple
• Machine Independent or Portable
• Mid-level programming language
• structured programming language
• Rich Library
• Memory Management
• Fast Speed
• Pointers
• Recursion
• Extensible
• Rich set of controlling statements
• Rich sent of Operators
Ares of C Language
C is the widely used language. It is used to develop sofwares in following
areas,
• Scientific Application
• Environmental Application
• Mathematical calculations
• Embedded Systems
• Space satellite Application
• Data Structure Application
• Computer Graphics Application
• Computer Network Applications
History of C Language
• Dennis Ritchie - founder of C language
• C programming language was developed in 1972 by
Dennis Ritchie at bell laboratories of AT&T (American
Telephone & Telegraph), located in the U.S.A.
• Dennis Ritchie is known as the founder of the c
language.
History of C Language
Language Year Developed By
Algol 1960 International Group
BCPL 1967 Martin Richard
B 1970 Ken Thompson
Traditional C 1972 Dennis Ritchie
K & R C 1978 Kernighan & Dennis Ritchie
ANSI C 1989 ANSI Committee
ANSI/ISO C 1990 ISO Committee
C99 1999 Standardization Committee
Let's see the programming languages that were developed before C language.
Structure Of a C Program Example Of C Program structure
My First C Program
#include <stdio.h>
int main()
{
printf("Hello C Language");
return 0;
}
Execution of First C Program
Comments in C Language
• Comments are non Executable statements in c program.
• C introduces a new comment symbol // (double slash). Comments start with a
double slash symbol and terminate at the end of line.
• A comment may start any where in the line and what ever follows till the end of line
is ignored.
• Note that there is no closing symbol.
• The double slash comment is basically a single line comment. Multi line comments
can be written as follows:
// this is an example of
// c++ program
// thank you
• The c comment symbols /* ….*/ are still valid and more suitable for multi line
comments.
/* this is an example of c++ program */
Steps in C Language study
Let's see the programming languages that were developed before C language.
Steps in C Language study
Let's see the programming languages that were developed before C language.
Token
1) Character set in C Language
1) Characters Used in C Programs
• Lowercase letters
• a b c . . . z
• Uppercase letters
• A B C . . . Z
• Digits
• 0 1 2 3 4 5 6 7 8 9
• Other characters
• + - * / = ( ) { } [ ] < > ‘ “
• ! @ # $ % & _ ^ ~  . , ; : ?
• White space characters
• blank, newline, tab, etc.
2) The Six Kinds of Tokens / Words in C
1) Keywords
2) Constants / Literals
3) Identifiers - variables / function / structure / array name
4) Statements/ Instructions – e.g. scanf, printf, getch etc.
5) Operators - +, -, * etc.
6) Punctuators - , : “ ‘ . ! ? % etc.
• The smallest individual units/words in program are known as tokens.
• C has the following Six different types of tokens.
2) Tokens / words in C Language
2.1) KEYWORDS :
 Keywords are C tokens that have a strict meaning in c language to perform certain tasks.
 They are explicitly reserved words and can’t be used as names for the program variables or other
user defined program elements.
 ANSII C has 32 key words.
 Some implementations such as Borland’s C or Microsoft’s C have additional key words.
auto do goto signed unsigned
break double if sizeof void
case else int static volatile
char enum long struct while
const extern register switch
continue float return typedef
default for short union
What is a Constant?
 Constant is a value (an entity) whose value cannot change throughout the
execution of a program,is known as constants.
 Like variables constants have data types.
2) Tokens / words in C Language
2.2) Constants / Literals :
1) Using const keyword
const data_type <variable_name>=<val>;
(or)
data_type const <variable_name>=<val>;
2) Using Define preprocerssor
#define <variable> <Value>
Syntax (Grammar) Example
const int x = 10;
int const x = 10;
#define PI 3.14
Types of Constants in C
2) Tokens / words in C Language
2.2) Constants / Literals :
 Integer constant - (complete / Whole Number)
 Real constant - (Fractional Number)
 Character Constant - (Single Letter)
 String Constant - (multiple letters)
2.2.1) Integer Constants
Decimal Constants Octal Constants Hexa-Decimal Constants
10 012 0xA
1024 02000 0x400
12789845 060624125 0xC32855
2) Tokens / words in C Language
2.2) Constants / Literals :
 In C language integer constant is a complete / Whole Number.
 integer constant are represented in one of following formats,
a) Decimal
b) octal (Value starts with 0)
c) or hexa-decimal number (Value starts with 0x).
 Integer constants are always positive until you specify a negative(-) sign.
Example Program
18
2) Tokens / words in C Language
2.2) Constants / Literals :
#include<stdio.h>
void main ( )
{
const int a = 10; //Decimal
int const b = 012; //Octal
const int c = 0xA; //Hexadecimal
printf(" %d t %d t %d ", a, b, c);
}
OUTPUT: 10 10 10
Representation Fractional form Exponential form Type
0 0.0 0.0e-10 or 0.0E-10 double
6.77 6.77 0.677e1 or 0.677E1 double
-6.0f -6.0 -0.6 e1 or -0.6E1 float
3.1415926536L 3.1415926536 0.31415926536 e1 long double
2.2.2) Real Constants
2) Tokens / words in C Language
2.2) Constants / Literals :
 In C language real constant is a fractional Number.
 We can represent the negative numbers in real constants.
 The default form of real constant is double and it must have a decimal
point.
 It may be in fractional form or exponential form.
 Ex: 3.45, -2.58, 0.3E-5 (equal to 0.3 x 10-5)
ASCII Character Symbol
Alert(bell) 'a'
Null character '0'
Backspace 'b'
Horizontal Tab 't'
New line 'n'
2.2.3) Character Constants
2) Tokens / words in C Language
2.2) Constants / Literals :
 Character Constants are in single letter form and must be enclosed with in
single quotes. e.g. ‘a’, ‘Z’, ‘1’, ‘4’, ‘&’, ‘%’,’#’ etc.
 We use escape character along with the character constants, followed by .
 The escape character says that it is not a normal character constants as they do
some tasks on user(output) screen.
ASCII Character Symbol
Vertical tab 'v'
Form Feed 'f'
Carriage Return 'r'
Single Quote '''
Double Quote '"'
21
2.2.4) String Constants
2) Tokens / words in C Language
2.2) Constants / Literals :
 A string constant is a sequence of characters enclosed in a double
quotes.
Examples:
 “ ” // Null String
 "programming9" // a full string with 12 characters
 "wel come" // string with 8 characters including space
 “Value= %d" // format string with 8 characters including space
 “a=%d n b=%d" // format string with 9 characters including space and
escape sequence character.
3) IDENTIFIERS:
 Identifiers refers to the name of variable, functions, array, structure etc. created by programmer.
 Variable is an entity in c program whose value can changes several time throughout the execution
of program.
 i.e. Variables are entities whose values can not remain constant in C program.
 Each language has its own rule for naming the identifiers. The following rules for naming the
identifiers in C and C++.
1. Identifier name should start with alphabet character or underscore _.
2. Other characters in identifier can be letters, digits and underscore are permitted.
3. A variable name should not consist of whitespace.
4. 'C' is a case sensitive language that means a variable named 'age' and 'AGE' are
different.
5. A variable name should not consist of a keyword.
6. It can have 8, 32 letter long in size.
7. It must be declared first (locally / Globally) before using in program.
3) Tokens / words in C Language
3) IDENTIFIERS:
 Following are the examples of valid variable names in a 'C' program:
3) Tokens / words in C Language
o height or HEIGHT
o _height
o _height1
o My_name
Following are the examples of invalid variable names in a 'C' program:
o 1height
o Hei$ght
o My name
o case
o switch
3) IDENTIFIERS:
 Following are the examples of valid variable names in a 'C' program:
3) Tokens / words in C Language
o height or HEIGHT
o _height
o _height1
o My_name
Following are the examples of invalid variable names in a 'C' program:
o 1height
o Hei$ght
o My name
o case
o switch
3) IDENTIFIERS:
3) Tokens / words in C Language
1) Declaration without initialization:
data_type <variable_name1> [,<variable_name2>, …… ] ;
2) Declaration with initialization:
data_type <variable_name1>=<val1> [,<variable_name2>=<val2>, …… ] ;
Declaration Syntax (Grammar)
1) Declaration without initialization:
int x;
float x,y,z;
2) Declaration with initialization:
int a=10;
float x=20, y=30, z=-40;
Declaration example
3) BASIC DATA TYPES IN C
3) Tokens / words in C Language
3) BASIC DATA TYPES IN C
3) Tokens / words in C Language
Tokens in C Language
3) BASIC DATA TYPES IN C
3) BASIC DATA TYPES IN C
3) Tokens / words in C Language
IDENTIFIERS BASIC DATA TYPES / DATA STRUCTURES IN C++
2.3) IDENTIFIERS:
3) Tokens / words in C Language
4) Tokens / Instructions(statements) in C Language
• Sequential execution means that each
command in a program script executes in the
order in which it is listed in the program.
• The first command in the sequence executes
first and when it is complete, the second
command executes, and so on.
4) Tokens / Instructions in C Language
4) Tokens / Instructions(statements) in C Language
C has following types of statement.
i) Variable Declaration Statements
ii) Assignment statements
• Initialization statement
• Arithmetical / Mathematical Statements
iii) Input Statements
iv) Selection (branching)
• if (expression) statement
• if (expression) else statement
• Nesting of if (expression) else statement
• if (expression) else ladder
• switch (expression) case statement
v) iteration (looping) statements
• while (expression){ block }
• for(expression ;expression ;expression){ block }
• do {block} while (expression);
vi) Output statements
vii) Normal / Abnormal termination statement;
viii) Null Statements
5) Tokens / Operators in C Language
• 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 −
5) Tokens / Operators in C Language
• Classification of Each Operators
Unary Operators Binary Operators
The operators which act upon a single
operand are called unary operators.
The operators which require two
operands for their action are
called binary operators.
Syntax
i) operator <operand>
ii) <operand> operator
Syntax
i) operand1 operator operand2
Example
i ++, j - -
++c
- 46
Example
a + b
x - 4
5) Tokens / Operators in C Language
• The following table shows all the arithmetic operators supported by the C language.
• Assume variable A = 10 and variable B = 20, then
5.1) Arithmetic Operators in c Language
Operator Description Example Result
+ Adds two operands. A + B 30
− Subtracts second operand from the first. A − B -10
* Multiplies both operands. A * B 200
/ Divides numerator by de-numerator. B / A 2
% Modulus Operator and remainder of after an integer division. B % A 0
++ Increment operator increases the integer value by one. A++ 11
-- Decrement operator decreases the integer value by one. A-- 9
5) Tokens / Operators in C Language
5.1) Classification of Arithmetic Operators in c Language
5) Tokens / Operators in C Language
• Program for Study of Arithmetic operators
5.1) Arithmetic Operators in c Language
#include <stdio.h>
main()
{
int a = 21;
int b = 10;
int c ;
c = a + b;
printf("Line 1 - Value of c is %dn", c );
c = a - b;
printf("Line 2 - Value of c is %dn", c );
c = a * b;
printf("Line 3 - Value of c is %dn", c );
c = a / b;
printf("Line 4 - Value of c is %dn", c );
c = a % b;
printf("Line 5 - Value of c is %dn", c );
c = a++;
printf("Line 6 - Value of c is %dn", c );
c = a--;
printf("Line 7 - Value of c is %dn", c );
}
Line 1 - Value of c is 31
Line 2 - Value of c is 11
Line 3 - Value of c is 210
Line 4 - Value of c is 2
Line 5 - Value of c is 1
Line 6 - Value of c is 21
Line 7 - Value of c is 22
Output
5) Tokens / Operators in C Language
• Priority / Precedence / Hierarchy of Arithmetic Operators in C
5.1) Arithmetic Operators in c Language
5) Tokens / Operators in C Language
• Priority / Precedence / Hierarchy of Arithmetic Operators in C Example
5.1) Arithmetic Operators in c Language
5) Tokens / Operators in C Language
• Priority / Precedence / Hierarchy of Arithmetic Operators in C Example
5.1) Arithmetic Operators in c Language
DATA INPUT AND OUTPUT INSTRUCTIONS IN C
 As we know that any c program is made up of 1 or more
then ONE standard function.
 Likewise it use some functions for input output
process. The most common function
 printf()
 scanf().
printf() Function
 printf() function is used to display something on the console or to display the value of
some variable on the console.
 The general syntax for printf() function is as follows
 printf(<”format string”>[,<list of variables>]);
 To print some message on the screen
 printf(“God is great”);
 This will print message “God is great” on the screen or console.
 Format specifiers in “format string” must match with respective variable
data type.
 Number of format specifiers must be equal to number of variables in list of
variables.
printf() Function
 To print the value of some variable on the screen
Integer Variable :
 int a=10;
printf(“%d”,a);
 Here %d is format string to print some integer value and a
is the integer variable whose value will be printed by
printf() function.
 This will print value of a “10” on the screen.
printf() function
• To print multiple variable’s value one can use printf() function in
following way.
int p=1000,n=5;
float r=10.5;
printf(“amount=%d rate=%f year=%d”,p,r,n);
• This will print “amount=1000 rate=10.5 year=5” on the screen
scanf() Function
• scanf() function is use to read data from keyboard and to
store that data in the variables during runtime.
• The general syntax for scanf() function is as follows.
scanf(“Format String”, &variable);
• Here format string is used to define which type of data it is taking as input.
• This format string can be %c for character, %d for integer
variable and %f for float variable.
• Format specifiers in “format string” must match with respective variable data
type.
• Number of format specifiers must be equal to number of variables in list of
variables.
scanf() Function
scanf(“Format String”, &variable1,…);
• Where as variable the name of memory location or
name of the variable
• and & sign is an operator that tells the compiler the
address of the variable where we want to store the
value.
scanf() Function
• For Integer Variable : int rollno;
printf(“Enter rollno=”);
scanf(“%d”,&rollno);
Here in scanf() function %d is a format string for integer variable and
&rollno will give the address of variable rollno to store the value at variable
rollno location.
• For Float Variable : float per;
printf(“Enter Percentage=”);
scanf(“%f”, &per);
• For Character Variable : char ans;
printf(“Enter answer=”);
scanf(“%c”, &ans);
/100
clrscr() function in C
• Function "clrscr" (works in Turbo C / C++ compiler only)
clears the screen and moves the cursor to the upper left-
hand corner of the screen.
• It is an output statement in c.
• Syntax:
void clrscr( );
• For Example
clrscr( );
getch() function in C
• getch() is a nonstandard function and is present in conio.h header file which
is mostly used by MS-DOS compilers like Turbo C.
• It is an input statement in c.
• Syntax:
int getch(void);
Parameters: This method does not accept any parameters.
Return value: This method returns the ASCII value of the key pressed.
For Example
int main()
{
int a;
a=getch();
printf("%c", a);
return 0;
}
Input: g (Without enter key)
Output: Program terminates immediately. But
when you use DOS shell in Turbo C, it shows a
single g, i.e., 'g'
Output with explanation
getch() function in C
• getch() method pauses the Output Console untill a key is pressed.
• It does not use any buffer to store the input character.
• The entered character is immediately returned without waiting for the enter
key.
• The entered character does not show up on the console.
• The getch() method can be used to accept hidden inputs like password, ATM
pin numbers, etc.
Single character input – the getchar () function :
• Single characters can be entered into the computer using the “C” library
function getchar.
• In general terms, a reference to the getchar function is written as.
character variable=getchar();
For example
char c;
c=getchar();
printf(“Given Character is:%c ”, c);
Single character output – The putchar function
• Single character can be displayed (i.e. written out of
the computer) using the C library function putchar.
• In general a reference to the putchar function is
written as
putchar (character variable);
• For Example
char c=’a’;
putchar(c);
RELATIONAL OPERATORS IN C:
• Relational operators are used to find the relation between two
variables. i.e. to compare the values of two variables in a C program.
Operator Description Example
== Checks if the values of two operands are equal or not. If yes, then the
condition becomes true.
(A == B) is not true.
!= Checks if the values of two operands are equal or not. If the values are
not equal, then the condition becomes true.
(A != B) is true.
> Checks if the value of left operand is greater than the value of right
operand. If yes, then the condition becomes true.
(A > B) is not true.
< Checks if the value of left operand is less than the value of right
operand. If yes, then the condition becomes true.
(A < B) is true.
>= Checks if the value of left operand is greater than or equal to the value
of right operand. If yes, then the condition becomes true.
(A >= B) is not true.
<= Checks if the value of left operand is less than or equal to the value of
right operand. If yes, then the condition becomes true.
(A <= B) is true.
Assume variable A holds 10 and variable B holds 20 then

More Related Content

Similar to Features and Fundamentals of C Language for Beginners

Similar to Features and Fundamentals of C Language for Beginners (20)

C programming Basics
C programming BasicsC programming Basics
C programming Basics
 
Cnotes
CnotesCnotes
Cnotes
 
C programming
C programmingC programming
C programming
 
Copy of UNIT 2 -- Basics Of Programming.pptx
Copy of UNIT 2 -- Basics Of Programming.pptxCopy of UNIT 2 -- Basics Of Programming.pptx
Copy of UNIT 2 -- Basics Of Programming.pptx
 
C prog ppt
C prog pptC prog ppt
C prog ppt
 
Aniket tore
Aniket toreAniket tore
Aniket tore
 
C programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer CentreC programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer Centre
 
Semester-1-22-23-Introduction_to_c_programming.ppt
Semester-1-22-23-Introduction_to_c_programming.pptSemester-1-22-23-Introduction_to_c_programming.ppt
Semester-1-22-23-Introduction_to_c_programming.ppt
 
C.ppt
C.pptC.ppt
C.ppt
 
Introduction_to_c_programming.ppt for software developing students
Introduction_to_c_programming.ppt for software developing studentsIntroduction_to_c_programming.ppt for software developing students
Introduction_to_c_programming.ppt for software developing students
 
C programming
C programmingC programming
C programming
 
2.Overview of C language.pptx
2.Overview of C language.pptx2.Overview of C language.pptx
2.Overview of C language.pptx
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptx
 
C introduction
C introductionC introduction
C introduction
 
UNIT 1 NOTES.docx
UNIT 1 NOTES.docxUNIT 1 NOTES.docx
UNIT 1 NOTES.docx
 
unit2.pptx
unit2.pptxunit2.pptx
unit2.pptx
 
Msc prev updated
Msc prev updatedMsc prev updated
Msc prev updated
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Msc prev completed
Msc prev completedMsc prev completed
Msc prev completed
 
introductory concepts
introductory conceptsintroductory concepts
introductory concepts
 

More from ChandrakantDivate1

Study of Computer Hardware System using Block Diagram
Study of Computer Hardware System using Block DiagramStudy of Computer Hardware System using Block Diagram
Study of Computer Hardware System using Block DiagramChandrakantDivate1
 
Computer System Output Devices Peripherals
Computer System Output  Devices PeripheralsComputer System Output  Devices Peripherals
Computer System Output Devices PeripheralsChandrakantDivate1
 
Computer system Input Devices Peripherals
Computer system Input  Devices PeripheralsComputer system Input  Devices Peripherals
Computer system Input Devices PeripheralsChandrakantDivate1
 
Computer system Input and Output Devices
Computer system Input and Output DevicesComputer system Input and Output Devices
Computer system Input and Output DevicesChandrakantDivate1
 
Introduction to COMPUTER’S MEMORY RAM and ROM
Introduction to COMPUTER’S MEMORY RAM and ROMIntroduction to COMPUTER’S MEMORY RAM and ROM
Introduction to COMPUTER’S MEMORY RAM and ROMChandrakantDivate1
 
Introduction to Computer Hardware Systems
Introduction to Computer Hardware SystemsIntroduction to Computer Hardware Systems
Introduction to Computer Hardware SystemsChandrakantDivate1
 
Fundamentals of Internet of Things (IoT) Part-2
Fundamentals of Internet of Things (IoT) Part-2Fundamentals of Internet of Things (IoT) Part-2
Fundamentals of Internet of Things (IoT) Part-2ChandrakantDivate1
 
Fundamentals of Internet of Things (IoT)
Fundamentals of Internet of Things (IoT)Fundamentals of Internet of Things (IoT)
Fundamentals of Internet of Things (IoT)ChandrakantDivate1
 
Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)ChandrakantDivate1
 
Fundamentals of functions in C program.pptx
Fundamentals of functions in C program.pptxFundamentals of functions in C program.pptx
Fundamentals of functions in C program.pptxChandrakantDivate1
 
Fundamentals of Structure in C Programming
Fundamentals of Structure in C ProgrammingFundamentals of Structure in C Programming
Fundamentals of Structure in C ProgrammingChandrakantDivate1
 
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN CINPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN CChandrakantDivate1
 
Programming in C - Fundamental Study of Strings
Programming in C - Fundamental Study of  StringsProgramming in C - Fundamental Study of  Strings
Programming in C - Fundamental Study of StringsChandrakantDivate1
 
Basics of Control Statement in C Languages
Basics of Control Statement in C LanguagesBasics of Control Statement in C Languages
Basics of Control Statement in C LanguagesChandrakantDivate1
 
Basics of Programming Algorithms and Flowchart
Basics of Programming Algorithms and FlowchartBasics of Programming Algorithms and Flowchart
Basics of Programming Algorithms and FlowchartChandrakantDivate1
 
Computer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesComputer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesChandrakantDivate1
 
Computer Graphics Three-Dimensional Geometric Transformations
Computer Graphics Three-Dimensional Geometric TransformationsComputer Graphics Three-Dimensional Geometric Transformations
Computer Graphics Three-Dimensional Geometric TransformationsChandrakantDivate1
 
Computer Graphics - Windowing and Clipping
Computer Graphics - Windowing and ClippingComputer Graphics - Windowing and Clipping
Computer Graphics - Windowing and ClippingChandrakantDivate1
 
Overview of Transformation in Computer Graphics
Overview of Transformation in Computer GraphicsOverview of Transformation in Computer Graphics
Overview of Transformation in Computer GraphicsChandrakantDivate1
 
Study on Fundamentals of Raster Scan Graphics
Study on Fundamentals of Raster Scan GraphicsStudy on Fundamentals of Raster Scan Graphics
Study on Fundamentals of Raster Scan GraphicsChandrakantDivate1
 

More from ChandrakantDivate1 (20)

Study of Computer Hardware System using Block Diagram
Study of Computer Hardware System using Block DiagramStudy of Computer Hardware System using Block Diagram
Study of Computer Hardware System using Block Diagram
 
Computer System Output Devices Peripherals
Computer System Output  Devices PeripheralsComputer System Output  Devices Peripherals
Computer System Output Devices Peripherals
 
Computer system Input Devices Peripherals
Computer system Input  Devices PeripheralsComputer system Input  Devices Peripherals
Computer system Input Devices Peripherals
 
Computer system Input and Output Devices
Computer system Input and Output DevicesComputer system Input and Output Devices
Computer system Input and Output Devices
 
Introduction to COMPUTER’S MEMORY RAM and ROM
Introduction to COMPUTER’S MEMORY RAM and ROMIntroduction to COMPUTER’S MEMORY RAM and ROM
Introduction to COMPUTER’S MEMORY RAM and ROM
 
Introduction to Computer Hardware Systems
Introduction to Computer Hardware SystemsIntroduction to Computer Hardware Systems
Introduction to Computer Hardware Systems
 
Fundamentals of Internet of Things (IoT) Part-2
Fundamentals of Internet of Things (IoT) Part-2Fundamentals of Internet of Things (IoT) Part-2
Fundamentals of Internet of Things (IoT) Part-2
 
Fundamentals of Internet of Things (IoT)
Fundamentals of Internet of Things (IoT)Fundamentals of Internet of Things (IoT)
Fundamentals of Internet of Things (IoT)
 
Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)
 
Fundamentals of functions in C program.pptx
Fundamentals of functions in C program.pptxFundamentals of functions in C program.pptx
Fundamentals of functions in C program.pptx
 
Fundamentals of Structure in C Programming
Fundamentals of Structure in C ProgrammingFundamentals of Structure in C Programming
Fundamentals of Structure in C Programming
 
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN CINPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
 
Programming in C - Fundamental Study of Strings
Programming in C - Fundamental Study of  StringsProgramming in C - Fundamental Study of  Strings
Programming in C - Fundamental Study of Strings
 
Basics of Control Statement in C Languages
Basics of Control Statement in C LanguagesBasics of Control Statement in C Languages
Basics of Control Statement in C Languages
 
Basics of Programming Algorithms and Flowchart
Basics of Programming Algorithms and FlowchartBasics of Programming Algorithms and Flowchart
Basics of Programming Algorithms and Flowchart
 
Computer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesComputer Graphics Introduction To Curves
Computer Graphics Introduction To Curves
 
Computer Graphics Three-Dimensional Geometric Transformations
Computer Graphics Three-Dimensional Geometric TransformationsComputer Graphics Three-Dimensional Geometric Transformations
Computer Graphics Three-Dimensional Geometric Transformations
 
Computer Graphics - Windowing and Clipping
Computer Graphics - Windowing and ClippingComputer Graphics - Windowing and Clipping
Computer Graphics - Windowing and Clipping
 
Overview of Transformation in Computer Graphics
Overview of Transformation in Computer GraphicsOverview of Transformation in Computer Graphics
Overview of Transformation in Computer Graphics
 
Study on Fundamentals of Raster Scan Graphics
Study on Fundamentals of Raster Scan GraphicsStudy on Fundamentals of Raster Scan Graphics
Study on Fundamentals of Raster Scan Graphics
 

Recently uploaded

ANSI(ST)-III_Manufacturing-I_05052020.pdf
ANSI(ST)-III_Manufacturing-I_05052020.pdfANSI(ST)-III_Manufacturing-I_05052020.pdf
ANSI(ST)-III_Manufacturing-I_05052020.pdfBertinKamsipa1
 
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...Roi Lipman
 
Diploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfDiploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfJNTUA
 
Complex plane, Modulus, Argument, Graphical representation of a complex numbe...
Complex plane, Modulus, Argument, Graphical representation of a complex numbe...Complex plane, Modulus, Argument, Graphical representation of a complex numbe...
Complex plane, Modulus, Argument, Graphical representation of a complex numbe...MohammadAliNayeem
 
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdfRESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdfKamal Acharya
 
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdfONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Artificial Intelligence Bayesian Reasoning
Artificial Intelligence Bayesian ReasoningArtificial Intelligence Bayesian Reasoning
Artificial Intelligence Bayesian Reasoninghotman30312
 
Intelligent Agents, A discovery on How A Rational Agent Acts
Intelligent Agents, A discovery on How A Rational Agent ActsIntelligent Agents, A discovery on How A Rational Agent Acts
Intelligent Agents, A discovery on How A Rational Agent ActsSheetal Jain
 
Theory for How to calculation capacitor bank
Theory for How to calculation capacitor bankTheory for How to calculation capacitor bank
Theory for How to calculation capacitor banktawat puangthong
 
ROAD CONSTRUCTION PRESENTATION.PPTX.pptx
ROAD CONSTRUCTION PRESENTATION.PPTX.pptxROAD CONSTRUCTION PRESENTATION.PPTX.pptx
ROAD CONSTRUCTION PRESENTATION.PPTX.pptxGagandeepKaur617299
 
Linux Systems Programming: Semaphores, Shared Memory, and Message Queues
Linux Systems Programming: Semaphores, Shared Memory, and Message QueuesLinux Systems Programming: Semaphores, Shared Memory, and Message Queues
Linux Systems Programming: Semaphores, Shared Memory, and Message QueuesRashidFaridChishti
 
Circuit Breaker arc phenomenon.pdf engineering
Circuit Breaker arc phenomenon.pdf engineeringCircuit Breaker arc phenomenon.pdf engineering
Circuit Breaker arc phenomenon.pdf engineeringKanchhaTamang
 
ChatGPT Prompt Engineering for project managers.pdf
ChatGPT Prompt Engineering for project managers.pdfChatGPT Prompt Engineering for project managers.pdf
ChatGPT Prompt Engineering for project managers.pdfqasastareekh
 
Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2T.D. Shashikala
 
Filters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility ApplicationsFilters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility ApplicationsMathias Magdowski
 
Lesson no16 application of Induction Generator in Wind.ppsx
Lesson no16 application of Induction Generator in Wind.ppsxLesson no16 application of Induction Generator in Wind.ppsx
Lesson no16 application of Induction Generator in Wind.ppsxmichaelprrior
 
E-Commerce Shopping using MERN Stack where different modules are present
E-Commerce Shopping using MERN Stack where different modules are presentE-Commerce Shopping using MERN Stack where different modules are present
E-Commerce Shopping using MERN Stack where different modules are presentjatinraor66
 
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdfInstruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdfEr.Sonali Nasikkar
 
How to Design and spec harmonic filter.pdf
How to Design and spec harmonic filter.pdfHow to Design and spec harmonic filter.pdf
How to Design and spec harmonic filter.pdftawat puangthong
 
DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdf
DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdfDR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdf
DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdfDrGurudutt
 

Recently uploaded (20)

ANSI(ST)-III_Manufacturing-I_05052020.pdf
ANSI(ST)-III_Manufacturing-I_05052020.pdfANSI(ST)-III_Manufacturing-I_05052020.pdf
ANSI(ST)-III_Manufacturing-I_05052020.pdf
 
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
 
Diploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfDiploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdf
 
Complex plane, Modulus, Argument, Graphical representation of a complex numbe...
Complex plane, Modulus, Argument, Graphical representation of a complex numbe...Complex plane, Modulus, Argument, Graphical representation of a complex numbe...
Complex plane, Modulus, Argument, Graphical representation of a complex numbe...
 
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdfRESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
 
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdfONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
 
Artificial Intelligence Bayesian Reasoning
Artificial Intelligence Bayesian ReasoningArtificial Intelligence Bayesian Reasoning
Artificial Intelligence Bayesian Reasoning
 
Intelligent Agents, A discovery on How A Rational Agent Acts
Intelligent Agents, A discovery on How A Rational Agent ActsIntelligent Agents, A discovery on How A Rational Agent Acts
Intelligent Agents, A discovery on How A Rational Agent Acts
 
Theory for How to calculation capacitor bank
Theory for How to calculation capacitor bankTheory for How to calculation capacitor bank
Theory for How to calculation capacitor bank
 
ROAD CONSTRUCTION PRESENTATION.PPTX.pptx
ROAD CONSTRUCTION PRESENTATION.PPTX.pptxROAD CONSTRUCTION PRESENTATION.PPTX.pptx
ROAD CONSTRUCTION PRESENTATION.PPTX.pptx
 
Linux Systems Programming: Semaphores, Shared Memory, and Message Queues
Linux Systems Programming: Semaphores, Shared Memory, and Message QueuesLinux Systems Programming: Semaphores, Shared Memory, and Message Queues
Linux Systems Programming: Semaphores, Shared Memory, and Message Queues
 
Circuit Breaker arc phenomenon.pdf engineering
Circuit Breaker arc phenomenon.pdf engineeringCircuit Breaker arc phenomenon.pdf engineering
Circuit Breaker arc phenomenon.pdf engineering
 
ChatGPT Prompt Engineering for project managers.pdf
ChatGPT Prompt Engineering for project managers.pdfChatGPT Prompt Engineering for project managers.pdf
ChatGPT Prompt Engineering for project managers.pdf
 
Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2
 
Filters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility ApplicationsFilters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility Applications
 
Lesson no16 application of Induction Generator in Wind.ppsx
Lesson no16 application of Induction Generator in Wind.ppsxLesson no16 application of Induction Generator in Wind.ppsx
Lesson no16 application of Induction Generator in Wind.ppsx
 
E-Commerce Shopping using MERN Stack where different modules are present
E-Commerce Shopping using MERN Stack where different modules are presentE-Commerce Shopping using MERN Stack where different modules are present
E-Commerce Shopping using MERN Stack where different modules are present
 
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdfInstruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
 
How to Design and spec harmonic filter.pdf
How to Design and spec harmonic filter.pdfHow to Design and spec harmonic filter.pdf
How to Design and spec harmonic filter.pdf
 
DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdf
DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdfDR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdf
DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdf
 

Features and Fundamentals of C Language for Beginners

  • 1. Basics of C Programming C. P. Divate
  • 2. Features of C Language C is the widely used language. It provides many features that are given below. • Simple • Machine Independent or Portable • Mid-level programming language • structured programming language • Rich Library • Memory Management • Fast Speed • Pointers • Recursion • Extensible • Rich set of controlling statements • Rich sent of Operators
  • 3. Ares of C Language C is the widely used language. It is used to develop sofwares in following areas, • Scientific Application • Environmental Application • Mathematical calculations • Embedded Systems • Space satellite Application • Data Structure Application • Computer Graphics Application • Computer Network Applications
  • 4. History of C Language • Dennis Ritchie - founder of C language • C programming language was developed in 1972 by Dennis Ritchie at bell laboratories of AT&T (American Telephone & Telegraph), located in the U.S.A. • Dennis Ritchie is known as the founder of the c language.
  • 5. History of C Language Language Year Developed By Algol 1960 International Group BCPL 1967 Martin Richard B 1970 Ken Thompson Traditional C 1972 Dennis Ritchie K & R C 1978 Kernighan & Dennis Ritchie ANSI C 1989 ANSI Committee ANSI/ISO C 1990 ISO Committee C99 1999 Standardization Committee Let's see the programming languages that were developed before C language.
  • 6. Structure Of a C Program Example Of C Program structure
  • 7. My First C Program #include <stdio.h> int main() { printf("Hello C Language"); return 0; } Execution of First C Program
  • 8. Comments in C Language • Comments are non Executable statements in c program. • C introduces a new comment symbol // (double slash). Comments start with a double slash symbol and terminate at the end of line. • A comment may start any where in the line and what ever follows till the end of line is ignored. • Note that there is no closing symbol. • The double slash comment is basically a single line comment. Multi line comments can be written as follows: // this is an example of // c++ program // thank you • The c comment symbols /* ….*/ are still valid and more suitable for multi line comments. /* this is an example of c++ program */
  • 9. Steps in C Language study Let's see the programming languages that were developed before C language.
  • 10. Steps in C Language study Let's see the programming languages that were developed before C language. Token
  • 11. 1) Character set in C Language
  • 12. 1) Characters Used in C Programs • Lowercase letters • a b c . . . z • Uppercase letters • A B C . . . Z • Digits • 0 1 2 3 4 5 6 7 8 9 • Other characters • + - * / = ( ) { } [ ] < > ‘ “ • ! @ # $ % & _ ^ ~ . , ; : ? • White space characters • blank, newline, tab, etc.
  • 13. 2) The Six Kinds of Tokens / Words in C 1) Keywords 2) Constants / Literals 3) Identifiers - variables / function / structure / array name 4) Statements/ Instructions – e.g. scanf, printf, getch etc. 5) Operators - +, -, * etc. 6) Punctuators - , : “ ‘ . ! ? % etc. • The smallest individual units/words in program are known as tokens. • C has the following Six different types of tokens.
  • 14. 2) Tokens / words in C Language 2.1) KEYWORDS :  Keywords are C tokens that have a strict meaning in c language to perform certain tasks.  They are explicitly reserved words and can’t be used as names for the program variables or other user defined program elements.  ANSII C has 32 key words.  Some implementations such as Borland’s C or Microsoft’s C have additional key words. auto do goto signed unsigned break double if sizeof void case else int static volatile char enum long struct while const extern register switch continue float return typedef default for short union
  • 15. What is a Constant?  Constant is a value (an entity) whose value cannot change throughout the execution of a program,is known as constants.  Like variables constants have data types. 2) Tokens / words in C Language 2.2) Constants / Literals : 1) Using const keyword const data_type <variable_name>=<val>; (or) data_type const <variable_name>=<val>; 2) Using Define preprocerssor #define <variable> <Value> Syntax (Grammar) Example const int x = 10; int const x = 10; #define PI 3.14
  • 16. Types of Constants in C 2) Tokens / words in C Language 2.2) Constants / Literals :  Integer constant - (complete / Whole Number)  Real constant - (Fractional Number)  Character Constant - (Single Letter)  String Constant - (multiple letters)
  • 17. 2.2.1) Integer Constants Decimal Constants Octal Constants Hexa-Decimal Constants 10 012 0xA 1024 02000 0x400 12789845 060624125 0xC32855 2) Tokens / words in C Language 2.2) Constants / Literals :  In C language integer constant is a complete / Whole Number.  integer constant are represented in one of following formats, a) Decimal b) octal (Value starts with 0) c) or hexa-decimal number (Value starts with 0x).  Integer constants are always positive until you specify a negative(-) sign.
  • 18. Example Program 18 2) Tokens / words in C Language 2.2) Constants / Literals : #include<stdio.h> void main ( ) { const int a = 10; //Decimal int const b = 012; //Octal const int c = 0xA; //Hexadecimal printf(" %d t %d t %d ", a, b, c); } OUTPUT: 10 10 10
  • 19. Representation Fractional form Exponential form Type 0 0.0 0.0e-10 or 0.0E-10 double 6.77 6.77 0.677e1 or 0.677E1 double -6.0f -6.0 -0.6 e1 or -0.6E1 float 3.1415926536L 3.1415926536 0.31415926536 e1 long double 2.2.2) Real Constants 2) Tokens / words in C Language 2.2) Constants / Literals :  In C language real constant is a fractional Number.  We can represent the negative numbers in real constants.  The default form of real constant is double and it must have a decimal point.  It may be in fractional form or exponential form.  Ex: 3.45, -2.58, 0.3E-5 (equal to 0.3 x 10-5)
  • 20. ASCII Character Symbol Alert(bell) 'a' Null character '0' Backspace 'b' Horizontal Tab 't' New line 'n' 2.2.3) Character Constants 2) Tokens / words in C Language 2.2) Constants / Literals :  Character Constants are in single letter form and must be enclosed with in single quotes. e.g. ‘a’, ‘Z’, ‘1’, ‘4’, ‘&’, ‘%’,’#’ etc.  We use escape character along with the character constants, followed by .  The escape character says that it is not a normal character constants as they do some tasks on user(output) screen. ASCII Character Symbol Vertical tab 'v' Form Feed 'f' Carriage Return 'r' Single Quote ''' Double Quote '"'
  • 21. 21 2.2.4) String Constants 2) Tokens / words in C Language 2.2) Constants / Literals :  A string constant is a sequence of characters enclosed in a double quotes. Examples:  “ ” // Null String  "programming9" // a full string with 12 characters  "wel come" // string with 8 characters including space  “Value= %d" // format string with 8 characters including space  “a=%d n b=%d" // format string with 9 characters including space and escape sequence character.
  • 22. 3) IDENTIFIERS:  Identifiers refers to the name of variable, functions, array, structure etc. created by programmer.  Variable is an entity in c program whose value can changes several time throughout the execution of program.  i.e. Variables are entities whose values can not remain constant in C program.  Each language has its own rule for naming the identifiers. The following rules for naming the identifiers in C and C++. 1. Identifier name should start with alphabet character or underscore _. 2. Other characters in identifier can be letters, digits and underscore are permitted. 3. A variable name should not consist of whitespace. 4. 'C' is a case sensitive language that means a variable named 'age' and 'AGE' are different. 5. A variable name should not consist of a keyword. 6. It can have 8, 32 letter long in size. 7. It must be declared first (locally / Globally) before using in program. 3) Tokens / words in C Language
  • 23. 3) IDENTIFIERS:  Following are the examples of valid variable names in a 'C' program: 3) Tokens / words in C Language o height or HEIGHT o _height o _height1 o My_name Following are the examples of invalid variable names in a 'C' program: o 1height o Hei$ght o My name o case o switch
  • 24. 3) IDENTIFIERS:  Following are the examples of valid variable names in a 'C' program: 3) Tokens / words in C Language o height or HEIGHT o _height o _height1 o My_name Following are the examples of invalid variable names in a 'C' program: o 1height o Hei$ght o My name o case o switch
  • 25. 3) IDENTIFIERS: 3) Tokens / words in C Language 1) Declaration without initialization: data_type <variable_name1> [,<variable_name2>, …… ] ; 2) Declaration with initialization: data_type <variable_name1>=<val1> [,<variable_name2>=<val2>, …… ] ; Declaration Syntax (Grammar) 1) Declaration without initialization: int x; float x,y,z; 2) Declaration with initialization: int a=10; float x=20, y=30, z=-40; Declaration example
  • 26. 3) BASIC DATA TYPES IN C 3) Tokens / words in C Language
  • 27. 3) BASIC DATA TYPES IN C 3) Tokens / words in C Language
  • 28. Tokens in C Language 3) BASIC DATA TYPES IN C
  • 29. 3) BASIC DATA TYPES IN C 3) Tokens / words in C Language
  • 30. IDENTIFIERS BASIC DATA TYPES / DATA STRUCTURES IN C++ 2.3) IDENTIFIERS: 3) Tokens / words in C Language
  • 31. 4) Tokens / Instructions(statements) in C Language • Sequential execution means that each command in a program script executes in the order in which it is listed in the program. • The first command in the sequence executes first and when it is complete, the second command executes, and so on.
  • 32. 4) Tokens / Instructions in C Language
  • 33. 4) Tokens / Instructions(statements) in C Language C has following types of statement. i) Variable Declaration Statements ii) Assignment statements • Initialization statement • Arithmetical / Mathematical Statements iii) Input Statements iv) Selection (branching) • if (expression) statement • if (expression) else statement • Nesting of if (expression) else statement • if (expression) else ladder • switch (expression) case statement v) iteration (looping) statements • while (expression){ block } • for(expression ;expression ;expression){ block } • do {block} while (expression); vi) Output statements vii) Normal / Abnormal termination statement; viii) Null Statements
  • 34. 5) Tokens / Operators in C Language • 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 −
  • 35. 5) Tokens / Operators in C Language • Classification of Each Operators Unary Operators Binary Operators The operators which act upon a single operand are called unary operators. The operators which require two operands for their action are called binary operators. Syntax i) operator <operand> ii) <operand> operator Syntax i) operand1 operator operand2 Example i ++, j - - ++c - 46 Example a + b x - 4
  • 36. 5) Tokens / Operators in C Language • The following table shows all the arithmetic operators supported by the C language. • Assume variable A = 10 and variable B = 20, then 5.1) Arithmetic Operators in c Language Operator Description Example Result + Adds two operands. A + B 30 − Subtracts second operand from the first. A − B -10 * Multiplies both operands. A * B 200 / Divides numerator by de-numerator. B / A 2 % Modulus Operator and remainder of after an integer division. B % A 0 ++ Increment operator increases the integer value by one. A++ 11 -- Decrement operator decreases the integer value by one. A-- 9
  • 37. 5) Tokens / Operators in C Language 5.1) Classification of Arithmetic Operators in c Language
  • 38. 5) Tokens / Operators in C Language • Program for Study of Arithmetic operators 5.1) Arithmetic Operators in c Language #include <stdio.h> main() { int a = 21; int b = 10; int c ; c = a + b; printf("Line 1 - Value of c is %dn", c ); c = a - b; printf("Line 2 - Value of c is %dn", c ); c = a * b; printf("Line 3 - Value of c is %dn", c ); c = a / b; printf("Line 4 - Value of c is %dn", c ); c = a % b; printf("Line 5 - Value of c is %dn", c ); c = a++; printf("Line 6 - Value of c is %dn", c ); c = a--; printf("Line 7 - Value of c is %dn", c ); } Line 1 - Value of c is 31 Line 2 - Value of c is 11 Line 3 - Value of c is 210 Line 4 - Value of c is 2 Line 5 - Value of c is 1 Line 6 - Value of c is 21 Line 7 - Value of c is 22 Output
  • 39. 5) Tokens / Operators in C Language • Priority / Precedence / Hierarchy of Arithmetic Operators in C 5.1) Arithmetic Operators in c Language
  • 40. 5) Tokens / Operators in C Language • Priority / Precedence / Hierarchy of Arithmetic Operators in C Example 5.1) Arithmetic Operators in c Language
  • 41. 5) Tokens / Operators in C Language • Priority / Precedence / Hierarchy of Arithmetic Operators in C Example 5.1) Arithmetic Operators in c Language
  • 42. DATA INPUT AND OUTPUT INSTRUCTIONS IN C  As we know that any c program is made up of 1 or more then ONE standard function.  Likewise it use some functions for input output process. The most common function  printf()  scanf().
  • 43. printf() Function  printf() function is used to display something on the console or to display the value of some variable on the console.  The general syntax for printf() function is as follows  printf(<”format string”>[,<list of variables>]);  To print some message on the screen  printf(“God is great”);  This will print message “God is great” on the screen or console.  Format specifiers in “format string” must match with respective variable data type.  Number of format specifiers must be equal to number of variables in list of variables.
  • 44. printf() Function  To print the value of some variable on the screen Integer Variable :  int a=10; printf(“%d”,a);  Here %d is format string to print some integer value and a is the integer variable whose value will be printed by printf() function.  This will print value of a “10” on the screen.
  • 45. printf() function • To print multiple variable’s value one can use printf() function in following way. int p=1000,n=5; float r=10.5; printf(“amount=%d rate=%f year=%d”,p,r,n); • This will print “amount=1000 rate=10.5 year=5” on the screen
  • 46. scanf() Function • scanf() function is use to read data from keyboard and to store that data in the variables during runtime. • The general syntax for scanf() function is as follows. scanf(“Format String”, &variable); • Here format string is used to define which type of data it is taking as input. • This format string can be %c for character, %d for integer variable and %f for float variable. • Format specifiers in “format string” must match with respective variable data type. • Number of format specifiers must be equal to number of variables in list of variables.
  • 47. scanf() Function scanf(“Format String”, &variable1,…); • Where as variable the name of memory location or name of the variable • and & sign is an operator that tells the compiler the address of the variable where we want to store the value.
  • 48. scanf() Function • For Integer Variable : int rollno; printf(“Enter rollno=”); scanf(“%d”,&rollno); Here in scanf() function %d is a format string for integer variable and &rollno will give the address of variable rollno to store the value at variable rollno location. • For Float Variable : float per; printf(“Enter Percentage=”); scanf(“%f”, &per); • For Character Variable : char ans; printf(“Enter answer=”); scanf(“%c”, &ans);
  • 49. /100
  • 50. clrscr() function in C • Function "clrscr" (works in Turbo C / C++ compiler only) clears the screen and moves the cursor to the upper left- hand corner of the screen. • It is an output statement in c. • Syntax: void clrscr( ); • For Example clrscr( );
  • 51. getch() function in C • getch() is a nonstandard function and is present in conio.h header file which is mostly used by MS-DOS compilers like Turbo C. • It is an input statement in c. • Syntax: int getch(void); Parameters: This method does not accept any parameters. Return value: This method returns the ASCII value of the key pressed. For Example int main() { int a; a=getch(); printf("%c", a); return 0; } Input: g (Without enter key) Output: Program terminates immediately. But when you use DOS shell in Turbo C, it shows a single g, i.e., 'g' Output with explanation
  • 52. getch() function in C • getch() method pauses the Output Console untill a key is pressed. • It does not use any buffer to store the input character. • The entered character is immediately returned without waiting for the enter key. • The entered character does not show up on the console. • The getch() method can be used to accept hidden inputs like password, ATM pin numbers, etc.
  • 53. Single character input – the getchar () function : • Single characters can be entered into the computer using the “C” library function getchar. • In general terms, a reference to the getchar function is written as. character variable=getchar(); For example char c; c=getchar(); printf(“Given Character is:%c ”, c);
  • 54. Single character output – The putchar function • Single character can be displayed (i.e. written out of the computer) using the C library function putchar. • In general a reference to the putchar function is written as putchar (character variable); • For Example char c=’a’; putchar(c);
  • 55. RELATIONAL OPERATORS IN C: • Relational operators are used to find the relation between two variables. i.e. to compare the values of two variables in a C program. Operator Description Example == Checks if the values of two operands are equal or not. If yes, then the condition becomes true. (A == B) is not true. != Checks if the values of two operands are equal or not. If the values are not equal, then the condition becomes true. (A != B) is true. > Checks if the value of left operand is greater than the value of right operand. If yes, then the condition becomes true. (A > B) is not true. < Checks if the value of left operand is less than the value of right operand. If yes, then the condition becomes true. (A < B) is true. >= Checks if the value of left operand is greater than or equal to the value of right operand. If yes, then the condition becomes true. (A >= B) is not true. <= Checks if the value of left operand is less than or equal to the value of right operand. If yes, then the condition becomes true. (A <= B) is true. Assume variable A holds 10 and variable B holds 20 then