SlideShare a Scribd company logo
1 of 38
1
C Programming Language
Presented By:
NARAHARI
PROGRAMMING LANGUAGE
2
 Program: Set of
 From the time when computers were invented
programming existed.
 Programming was done using a particular set of rules
and syntaxes which is said to be a language used to
write the Program.
EVOLUTION OF ‘C’
3
ALGOL 60 (Programming using Algorithms)
CPL (Combined Programming Language)
BCPL (Basic Combined Programming Language)
‘B’ Developed By Ken Thompson
BCPL + B + Additional Features = ‘C’ Language
Developed By : Dennis M. Ritchie & T BELL
Laboratory, New Jersey, USA in 1972.
FEATURES OF ‘C’
4
 Robust Language, for writing any complex program.
 Built-in Functions & Data types.
 Suitable for writing both System Software and Business
Applications.
 Efficient & Faster in Execution.
 Highly Portable.
 Dynamic Memory Allocation (DMA)
STRUCTURE OF A C PROGRAM
YCT Academy, FB : facebook/pankajsir007
5
#include<stdio.h>
#define PI 3.14
void main()
{
statements;
……..
}
Preprocessor
Symbol ( # )
Header file
(all files with
Extension *.h)
Symbolic
Constants
Function main()
(Entry point for
any C Program)
Function Block
(main() function
Starting and ending
Limit within { })
Statements;
(all the coding which
to be written for
Execution)
include for including
The file at Preprocessing
< > to locate
The file in the
Default Include
Directory
TOKENS
(The smallest individual unit in a C Program)
YCT Academy, FB : facebook/pankajsir007
6
 Identifiers
 Keywords
 Constants
 Special Characters
IDENTIFIERS
YCT Academy, FB : facebook/pankajsir007
7
 Identifiers can be defined as the name of the
variables and some other program elements.
 It can be the combination of the following characters.
Alphabets (a-z, A-Z), Numbers (0-9) & Underscore ( _
).
 All the names used to refer an element in a program
is said to be Identifier.
 Examples of some valid identifiers name, mark1,
total_marks, _avg
KEYWORDS
YCT Academy, FB : facebook/pankajsir007
8
 Keywords are also identifiers but cannot be user defined
since they are reserved words.
 Keywords are some special words for which the meaning
is already known to the compiler.
 All the keywords should be in lower case letters.
 Examples for some keywords are if, break, else, return,
void, etc.
CONSTANTS
YCT Academy, FB : facebook/pankajsir007
9
 Constants are of three types :
1) Literal Integer Constants.
2) Literal Floating point Constants.
2) Literal Character Constants.
3) Literal String Constants.
 Literal Integer Constants are all positive and negative numbers like
1, -5, 1548, -58469, etc.
 Literal Floating point Constants are all decimal numbers like 12.25,
0.564, 56.e38, etc.
 Literal Character Constants are all single characters represented
within single quotes like ‘A’, ‘a’, ‘:’, ‘1’, etc.
 Literal String Constants are group of characters represented within
double quotes like “Hello”, “Programming”, “A”, etc.
THE PREPROCESSING ( # )
YCT Academy, FB : facebook/pankajsir007
10
 # is called as the pre-processor symbol.
 The statements which are following the # symbol will get pre-
processed, so they are called as pre-processor directives.
 Pre-Processing is done by the preprocessor which inserts the
files given with the pre-processor symbol # into the actual
program before it gets executed.
 Pre-Processing is done before the actual main program is
compiled by the compiler. Any statements that follow the #
symbol will be embedded as if present in the actual program.
COMPILATION & EXECUTION OF A
C PROGRAM
YCT Academy, FB : facebook/pankajsir007
11
 The Source Code files of C are saved with the extension
( *.C ) (where * denotes the file name)
 They are then compiled by the compiler to a Object Code
( *.obj )
 Then the Object Code will be linked by the Linker to form
the Machine Language also known as Executable Code,
files with extension ( *.exe)
COMPILATION & EXECUTION OF A
C PROGRAM
YCT Academy, FB : facebook/pankajsir007
12
C Program (with *.C extension)
Preprocessor
Object Code (with *.obj extension)
Executable Code (with *.exe extension)
Compiler
Linker
SYMBOLIC CONSTANTS
YCT Academy, FB : facebook/pankajsir007
13
 The #define statement is used to create Symbolic
Constants known as Macros (replacement text).
 The statement #define PI 3.14 will create PI to have the
constant value 3.14.
 The constant created with #define can be used in
program that will represent the constant value defined for
it.
 It is also used to create Macro Functions or Macros.
HEADER FILES (*.h)
YCT Academy, FB : facebook/pankajsir007
14
 Files with the extension *.h are said to Header Files.
 In a C program many inbuilt functions might be used, those
functions Prototype (Declaration) need to known to compiler which
are already specified in the particular header files related to them.
 The header file like stdio.h is the Standard Input / Output header file
which contains the Prototype or Declaration for all the inbuilt Input /
Output related functions.
 In in C Program different header files might be included in the pre-
processor based on the inbuilt functions used by the program.
The main() Function
YCT Academy, FB : facebook/pankajsir007
15
 In every C Program there will be at least one function
without which the program does not execute which is the
main() function.
 The main() Function is the Entry Point for every program
from which the compiler starts to compile the program.
 All the C Programs start to execute from the Open Block
{ where the main() function begins and ends at the Close
Block } where it ends.
 So, the statements or coding written inside the main()
block gets executed at the runtime of the program.
TWO TYPES OF main()
FUNCTION
YCT Academy, FB : facebook/pankajsir007
16
#include<stdio.h>
void main()
{
statements;
…….
…….
}
#include<stdio.h>
int main()
{
statements;
…….
return 0;
}
Syntax for a Function or A Function is identified by the following
return_type Function_name(argument_list)
Here the return_type is the value which the function returns back to the area from where it
was invoked. The Function_name is the name given to the function and the () just following
the function name is the identification that it is a function within which arguments passed to
the function will be specified.
DATA TYPES IN ‘C’
Data Types
Primary Data Types
Integers
Floating Points
Characters
Strings
Derived Data Types
Arrays
Pointers
Functions
User-Defined Types
Structures
Unions
Enumerations
YCT Academy, FB : facebook/pankajsir007
17
Description Keyword Format String Memory Range
Short Range of
numbers
int %d 2 Bytes -32768 to
+32767
Long Range of
numbers
long %ld 4 Bytes -2147483648
to
+2147483647
YCT Academy, FB : facebook/pankajsir007
18
INTEGERS
Description Keyword Format String Memory Range
Single Precision
Decimal numbers
float %f 4 bytes 3.4 e-38 to
3.4e+38
Double Precision
Decimal Numbers
double %lf 8 bytes 1.7e-308 to
1.7e+308
Range of Decimals
beyond double
long double %Lf 10 bytes 3.4e-4932 to
1.1e+4932
YCT Academy, FB : facebook/pankajsir007
19
FLOATING POINTS
CHARACTERS
Description Keyword Format String Memory Range
Single Characters char %c 1 Byte -128 to +127
YCT Academy, FB : facebook/pankajsir007
20
All the Alphabets, Numbers, Special Symbols represented within
SINGLE QUOTES are said to characters.
For example ‘a’ ‘A’ ‘{‘ ‘:’ ‘1’
All Characters have a unique Number Representation which is called
as the ASCII CODE.
ASCII means American Standard Code for Information Interchange.
For example the ASCII Value for the character ‘A’ is 65 and ‘0’ is 48
THE unsigned DATA TYPE MODIFIER
Description Keyword Format
String
Memory Range
Short Range of
unsigned numbers
unsigned int %u 2 Bytes 0 to 65535
Long Range of
unsigned numbers
unsigned long %u 4 Bytes 0 to
4294967295
Unsigned
Characters
unsigned char %u 1 byte 0 to 255
YCT Academy, FB : facebook/pankajsir007
21
Syntax : unsigned <type> <variable> ;
Description : Use the unsigned type modifier when variable
values will always be positive. The unsigned modifier can be
applied to base types int, char, long, and short.
When the base type is omitted from a declaration, int is
assumed.
VARIABLES
YCT Academy, FB : facebook/pankajsir007
22
 Variables are names used to refer the memory location where different
constants are stored.
 It is like a label given to a particular memory location where the values of
constants are stored.
 For example lets see the pictorial memory representation when a value is
stored in memory for a declaration like
char ch;
…..100 101 102 103 104 105 106 107 108 109 110 111 ….
ch
Address of the memory
Variable name
Value at the memory
RULES FOR GIVING VARIABLE
NAMES
YCT Academy, FB : facebook/pankajsir007
23
 It should begin with a alphabet or underscore ( _ )
followed by any combination of alphabets, underscores,
or digits. E.g. int n1;
 Variable names are case-sensitive i.e. uppercase are
different from lower case letter. E.g. int a, A;
 Variable names cannot be a Keyword.
 No Commas or blank spaces are allowed within a
Variable name.
 Length for declaring a variable depends on the complier.
STRINGS
YCT Academy, FB : facebook/pankajsir007
24
 Strings are Group of Characters. In C strings are said to be Character Arrays.
 Array is a collection of similar type of elements referred by a single name and
allocated in a contiguous memory locations.
 char Array_name[size]; where char is data type, Array name is the name given to the
array and [] is the subscript or Delimiters of the array within which the size that is the
no. of characters that the array can contain is specified.
 Strings in C are called as NULL TERMINATED CHARACTER ARRAYS. A special
character called as the NULL character ( ‘0’ ) a backslash with a zero is the last
character ending the array which is automatically inserted by the C compiler after the
last character inputed.
 For example char name[10] = “Dennis”;
‘D’ ‘e’ ‘n’ ‘n’ ‘i’ ‘s’ ‘0’
[0] [1] [2] [3] [4] [5] [6] [7] [8] [9]
100 101 102 103 104 105 106 107 108 109
Index of The Array
Element of the array
Address of each
Element of the array
OPERATORS
YCT Academy, FB : facebook/pankajsir007
25
 Arithmetic Operators
 Relational Operators
 Logical Operators
 Assignment Operators
 Conditional or Ternary Operator
ARITHEMETIC OPERTORS
YCT Academy, FB : facebook/pankajsir007
26
 Addition Operator +
 Subtraction Operator –
 Multiplication Operator *
 Quotient Division Operator /
 Reminder Division or Modulus Operator
%
UNARY OPERATORS
YCT Academy, FB : facebook/pankajsir007
27
UNARY + OPERATOR
 The Operator unary ‘+’
precedes an operand.
 Operand is the value on
which the operator
operates.
 For Example
 If a=5 then +a means 5
 If a=0 then +a means 0
 If a=-4 then +a means -
4
UNARY - OPERATOR
 The Operator unary –
precedes an operand.
 For Example
 If a=5 then –a means -5
 If a=0 then –a means 0
 If a=-4 then –a means 4
 This operator reverses
the sign of the
operand’s value
Operators that act on one operand are referred to as Unary Operators
BINARY OPERATORS
YCT Academy, FB : facebook/pankajsir007
28
 The operands of a binary operator are distinguished as the left or right
operand. Together, the operator and its operand is called as an expression.
 For Example addition of two numbers 4+20 results in 24.
 If a=4 and b=6 then a + b will result in 10 where the left side operand and
the right side operand is b.
 The Modulus Operator (%) produces the reminder of dividing the first by the
second operand. For example
19 % 6 evaluates to 1, since 6 goes into 19 three times with a reminder 1.
Note that the both operands must be integer data types when using modulus
operator (%).
Operators that act on two operands are referred to as Binary Operators
RELATIONAL OPERATORS
YCT Academy, FB : facebook/pankajsir007
29
 Less than Operator <
 Less than or equal to Operator <=
 Greater than Operator >
 Greater than or equal to Operator >=
 Equality Operator ==
 Not Equality Operator !=
LOGICAL OPERATORS
YCT Academy, FB : facebook/pankajsir007
30
Logical AND Operator &&
This operator is used to
combine two expressions
into one and check whether
the both the expressions
are true
For example:-
(6<9)&&(4>2) is true
6==6&&4==3 is false
If a=4 and b=4 then
(a>=a) && (b<=b) is true
Logical OR Operator ||
This operator is used to
combine two expressions
into one and check
whether any one of the
expressions are true.
For example:-
(5>8) || (5<2) is false
6==6 || 4==3 is true
If a=4 and b=4 then
(a>a) || (b<=b) is true
C considers 0 as a false value and any non-zero value as a true value
ASSIGNMENT OPERATORS
YCT Academy, FB : facebook/pankajsir007
31
 Normal Assignment =
For e.g. int a=10;
 Addition Assignment +=
For e.g. int a=10,b=10; then a += b
means a = a + b;
 Multiplication Assignment *=
 Subtraction Assignment -=
 Division Assignment /=
 Modulus Assignment %=
Assignment Operators assign value from Right to Left.
That is right side operand value is assigned to the left side operand
UNARY INCREMENT / DECREMENT
OPERATORS (++, --)
YCT Academy, FB : facebook/pankajsir007
32
 C includes two useful operators which is not
generally found in other computer languages.
 These are the increment and decrement
operators, ++ and --
 The operator ++ adds 1 to its operand, and --
subtracts one. In other words,
a = a + 1 is same as ++a or a++ and
a = a – 1 is same as --a or a--
PREFIXING OF ++ OR --
YCT Academy, FB : facebook/pankajsir007
33
The Prefix increment or decrement operators follow
CHANGE-THEN-USE rule i.e. they first change
(increment or decrement) the value of their operand,
then use the new value in evaluating the expression.
For example,
Prefixing of ++ Prefixing of --
int a=10, b;
b = ++a;
Here first a = a + 1 is
done and the new value is
assigned to b. So b will be
11 and a will also be 11
int a=10, b;
b = --a;
Here first a = a - 1 is done
and the new value is
assigned to b. So b will be
9 and a will also be 9
POSTFIXING OF ++ OR --
YCT Academy, FB : facebook/pankajsir007
34
The Postfix increment or decrement operators follow
USE-THEN-CHANGE rule i.e. they first use the value
of their operand in evaluating the expression and then
change (increment / decrement) the operand’s value.
For example,
Postfixing of ++ Postfixing of --
int a=10, b;
b = a++;
Here first a value is assigned
to b and then a = a + 1
increments the value of a. So,
b will be 10 and a will be 11.
int a=10, b;
b = a--;
Here first a value is assigned to
b and then a = a - 1
decrements the value of a. So, b
will be 10 and a will be 9.
CONDITIONAL / TERNARY
OPERATOR
YCT Academy, FB : facebook/pankajsir007
35
C offers a conditional operator ?: that stores a value
depending upon a condition. This operator is ternary i.e.,
it requires three operands. The general form of
conditional operator ?: is as follows:-
expression1 ? expression2 : expression3
If expression1 evaluates to be true i.e. 1, then the value
of the whole expression is the value of expression2,
otherwise the value of the whole expression is the value
of the expression3. For example,
result = marks >=50 ? ‘P’ : ‘F’;
4==9 ? 10 : 25 evaluates to 25 because test expression
4==9 is false.
(a>b ? (a>c ? a : c) : (b>c ? b : c);
In the above statement the expression will be having the
highest value among the three a, b & c.
FORMATTED I / O FUNCTIONS
YCT Academy, FB : facebook/pankajsir007
36
 The function printf() is used to print the formatted output
on the standard output device (monitor). The function
printf() is an inbuilt function which is defined in the header
file stdio.h
 The function scanf() is used to read the formatted input
from the standard input device (keyboard). The function
scanf() is an inbuilt function defined in the header file
stdio.h
 The header file stdio.h should be included in the
preprocessor directive to use the above mentioned
printf() and scanf() functions in the program
THE printf() FUNCTION
YCT Academy, FB : facebook/pankajsir007
37
Syntax : printf(“formatstring”,arg list);
Example statements for showing the use of printf() function
E.g. 1. printf(“Welcome to C Programming”);
E.g. 2. int a=10;
printf(“Value of a = %d”,a);
E.g. 3. int x=10;long y = 200L; float z = 20.5;
printf(“x = %d y = %ld z = %f”,x,y,z);
printf() function always works from Right to Left that is in the above
example from the last the value of z gets printed in the last format
string %f and then value of y gets printed in the place of %ld location
and finally the value of x gets printed in the place of %d location
THE scanf() FUNCTION
YCT Academy, FB : facebook/pankajsir007
38
Syntax : scanf(“formatstring”,arg list);
Example statements for showing the use of scanf() function
E.g. 2. int a;
scanf(“%d”,&a);
E.g. 3. int x; long y; float z;
scanf(“%d%ld%f”,&x,&y,&z);
scanf() function always works from Left to Right that is the first number
inputted will be assigned to x and then the next number inputted will be
assigned to y and the last number inputted will be assigned to z. Here the
& operator which is called as the address of operator is used to mention
the address of the variable where the value is to be stored. Only when
strings are inputted the & operator is not used in the scanf() functions
other than this for all other data types the & operator is a must to be
prefixed before the variable name in the scanf() function.

More Related Content

Similar to c programming Pankaj Panjwani.pptx

Similar to c programming Pankaj Panjwani.pptx (20)

unit2.pptx
unit2.pptxunit2.pptx
unit2.pptx
 
Introduction of C++ By Pawan Thakur
Introduction of C++ By Pawan ThakurIntroduction of C++ By Pawan Thakur
Introduction of C++ By Pawan Thakur
 
Cnotes
CnotesCnotes
Cnotes
 
Unit 2 introduction to c programming
Unit 2   introduction to c programmingUnit 2   introduction to c programming
Unit 2 introduction to c programming
 
history of c.ppt
history of c.ppthistory of c.ppt
history of c.ppt
 
5 introduction-to-c
5 introduction-to-c5 introduction-to-c
5 introduction-to-c
 
C Language
C LanguageC Language
C Language
 
C language ppt
C language pptC language ppt
C language ppt
 
Lecture 01 2017
Lecture 01 2017Lecture 01 2017
Lecture 01 2017
 
C presentation book
C presentation bookC presentation book
C presentation book
 
C programming language Reference Note
C programming language Reference NoteC programming language Reference Note
C programming language Reference Note
 
Introduction%20C.pptx
Introduction%20C.pptxIntroduction%20C.pptx
Introduction%20C.pptx
 
Basic of the C language
Basic of the C languageBasic of the C language
Basic of the C language
 
C programming notes
C programming notesC programming notes
C programming notes
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
Chapter3
Chapter3Chapter3
Chapter3
 
C programming notes.pdf
C programming notes.pdfC programming notes.pdf
C programming notes.pdf
 
Unit 1.1 - Introduction to C.pptx
Unit 1.1 - Introduction to C.pptxUnit 1.1 - Introduction to C.pptx
Unit 1.1 - Introduction to C.pptx
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
 

Recently uploaded

SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 

Recently uploaded (20)

SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 

c programming Pankaj Panjwani.pptx

  • 2. PROGRAMMING LANGUAGE 2  Program: Set of  From the time when computers were invented programming existed.  Programming was done using a particular set of rules and syntaxes which is said to be a language used to write the Program.
  • 3. EVOLUTION OF ‘C’ 3 ALGOL 60 (Programming using Algorithms) CPL (Combined Programming Language) BCPL (Basic Combined Programming Language) ‘B’ Developed By Ken Thompson BCPL + B + Additional Features = ‘C’ Language Developed By : Dennis M. Ritchie & T BELL Laboratory, New Jersey, USA in 1972.
  • 4. FEATURES OF ‘C’ 4  Robust Language, for writing any complex program.  Built-in Functions & Data types.  Suitable for writing both System Software and Business Applications.  Efficient & Faster in Execution.  Highly Portable.  Dynamic Memory Allocation (DMA)
  • 5. STRUCTURE OF A C PROGRAM YCT Academy, FB : facebook/pankajsir007 5 #include<stdio.h> #define PI 3.14 void main() { statements; …….. } Preprocessor Symbol ( # ) Header file (all files with Extension *.h) Symbolic Constants Function main() (Entry point for any C Program) Function Block (main() function Starting and ending Limit within { }) Statements; (all the coding which to be written for Execution) include for including The file at Preprocessing < > to locate The file in the Default Include Directory
  • 6. TOKENS (The smallest individual unit in a C Program) YCT Academy, FB : facebook/pankajsir007 6  Identifiers  Keywords  Constants  Special Characters
  • 7. IDENTIFIERS YCT Academy, FB : facebook/pankajsir007 7  Identifiers can be defined as the name of the variables and some other program elements.  It can be the combination of the following characters. Alphabets (a-z, A-Z), Numbers (0-9) & Underscore ( _ ).  All the names used to refer an element in a program is said to be Identifier.  Examples of some valid identifiers name, mark1, total_marks, _avg
  • 8. KEYWORDS YCT Academy, FB : facebook/pankajsir007 8  Keywords are also identifiers but cannot be user defined since they are reserved words.  Keywords are some special words for which the meaning is already known to the compiler.  All the keywords should be in lower case letters.  Examples for some keywords are if, break, else, return, void, etc.
  • 9. CONSTANTS YCT Academy, FB : facebook/pankajsir007 9  Constants are of three types : 1) Literal Integer Constants. 2) Literal Floating point Constants. 2) Literal Character Constants. 3) Literal String Constants.  Literal Integer Constants are all positive and negative numbers like 1, -5, 1548, -58469, etc.  Literal Floating point Constants are all decimal numbers like 12.25, 0.564, 56.e38, etc.  Literal Character Constants are all single characters represented within single quotes like ‘A’, ‘a’, ‘:’, ‘1’, etc.  Literal String Constants are group of characters represented within double quotes like “Hello”, “Programming”, “A”, etc.
  • 10. THE PREPROCESSING ( # ) YCT Academy, FB : facebook/pankajsir007 10  # is called as the pre-processor symbol.  The statements which are following the # symbol will get pre- processed, so they are called as pre-processor directives.  Pre-Processing is done by the preprocessor which inserts the files given with the pre-processor symbol # into the actual program before it gets executed.  Pre-Processing is done before the actual main program is compiled by the compiler. Any statements that follow the # symbol will be embedded as if present in the actual program.
  • 11. COMPILATION & EXECUTION OF A C PROGRAM YCT Academy, FB : facebook/pankajsir007 11  The Source Code files of C are saved with the extension ( *.C ) (where * denotes the file name)  They are then compiled by the compiler to a Object Code ( *.obj )  Then the Object Code will be linked by the Linker to form the Machine Language also known as Executable Code, files with extension ( *.exe)
  • 12. COMPILATION & EXECUTION OF A C PROGRAM YCT Academy, FB : facebook/pankajsir007 12 C Program (with *.C extension) Preprocessor Object Code (with *.obj extension) Executable Code (with *.exe extension) Compiler Linker
  • 13. SYMBOLIC CONSTANTS YCT Academy, FB : facebook/pankajsir007 13  The #define statement is used to create Symbolic Constants known as Macros (replacement text).  The statement #define PI 3.14 will create PI to have the constant value 3.14.  The constant created with #define can be used in program that will represent the constant value defined for it.  It is also used to create Macro Functions or Macros.
  • 14. HEADER FILES (*.h) YCT Academy, FB : facebook/pankajsir007 14  Files with the extension *.h are said to Header Files.  In a C program many inbuilt functions might be used, those functions Prototype (Declaration) need to known to compiler which are already specified in the particular header files related to them.  The header file like stdio.h is the Standard Input / Output header file which contains the Prototype or Declaration for all the inbuilt Input / Output related functions.  In in C Program different header files might be included in the pre- processor based on the inbuilt functions used by the program.
  • 15. The main() Function YCT Academy, FB : facebook/pankajsir007 15  In every C Program there will be at least one function without which the program does not execute which is the main() function.  The main() Function is the Entry Point for every program from which the compiler starts to compile the program.  All the C Programs start to execute from the Open Block { where the main() function begins and ends at the Close Block } where it ends.  So, the statements or coding written inside the main() block gets executed at the runtime of the program.
  • 16. TWO TYPES OF main() FUNCTION YCT Academy, FB : facebook/pankajsir007 16 #include<stdio.h> void main() { statements; ……. ……. } #include<stdio.h> int main() { statements; ……. return 0; } Syntax for a Function or A Function is identified by the following return_type Function_name(argument_list) Here the return_type is the value which the function returns back to the area from where it was invoked. The Function_name is the name given to the function and the () just following the function name is the identification that it is a function within which arguments passed to the function will be specified.
  • 17. DATA TYPES IN ‘C’ Data Types Primary Data Types Integers Floating Points Characters Strings Derived Data Types Arrays Pointers Functions User-Defined Types Structures Unions Enumerations YCT Academy, FB : facebook/pankajsir007 17
  • 18. Description Keyword Format String Memory Range Short Range of numbers int %d 2 Bytes -32768 to +32767 Long Range of numbers long %ld 4 Bytes -2147483648 to +2147483647 YCT Academy, FB : facebook/pankajsir007 18 INTEGERS
  • 19. Description Keyword Format String Memory Range Single Precision Decimal numbers float %f 4 bytes 3.4 e-38 to 3.4e+38 Double Precision Decimal Numbers double %lf 8 bytes 1.7e-308 to 1.7e+308 Range of Decimals beyond double long double %Lf 10 bytes 3.4e-4932 to 1.1e+4932 YCT Academy, FB : facebook/pankajsir007 19 FLOATING POINTS
  • 20. CHARACTERS Description Keyword Format String Memory Range Single Characters char %c 1 Byte -128 to +127 YCT Academy, FB : facebook/pankajsir007 20 All the Alphabets, Numbers, Special Symbols represented within SINGLE QUOTES are said to characters. For example ‘a’ ‘A’ ‘{‘ ‘:’ ‘1’ All Characters have a unique Number Representation which is called as the ASCII CODE. ASCII means American Standard Code for Information Interchange. For example the ASCII Value for the character ‘A’ is 65 and ‘0’ is 48
  • 21. THE unsigned DATA TYPE MODIFIER Description Keyword Format String Memory Range Short Range of unsigned numbers unsigned int %u 2 Bytes 0 to 65535 Long Range of unsigned numbers unsigned long %u 4 Bytes 0 to 4294967295 Unsigned Characters unsigned char %u 1 byte 0 to 255 YCT Academy, FB : facebook/pankajsir007 21 Syntax : unsigned <type> <variable> ; Description : Use the unsigned type modifier when variable values will always be positive. The unsigned modifier can be applied to base types int, char, long, and short. When the base type is omitted from a declaration, int is assumed.
  • 22. VARIABLES YCT Academy, FB : facebook/pankajsir007 22  Variables are names used to refer the memory location where different constants are stored.  It is like a label given to a particular memory location where the values of constants are stored.  For example lets see the pictorial memory representation when a value is stored in memory for a declaration like char ch; …..100 101 102 103 104 105 106 107 108 109 110 111 …. ch Address of the memory Variable name Value at the memory
  • 23. RULES FOR GIVING VARIABLE NAMES YCT Academy, FB : facebook/pankajsir007 23  It should begin with a alphabet or underscore ( _ ) followed by any combination of alphabets, underscores, or digits. E.g. int n1;  Variable names are case-sensitive i.e. uppercase are different from lower case letter. E.g. int a, A;  Variable names cannot be a Keyword.  No Commas or blank spaces are allowed within a Variable name.  Length for declaring a variable depends on the complier.
  • 24. STRINGS YCT Academy, FB : facebook/pankajsir007 24  Strings are Group of Characters. In C strings are said to be Character Arrays.  Array is a collection of similar type of elements referred by a single name and allocated in a contiguous memory locations.  char Array_name[size]; where char is data type, Array name is the name given to the array and [] is the subscript or Delimiters of the array within which the size that is the no. of characters that the array can contain is specified.  Strings in C are called as NULL TERMINATED CHARACTER ARRAYS. A special character called as the NULL character ( ‘0’ ) a backslash with a zero is the last character ending the array which is automatically inserted by the C compiler after the last character inputed.  For example char name[10] = “Dennis”; ‘D’ ‘e’ ‘n’ ‘n’ ‘i’ ‘s’ ‘0’ [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] 100 101 102 103 104 105 106 107 108 109 Index of The Array Element of the array Address of each Element of the array
  • 25. OPERATORS YCT Academy, FB : facebook/pankajsir007 25  Arithmetic Operators  Relational Operators  Logical Operators  Assignment Operators  Conditional or Ternary Operator
  • 26. ARITHEMETIC OPERTORS YCT Academy, FB : facebook/pankajsir007 26  Addition Operator +  Subtraction Operator –  Multiplication Operator *  Quotient Division Operator /  Reminder Division or Modulus Operator %
  • 27. UNARY OPERATORS YCT Academy, FB : facebook/pankajsir007 27 UNARY + OPERATOR  The Operator unary ‘+’ precedes an operand.  Operand is the value on which the operator operates.  For Example  If a=5 then +a means 5  If a=0 then +a means 0  If a=-4 then +a means - 4 UNARY - OPERATOR  The Operator unary – precedes an operand.  For Example  If a=5 then –a means -5  If a=0 then –a means 0  If a=-4 then –a means 4  This operator reverses the sign of the operand’s value Operators that act on one operand are referred to as Unary Operators
  • 28. BINARY OPERATORS YCT Academy, FB : facebook/pankajsir007 28  The operands of a binary operator are distinguished as the left or right operand. Together, the operator and its operand is called as an expression.  For Example addition of two numbers 4+20 results in 24.  If a=4 and b=6 then a + b will result in 10 where the left side operand and the right side operand is b.  The Modulus Operator (%) produces the reminder of dividing the first by the second operand. For example 19 % 6 evaluates to 1, since 6 goes into 19 three times with a reminder 1. Note that the both operands must be integer data types when using modulus operator (%). Operators that act on two operands are referred to as Binary Operators
  • 29. RELATIONAL OPERATORS YCT Academy, FB : facebook/pankajsir007 29  Less than Operator <  Less than or equal to Operator <=  Greater than Operator >  Greater than or equal to Operator >=  Equality Operator ==  Not Equality Operator !=
  • 30. LOGICAL OPERATORS YCT Academy, FB : facebook/pankajsir007 30 Logical AND Operator && This operator is used to combine two expressions into one and check whether the both the expressions are true For example:- (6<9)&&(4>2) is true 6==6&&4==3 is false If a=4 and b=4 then (a>=a) && (b<=b) is true Logical OR Operator || This operator is used to combine two expressions into one and check whether any one of the expressions are true. For example:- (5>8) || (5<2) is false 6==6 || 4==3 is true If a=4 and b=4 then (a>a) || (b<=b) is true C considers 0 as a false value and any non-zero value as a true value
  • 31. ASSIGNMENT OPERATORS YCT Academy, FB : facebook/pankajsir007 31  Normal Assignment = For e.g. int a=10;  Addition Assignment += For e.g. int a=10,b=10; then a += b means a = a + b;  Multiplication Assignment *=  Subtraction Assignment -=  Division Assignment /=  Modulus Assignment %= Assignment Operators assign value from Right to Left. That is right side operand value is assigned to the left side operand
  • 32. UNARY INCREMENT / DECREMENT OPERATORS (++, --) YCT Academy, FB : facebook/pankajsir007 32  C includes two useful operators which is not generally found in other computer languages.  These are the increment and decrement operators, ++ and --  The operator ++ adds 1 to its operand, and -- subtracts one. In other words, a = a + 1 is same as ++a or a++ and a = a – 1 is same as --a or a--
  • 33. PREFIXING OF ++ OR -- YCT Academy, FB : facebook/pankajsir007 33 The Prefix increment or decrement operators follow CHANGE-THEN-USE rule i.e. they first change (increment or decrement) the value of their operand, then use the new value in evaluating the expression. For example, Prefixing of ++ Prefixing of -- int a=10, b; b = ++a; Here first a = a + 1 is done and the new value is assigned to b. So b will be 11 and a will also be 11 int a=10, b; b = --a; Here first a = a - 1 is done and the new value is assigned to b. So b will be 9 and a will also be 9
  • 34. POSTFIXING OF ++ OR -- YCT Academy, FB : facebook/pankajsir007 34 The Postfix increment or decrement operators follow USE-THEN-CHANGE rule i.e. they first use the value of their operand in evaluating the expression and then change (increment / decrement) the operand’s value. For example, Postfixing of ++ Postfixing of -- int a=10, b; b = a++; Here first a value is assigned to b and then a = a + 1 increments the value of a. So, b will be 10 and a will be 11. int a=10, b; b = a--; Here first a value is assigned to b and then a = a - 1 decrements the value of a. So, b will be 10 and a will be 9.
  • 35. CONDITIONAL / TERNARY OPERATOR YCT Academy, FB : facebook/pankajsir007 35 C offers a conditional operator ?: that stores a value depending upon a condition. This operator is ternary i.e., it requires three operands. The general form of conditional operator ?: is as follows:- expression1 ? expression2 : expression3 If expression1 evaluates to be true i.e. 1, then the value of the whole expression is the value of expression2, otherwise the value of the whole expression is the value of the expression3. For example, result = marks >=50 ? ‘P’ : ‘F’; 4==9 ? 10 : 25 evaluates to 25 because test expression 4==9 is false. (a>b ? (a>c ? a : c) : (b>c ? b : c); In the above statement the expression will be having the highest value among the three a, b & c.
  • 36. FORMATTED I / O FUNCTIONS YCT Academy, FB : facebook/pankajsir007 36  The function printf() is used to print the formatted output on the standard output device (monitor). The function printf() is an inbuilt function which is defined in the header file stdio.h  The function scanf() is used to read the formatted input from the standard input device (keyboard). The function scanf() is an inbuilt function defined in the header file stdio.h  The header file stdio.h should be included in the preprocessor directive to use the above mentioned printf() and scanf() functions in the program
  • 37. THE printf() FUNCTION YCT Academy, FB : facebook/pankajsir007 37 Syntax : printf(“formatstring”,arg list); Example statements for showing the use of printf() function E.g. 1. printf(“Welcome to C Programming”); E.g. 2. int a=10; printf(“Value of a = %d”,a); E.g. 3. int x=10;long y = 200L; float z = 20.5; printf(“x = %d y = %ld z = %f”,x,y,z); printf() function always works from Right to Left that is in the above example from the last the value of z gets printed in the last format string %f and then value of y gets printed in the place of %ld location and finally the value of x gets printed in the place of %d location
  • 38. THE scanf() FUNCTION YCT Academy, FB : facebook/pankajsir007 38 Syntax : scanf(“formatstring”,arg list); Example statements for showing the use of scanf() function E.g. 2. int a; scanf(“%d”,&a); E.g. 3. int x; long y; float z; scanf(“%d%ld%f”,&x,&y,&z); scanf() function always works from Left to Right that is the first number inputted will be assigned to x and then the next number inputted will be assigned to y and the last number inputted will be assigned to z. Here the & operator which is called as the address of operator is used to mention the address of the variable where the value is to be stored. Only when strings are inputted the & operator is not used in the scanf() functions other than this for all other data types the & operator is a must to be prefixed before the variable name in the scanf() function.