SlideShare a Scribd company logo
1 of 64
C Programming
🞂 Developed by Dennis Richie
🞂 Developed at Bell Lab in U.S.A. in 1972
🞂 Derived from a language known as BCPL
(Basic Combined Programming Language)
Introduction
🞂 Creating Source Code
🞂 Compiling Source Code
🞂 Linking the source code
🞂 Running the executable file
Program Development Cycle
Program Development Cycle
Written in
C
Program
Editor
Source
Code
Pre-
processed
Code
Compilation
Linker
Object
Code
Executable
Code
🞂 Documentation Section
🞂 Link Section
🞂 Definition Section
🞂 Global Declaration Section
🞂 Function Section
🞂 Main Function()
🞂 {
🞂 Declaration
🞂 Executable Part
🞂 }
🞂 Sub Program Section
🞂 {
🞂 Function 1()
🞂 …
🞂 Function n ()
🞂 }
Structure of C program
History of C
🞂 Character Set
🞂 Upper case and lowercase characters, 0-9
digits, special characters, white spaces
1. Alphabets A-Z, a-z
2. Digits 0-9
3. Special Characters #, @, &, %, _,-
4. White Space Characters blank space, tab,
new line
Variables, Data Types, Operators, Expression
C Token
Identifiers Keywords Constants
String
Literals
Operators
Other
Symbols
C Tokens
Identifier is a user defined name given to a
program element – variable, functions,
symbolic constants
Rules for naming identifier :-
1) Must be sequence of alphabets & digits
2) Must begin with alphabet
3) No special symbol except (_) is allowed
4) Reserve word should not used as identifier
5) C is case sensitive
6) For naming maximum 32 characters are
allowed
Identifiers and Keywords
Keywords are reserve words & predefined by language. The
can not be used by programmer in any other than specifie
by syntax. C provides 32 keywords.
Keywords
auto
break
case
char
const
continue
default
do
double
else
enum
extern
float
for
goto
if
int
long
register
return
while
volatile
short
signed
sizeof
static
struct
switch
typedef
union
unsigned
void
_Alignas (C11)
_Alignof (C11)
_Atomic (C11)
_Bool (C99 beyond)
_Complex (C99 beyond)
_Generic (C11)
_Imaginary (C99
beyond)
_Noreturn (C11)
_Static_assert (C11)
_Thread_local (C11)
inline (C99 beyond)
restrict (C99 beyond)
Constants refers to fixed value that do not
changes during program execution. They can
be classified as :
1) integer constants
2) floating point constants
3) character constants
4) string constants
Constants
int y = 123; //here 123 is a decimal integer constant
int x = 0123; // here 0123 is a octal integer constant
int x = 0x12 // here Ox12 is a Hexa-Decimal integer constant
float x = 6.3; //here 6.3 is a double constant.
float y = 6.3f; //here 6.3f is a float constant.
float z = 6.3 e + 2; //here 6.3 e + 2 is a exponential constant.
float s = 6.3L ; //here 6.3L is a long double constant
char p ='ok' ; // p will hold the value 'O' and k will be omitted
char y ='u'; // y will hold the value 'u'
char k ='34' ; // k will hold the value '3, and '4' will be omitted
char e =' '; // e will hold the value ' ' , a blank space
chars ='45'; // swill hold the value ' ' , a blank space
Backslash Character Constants [Escape
Sequences]
Constant Meaning
‘a’ .Audible Alert (Bell)
‘b’ .Backspace
‘f’ .Formfeed
‘n’ .New Line
‘r’ .Carriage Return
‘t’ .Horizontal tab
‘v’ .Vertical Tab
‘” .Single Quote
‘”‘ .Double Quote
‘?’ .Question Mark
‘’ .Back Slash
‘0’ .Null
A variable name is an identifier or symbolic name assigned
the memory location where data is stored. A variable ca ha
only one value assigned to it at any given time during
program execution. Its value may change during execution
the program.
Variables
Data Types in C
🞂 The size qualifiers are :
short
long
🞂 Sign qualifiers
signed
unsigned
Qualifiers
Integer Data Types
Floating type data types
Character Data Type
Arithmetic Operators
Operator Symbol Action Example
Addition + Adds operands x + y
Subtraction - Subs second from first x - y
Negation - Negates operand -x
Multiplication * Multiplies operands x * y
Division / Divides first by second x / y
(integer quotient)
Modulus % Remainder of divide op x % y
Assignment Operator
 x=3
– = is an operator
– The value of this expression is 3
– = operator has a side effect -- assign 3 to x
 The assignment operator =
– The side-effect is to assign the value of the right hand side (rhs) to the left hand side
(lhs).
– The value is the value of the rhs.
 For example:
x = ( y = 3 ) +1; /* y is assigned 3 */
/* the value of (y=3) is 3 */
/* x is assigned 4 */
Compound Assignment Operator
 Often we use “update” forms of operators
– x=x+1, x=x*2, ...
 C offers a short form for this:
– Generic Form
variable op= expr equivalent to variable = variable op expr
– Update forms have value equal to the final value of expr
 i.e., x=3; y= (x+=3); /* x and y both get value 6 */
Operator Equivalent to:
x *= y x = x * y
y -= z + 1 y = y - (z + 1)
a /= b a = a / b
x += y x = x + y
y %= 3 y = y % 3
Increment and Decrement
 Pre Increment [++x]:
the value of a variable is first incremented by 1, and then the
updated value is used in the expression.
 Post Increment [x++]:
the variable's original value is used in the expression first, and
then the post-increment operator updates the operand value
by 1.
 Pre Decrement [--x]:
the value of a variable is first decremented by 1, and then the
updated value is used in the expression.
 Post Decrement [x--]:
the variable's original value is used in the expression first, and
then the post-decrement operator updates the operand value
by substracting 1.
Pre Increment and Post Increment
#include <stdio.h>
int main() {
int x = 7;
int y = ++x;
printf("x is %dn", x);
printf("y is %dn", y);
return 0;
}
Output :
x is 8
y is 8
#include <stdio.h>
int main() {
int x = 7;
int y = x++;
printf("x is %dn", x);
printf("y is %dn", y);
return 0;
}
Output :
x is 8
y is 7
Pre Decrement and Post Decrement
#include <stdio.h>
int main() {
int x = 7;
int y = --x;
printf("x is %dn", x);
printf("y is %dn", y);
return 0;
}
Output :
x is 6
y is 6
#include <stdio.h>
int main() {
int x = 7;
int y = x--;
printf("x is %dn", x);
printf("y is %dn", y);
return 0;
}
Output :
x is 6
y is 7
Relational Operators
 Relational operators allow you to compare variables.
– They return a 1 value for true and a 0 for false.
Operator Symbol Example
Equals == x == y NOT x = y
Greater than > x > y
Less than < x < y
Greater/equals >= x >= y
Less than/equals <= x <= y
Not equal != x != y
 There is no bool type in C. Instead, C uses:
– 0 as false
– Non-zero integer as true
Relational Operators
#include <stdio.h>
int main() {
int p = 5, q = 5, r = 10;
printf(“%d == %d is %d n”, p, r, p == r);
printf(“%d == %d is %d n”, p, q, p == q);
printf(“%d > %d is %d n”, p, r, p > r);
printf(“%d > %d is %d n”, p, q, p > q);
printf(“%d < %d is %d n”, p, r, p < r);
printf(“%d < %d is %d n”, p, q, p < q);
printf(“%d != %d is %d n”, p, r, p != r);
printf(“%d != %d is %d n”, p, q, p != q);
printf(“%d >= %d is %d n”, p, r, p >= r);
printf(“%d >= %d is %d n”, p, q, p >= q);
printf(“%d <= %d is %d n”, p, r, p <= r);
printf(“%d <= %d is %d n”, p, q, p <= q);
return 0;
}
The output generated here would be:
5 == 10 is 0
5 == 5 is 1
5 > 10 is 0
5 > 5 is 0
5 < 10 is 1
5 < 5 is 0
5 != 10 is 1
5 != 5 is 0
5 >= 10 is 0
5 >= 5 is 1
5 <= 10 is 1
5 <= 5 is 1
Logical Operators
 && Logical AND Operator
If both operands are non zero then the condition becomes true. Otherwise, the result has a value
of 0.
// C program for Logical AND Operator
#include <stdio.h>
int main()
{
int a = 10, b = 20;
if (a > 0 && b > 0) {
printf("Both values are greater than 0n");
}
else {
printf("Both values are less than 0n");
}
return 0;
}
Output :
X Y X && Y
1 1 1
1 0 0
0 1 0
0 0 0
Both values are greater than 0
Logical Operators
 || Logical OR Operator
The condition becomes true if any one of them is non-zero. Otherwise, it returns false i.e., 0 as the
value.
// C program for Logical OR Operator
#include <stdio.h>
int main()
{
int a = -1, b = 20;
if (a > 0 || b > 0) {
printf("Any one of the given value is greater than 0n");
}
else {
printf("Both values are less than 0n");
}
return 0;
}
Output :
X Y X || Y
1 1 1
1 0 1
0 1 1
0 0 0
Any one of the given value is greater than 0
Logical Operators
 ! Logical NOT Operator
If the condition is true then the logical NOT operator will make it false and vice-versa.
// C program for Logical NOT Operator
#include <stdio.h>
int main()
{
int a = 10, b = 20;
if (!(a > 0 && b > 0)) {
// condition returned true but logical NOT operator changed it to false
printf("Both values are greater than 0n");
}
else {
printf("Both values are less than 0n");
}
return 0;
}
Output :
Both values are less than 0
X !X
0 1
1 0
Operating on Bits (1)
 C allows you to operate on the bit
representations of integer variables.
– Generally called bit-wise operators.
 All integers can be thought of in binary form.
– For example, suppose ints have 16-bits
6552010 = 1111 1111 1111 00002 = FFF016 = 1777608
 In C, hexadecimal literals begin with 0x, and octal
literals begin with 0.
x=65520; base 10
x=0xfff0; base 16 (hex)
x=0177760; base 8 (octal)
Operating on Bits (2)
Bitwise operators
 The shift operator:
– x << n
 Shifts the bits in x to n positions to the left, shifting in zeros
on the right.
 If x = 1111 1111 1111 00002
x << 1 equals 1111 1111 1110 00002
– x >> n
 Shifts the bits in x to n positions right.
– shifts in the sign if it is a signed integer (arithmetic shift)
– shifts in 0 if it is an unsigned integer
 x >> 1 is 0111 1111 1111 10002 (unsigned)
 x >> 1 is 1111 1111 1111 10002 (signed)
Operating on Bits (3)
 Bitwise logical operations
– Work on all integer types
 & Bitwise AND
x= 0xFFF0
y= 0x002F
x&y= 0x0020
 | Bitwise Inclusive OR
x|y= 0xFFFF
 ^ Bitwise Exclusive OR
x^y= 0xFFDF
 ~ The complement operator
~ y= 0xFFD0
– Complements all of the bits of X
X Y X ^ Y
1 1 0
1 0 1
0 1 1
0 0 0
Shift, Multiplication and Division
 Multiplication and division is often slower than shift.
 Multiplying 2 can be replaced by shifting 1 bit to the left.
n = 10
printf(“%d = %d” , n*2, n<<1);
printf(“%d = %d”, n*4, n<<2);
……
 Division by 2 can be replace by shifting 1 bit to the right.
n = 10
printf(“%d = %d” , n/2, n>>1);
printf(“%d = %d”, n/4, n>>2);
Operator Precedence and Associativity
 Operator precedence
– It determines the order in which different operators are evaluated in an expression.
– This is important because it can change the outcome of an expression if not
understood correctly.
 Operator associativity
– It determines the order in which operators of the same precedence are evaluated when
they appear in a sequence without parentheses.
– There are two types of associativity: left-to-right and right-to-left.
Operator Precedence
Operator Precedence level
( ) 1
~, ++, --, unary - 2
*, /, % 3
+, - 4
<<, >> 5
<, <=, >, >= 6
==, != 7
& 8
^ 9
| 10
&& 11
|| 12
=, +=, -=, etc. 14
We’ll be adding more to this list later on...
Operator Precedence
Operator Precedence and Associativity
Operator Precedence example
#include <stdio.h>
int main()
{
int x = 5;
int y = 3;
int result = x+++y
printf("%d %d %d",x,y,result);
return 0;
}
OUTPUT:
 6 3 8
#include <stdio.h>
int main()
{
int x = 5;
int y = 3;
int result = ++x+y
printf("%d %d %d",x,y,result);
return 0;
}
OUTPUT:
 6 3 9
An Example
 What is the difference between the two lines of output?
#include <stdio.h>
int main ()
{
int w=10,x=20,y=30,z=40;
int temp1, temp2;
temp1 = x * x /++y + z / y;
printf ("temp1= %d;nw= %d;nx= %d;ny= %d;nz= %dn",
temp1, w,x,y,z);
y=30;
temp2 = x * x /y++ + z / y;
printf ("temp2= %d;nw= %d;nx= %d;ny= %d;nz= %dn",
temp2, w,x,y,z);
return 0;
}
Conditional Operator
 The conditional operator essentially allows you to embed an “if” statement into an
expression
 Generic Form
exp1 ? exp2 : exp3 if exp1 is true (non-zero)
value is exp2
(exp3 is not evaluated)
if exp1 is false (0),
value is exp3
(exp2 is not evaluated)
 Example:
z = (x > y) ? x : y;
 This is equivalent to:
if (x > y)
z = x;
else
z = y;
Comma Operator
 An expression can be composed of multiple
subexpressions separated by commas.
– Subexpressions are evaluated left to right.
– The entire expression evaluates to the value of the
rightmost subexpression.
 Example:
x = (a++, b++);
 a is incremented
 b is assigned to x
 b is incremented
– Parenthesis are required because the comma operator has
a lower precedence than the assignment operator!
 The comma operator is often used in for loops.
Comma Operator and For Loop
 Example:
 int i, sum;
 for (i=0,sum=0;i<100;i++){
 sum += i;
 }
 printf(“1+...+100 = %d”, sum);
🞂 Local
🞂 Global
Scope of Variables
main()
{
int a, b;
}
void add(int x, int y)
{
int sum=0;
sum=x+y;
printf(“n Sum = %d”, sum);
}
Local Variable
int a, b;
main()
{
printf (“n in main a=%d”,a);
}
void val(int x)
{
a=x;
printf(“n in Function = %d”,a);
}
Global Variable
🞂 Arithmetic
🞂 Relational
🞂 Logical
🞂 Assignment
🞂 Increment/ Decrement
🞂 Conditional
Opeators
🞂 A=10
🞂 B=10
🞂 A==B
🞂 &&
🞂 ||
🞂 !
Logical
if(age>18) &&(citizen==“Indian”)
{
printf(“Elegible for voting”);
}
else
{
printf(“n Not eligible for voting”);
}
And &&
If(day==“Saturday” ) || (day==“Sunday”)
{
printf(“Its holiday”);
}
else
{
printf(“Working day”);
}
Or ||
If(n!=0)
{
printf(“%d”,n);
}
Else
{
printf(“Its zero”);
}
!not
🞂 + +
i=1
i++
I is 2
i+2
I is 4
🞂 - -
J=5
J- -
Jis 4
Increment/decrement
🞂 Ans= (condition)
🞂 A=15
🞂 B =5
Z=A>B ? A:B
? Opt1 :opt2
Conditional operators
Int a;
Sizeof(a)
2
sizeof
🞂 Input means to provide the program with some data to be
used in the program and Output means to display data on the
screen or write the data to a printer or a file.
🞂 The C programming language provides standard library
functions to read any given input and to display data on the
console.
Input/Output Statement in C
The functions used for standard input and output are
present in the stdio.h header file. Hence to use the
functions we need to include the stdio.h header file
#include<stdio.h>
Following are the functions used for standard input and
output:
printf() function - Show Output
scanf() function - Take Input
getchar() and putchar() function
gets() and puts() function
🞂 The printf() function is the most used function in the C
language. This function is defined in the stdio.h header
file and is used to show output on the console (standard
output).
🞂 This function is used to print a simple text
sentence or value of any variable which can be
of int, char, float, or any other datatype.
printf() function
🞂 To print values of different datatypes using
the printf() statement, we need to use format
specifiers, like we have used in the code examples
above.
🞂 Also, when we take input from user using
the scanf() function, then also, we have to specify
what type of input to expect from the user using
these format specifiers.
Format Specifiers
Datatype Format Specifier
int %d, %i
char %c
float %f
double %lf
short int %hd
unsigned int %u
long int %li
unsigned long int %lu
signed char %c
unsigned char %c
long double %Lf
🞂 When we want to take input from the user, we use
the scanf() function. When we take input from the user, we store the
input value into a variable.
🞂 The scanf() function can be used to take any datatype input from user,
all we have to take care is that the variable in which we store the value
has the same datatype.
scanf()
🞂 The getchar() function reads a character from the terminal
and returns it as an integer. This function reads only a sin
character at a time.
🞂 The putchar() function displays the character passed to it o
the screen and returns the same character. This function t
displays only a single character at a time.
🞂 In case you want to display more than one character, use
putchar() method in a loop.
getchar() & putchar()
🞂 The gets() function reads a line from stdin(standard
input) into the buffer pointed to by str pointer, until
either a terminating newline or EOF (end of file)
occurs.
🞂 The puts() function writes the string str and a trailing
newline to stdout.
gets() & puts()

More Related Content

Similar to introduction to c programming and C History.pptx

C Operators and Control Structures.pdf
C Operators and Control Structures.pdfC Operators and Control Structures.pdf
C Operators and Control Structures.pdfMaryJacob24
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Languagemadan reddy
 
Computer programming chapter ( 4 )
Computer programming chapter ( 4 ) Computer programming chapter ( 4 )
Computer programming chapter ( 4 ) Ibrahim Elewah
 
C Operators and Control Structures.pptx
C Operators and Control Structures.pptxC Operators and Control Structures.pptx
C Operators and Control Structures.pptxramanathan2006
 
PROGRAMMING IN C - Operators.pptx
PROGRAMMING IN C - Operators.pptxPROGRAMMING IN C - Operators.pptx
PROGRAMMING IN C - Operators.pptxNithya K
 
Lecture 3 and 4.pptx
Lecture 3 and 4.pptxLecture 3 and 4.pptx
Lecture 3 and 4.pptxMAHAMASADIK
 
presentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptxpresentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptxKrishanPalSingh39
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxhappycocoman
 
Types of Operators in C programming .pdf
Types of Operators in C programming  .pdfTypes of Operators in C programming  .pdf
Types of Operators in C programming .pdfRichardMathengeSPASP
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statementsMomenMostafa
 
B.sc CSIT 2nd semester C++ Unit2
B.sc CSIT  2nd semester C++ Unit2B.sc CSIT  2nd semester C++ Unit2
B.sc CSIT 2nd semester C++ Unit2Tekendra Nath Yogi
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++Neeru Mittal
 
C programming Lab 2
C programming Lab 2C programming Lab 2
C programming Lab 2Zaibi Gondal
 
5 c control statements looping
5  c control statements looping5  c control statements looping
5 c control statements loopingMomenMostafa
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 FocJAYA
 

Similar to introduction to c programming and C History.pptx (20)

C Operators and Control Structures.pdf
C Operators and Control Structures.pdfC Operators and Control Structures.pdf
C Operators and Control Structures.pdf
 
C tutorial
C tutorialC tutorial
C tutorial
 
Operators1.pptx
Operators1.pptxOperators1.pptx
Operators1.pptx
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Language
 
Computer programming chapter ( 4 )
Computer programming chapter ( 4 ) Computer programming chapter ( 4 )
Computer programming chapter ( 4 )
 
c_tutorial_2.ppt
c_tutorial_2.pptc_tutorial_2.ppt
c_tutorial_2.ppt
 
C Operators and Control Structures.pptx
C Operators and Control Structures.pptxC Operators and Control Structures.pptx
C Operators and Control Structures.pptx
 
PROGRAMMING IN C - Operators.pptx
PROGRAMMING IN C - Operators.pptxPROGRAMMING IN C - Operators.pptx
PROGRAMMING IN C - Operators.pptx
 
C language basics
C language basicsC language basics
C language basics
 
Lecture 3 and 4.pptx
Lecture 3 and 4.pptxLecture 3 and 4.pptx
Lecture 3 and 4.pptx
 
presentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptxpresentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptx
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
 
Types of Operators in C programming .pdf
Types of Operators in C programming  .pdfTypes of Operators in C programming  .pdf
Types of Operators in C programming .pdf
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statements
 
l7-pointers.ppt
l7-pointers.pptl7-pointers.ppt
l7-pointers.ppt
 
B.sc CSIT 2nd semester C++ Unit2
B.sc CSIT  2nd semester C++ Unit2B.sc CSIT  2nd semester C++ Unit2
B.sc CSIT 2nd semester C++ Unit2
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
C programming Lab 2
C programming Lab 2C programming Lab 2
C programming Lab 2
 
5 c control statements looping
5  c control statements looping5  c control statements looping
5 c control statements looping
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
 

Recently uploaded

Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 

Recently uploaded (20)

Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 

introduction to c programming and C History.pptx

  • 2. 🞂 Developed by Dennis Richie 🞂 Developed at Bell Lab in U.S.A. in 1972 🞂 Derived from a language known as BCPL (Basic Combined Programming Language) Introduction
  • 3. 🞂 Creating Source Code 🞂 Compiling Source Code 🞂 Linking the source code 🞂 Running the executable file Program Development Cycle
  • 4. Program Development Cycle Written in C Program Editor Source Code Pre- processed Code Compilation Linker Object Code Executable Code
  • 5. 🞂 Documentation Section 🞂 Link Section 🞂 Definition Section 🞂 Global Declaration Section 🞂 Function Section 🞂 Main Function() 🞂 { 🞂 Declaration 🞂 Executable Part 🞂 } 🞂 Sub Program Section 🞂 { 🞂 Function 1() 🞂 … 🞂 Function n () 🞂 } Structure of C program
  • 7. 🞂 Character Set 🞂 Upper case and lowercase characters, 0-9 digits, special characters, white spaces 1. Alphabets A-Z, a-z 2. Digits 0-9 3. Special Characters #, @, &, %, _,- 4. White Space Characters blank space, tab, new line Variables, Data Types, Operators, Expression
  • 8. C Token Identifiers Keywords Constants String Literals Operators Other Symbols C Tokens
  • 9. Identifier is a user defined name given to a program element – variable, functions, symbolic constants Rules for naming identifier :- 1) Must be sequence of alphabets & digits 2) Must begin with alphabet 3) No special symbol except (_) is allowed 4) Reserve word should not used as identifier 5) C is case sensitive 6) For naming maximum 32 characters are allowed Identifiers and Keywords
  • 10. Keywords are reserve words & predefined by language. The can not be used by programmer in any other than specifie by syntax. C provides 32 keywords. Keywords auto break case char const continue default do double else enum extern float for goto if int long register return while volatile short signed sizeof static struct switch typedef union unsigned void _Alignas (C11) _Alignof (C11) _Atomic (C11) _Bool (C99 beyond) _Complex (C99 beyond) _Generic (C11) _Imaginary (C99 beyond) _Noreturn (C11) _Static_assert (C11) _Thread_local (C11) inline (C99 beyond) restrict (C99 beyond)
  • 11. Constants refers to fixed value that do not changes during program execution. They can be classified as : 1) integer constants 2) floating point constants 3) character constants 4) string constants Constants
  • 12. int y = 123; //here 123 is a decimal integer constant int x = 0123; // here 0123 is a octal integer constant int x = 0x12 // here Ox12 is a Hexa-Decimal integer constant float x = 6.3; //here 6.3 is a double constant. float y = 6.3f; //here 6.3f is a float constant. float z = 6.3 e + 2; //here 6.3 e + 2 is a exponential constant. float s = 6.3L ; //here 6.3L is a long double constant char p ='ok' ; // p will hold the value 'O' and k will be omitted char y ='u'; // y will hold the value 'u' char k ='34' ; // k will hold the value '3, and '4' will be omitted char e =' '; // e will hold the value ' ' , a blank space chars ='45'; // swill hold the value ' ' , a blank space
  • 13. Backslash Character Constants [Escape Sequences] Constant Meaning ‘a’ .Audible Alert (Bell) ‘b’ .Backspace ‘f’ .Formfeed ‘n’ .New Line ‘r’ .Carriage Return ‘t’ .Horizontal tab ‘v’ .Vertical Tab ‘” .Single Quote ‘”‘ .Double Quote ‘?’ .Question Mark ‘’ .Back Slash ‘0’ .Null
  • 14. A variable name is an identifier or symbolic name assigned the memory location where data is stored. A variable ca ha only one value assigned to it at any given time during program execution. Its value may change during execution the program. Variables
  • 16. 🞂 The size qualifiers are : short long 🞂 Sign qualifiers signed unsigned Qualifiers
  • 20. Arithmetic Operators Operator Symbol Action Example Addition + Adds operands x + y Subtraction - Subs second from first x - y Negation - Negates operand -x Multiplication * Multiplies operands x * y Division / Divides first by second x / y (integer quotient) Modulus % Remainder of divide op x % y
  • 21. Assignment Operator  x=3 – = is an operator – The value of this expression is 3 – = operator has a side effect -- assign 3 to x  The assignment operator = – The side-effect is to assign the value of the right hand side (rhs) to the left hand side (lhs). – The value is the value of the rhs.  For example: x = ( y = 3 ) +1; /* y is assigned 3 */ /* the value of (y=3) is 3 */ /* x is assigned 4 */
  • 22. Compound Assignment Operator  Often we use “update” forms of operators – x=x+1, x=x*2, ...  C offers a short form for this: – Generic Form variable op= expr equivalent to variable = variable op expr – Update forms have value equal to the final value of expr  i.e., x=3; y= (x+=3); /* x and y both get value 6 */ Operator Equivalent to: x *= y x = x * y y -= z + 1 y = y - (z + 1) a /= b a = a / b x += y x = x + y y %= 3 y = y % 3
  • 23. Increment and Decrement  Pre Increment [++x]: the value of a variable is first incremented by 1, and then the updated value is used in the expression.  Post Increment [x++]: the variable's original value is used in the expression first, and then the post-increment operator updates the operand value by 1.  Pre Decrement [--x]: the value of a variable is first decremented by 1, and then the updated value is used in the expression.  Post Decrement [x--]: the variable's original value is used in the expression first, and then the post-decrement operator updates the operand value by substracting 1.
  • 24. Pre Increment and Post Increment #include <stdio.h> int main() { int x = 7; int y = ++x; printf("x is %dn", x); printf("y is %dn", y); return 0; } Output : x is 8 y is 8 #include <stdio.h> int main() { int x = 7; int y = x++; printf("x is %dn", x); printf("y is %dn", y); return 0; } Output : x is 8 y is 7
  • 25. Pre Decrement and Post Decrement #include <stdio.h> int main() { int x = 7; int y = --x; printf("x is %dn", x); printf("y is %dn", y); return 0; } Output : x is 6 y is 6 #include <stdio.h> int main() { int x = 7; int y = x--; printf("x is %dn", x); printf("y is %dn", y); return 0; } Output : x is 6 y is 7
  • 26. Relational Operators  Relational operators allow you to compare variables. – They return a 1 value for true and a 0 for false. Operator Symbol Example Equals == x == y NOT x = y Greater than > x > y Less than < x < y Greater/equals >= x >= y Less than/equals <= x <= y Not equal != x != y  There is no bool type in C. Instead, C uses: – 0 as false – Non-zero integer as true
  • 27. Relational Operators #include <stdio.h> int main() { int p = 5, q = 5, r = 10; printf(“%d == %d is %d n”, p, r, p == r); printf(“%d == %d is %d n”, p, q, p == q); printf(“%d > %d is %d n”, p, r, p > r); printf(“%d > %d is %d n”, p, q, p > q); printf(“%d < %d is %d n”, p, r, p < r); printf(“%d < %d is %d n”, p, q, p < q); printf(“%d != %d is %d n”, p, r, p != r); printf(“%d != %d is %d n”, p, q, p != q); printf(“%d >= %d is %d n”, p, r, p >= r); printf(“%d >= %d is %d n”, p, q, p >= q); printf(“%d <= %d is %d n”, p, r, p <= r); printf(“%d <= %d is %d n”, p, q, p <= q); return 0; } The output generated here would be: 5 == 10 is 0 5 == 5 is 1 5 > 10 is 0 5 > 5 is 0 5 < 10 is 1 5 < 5 is 0 5 != 10 is 1 5 != 5 is 0 5 >= 10 is 0 5 >= 5 is 1 5 <= 10 is 1 5 <= 5 is 1
  • 28. Logical Operators  && Logical AND Operator If both operands are non zero then the condition becomes true. Otherwise, the result has a value of 0. // C program for Logical AND Operator #include <stdio.h> int main() { int a = 10, b = 20; if (a > 0 && b > 0) { printf("Both values are greater than 0n"); } else { printf("Both values are less than 0n"); } return 0; } Output : X Y X && Y 1 1 1 1 0 0 0 1 0 0 0 0 Both values are greater than 0
  • 29. Logical Operators  || Logical OR Operator The condition becomes true if any one of them is non-zero. Otherwise, it returns false i.e., 0 as the value. // C program for Logical OR Operator #include <stdio.h> int main() { int a = -1, b = 20; if (a > 0 || b > 0) { printf("Any one of the given value is greater than 0n"); } else { printf("Both values are less than 0n"); } return 0; } Output : X Y X || Y 1 1 1 1 0 1 0 1 1 0 0 0 Any one of the given value is greater than 0
  • 30. Logical Operators  ! Logical NOT Operator If the condition is true then the logical NOT operator will make it false and vice-versa. // C program for Logical NOT Operator #include <stdio.h> int main() { int a = 10, b = 20; if (!(a > 0 && b > 0)) { // condition returned true but logical NOT operator changed it to false printf("Both values are greater than 0n"); } else { printf("Both values are less than 0n"); } return 0; } Output : Both values are less than 0 X !X 0 1 1 0
  • 31. Operating on Bits (1)  C allows you to operate on the bit representations of integer variables. – Generally called bit-wise operators.  All integers can be thought of in binary form. – For example, suppose ints have 16-bits 6552010 = 1111 1111 1111 00002 = FFF016 = 1777608  In C, hexadecimal literals begin with 0x, and octal literals begin with 0. x=65520; base 10 x=0xfff0; base 16 (hex) x=0177760; base 8 (octal)
  • 32. Operating on Bits (2) Bitwise operators  The shift operator: – x << n  Shifts the bits in x to n positions to the left, shifting in zeros on the right.  If x = 1111 1111 1111 00002 x << 1 equals 1111 1111 1110 00002 – x >> n  Shifts the bits in x to n positions right. – shifts in the sign if it is a signed integer (arithmetic shift) – shifts in 0 if it is an unsigned integer  x >> 1 is 0111 1111 1111 10002 (unsigned)  x >> 1 is 1111 1111 1111 10002 (signed)
  • 33. Operating on Bits (3)  Bitwise logical operations – Work on all integer types  & Bitwise AND x= 0xFFF0 y= 0x002F x&y= 0x0020  | Bitwise Inclusive OR x|y= 0xFFFF  ^ Bitwise Exclusive OR x^y= 0xFFDF  ~ The complement operator ~ y= 0xFFD0 – Complements all of the bits of X X Y X ^ Y 1 1 0 1 0 1 0 1 1 0 0 0
  • 34. Shift, Multiplication and Division  Multiplication and division is often slower than shift.  Multiplying 2 can be replaced by shifting 1 bit to the left. n = 10 printf(“%d = %d” , n*2, n<<1); printf(“%d = %d”, n*4, n<<2); ……  Division by 2 can be replace by shifting 1 bit to the right. n = 10 printf(“%d = %d” , n/2, n>>1); printf(“%d = %d”, n/4, n>>2);
  • 35. Operator Precedence and Associativity  Operator precedence – It determines the order in which different operators are evaluated in an expression. – This is important because it can change the outcome of an expression if not understood correctly.  Operator associativity – It determines the order in which operators of the same precedence are evaluated when they appear in a sequence without parentheses. – There are two types of associativity: left-to-right and right-to-left.
  • 36. Operator Precedence Operator Precedence level ( ) 1 ~, ++, --, unary - 2 *, /, % 3 +, - 4 <<, >> 5 <, <=, >, >= 6 ==, != 7 & 8 ^ 9 | 10 && 11 || 12 =, +=, -=, etc. 14 We’ll be adding more to this list later on...
  • 38. Operator Precedence and Associativity
  • 39. Operator Precedence example #include <stdio.h> int main() { int x = 5; int y = 3; int result = x+++y printf("%d %d %d",x,y,result); return 0; } OUTPUT:  6 3 8 #include <stdio.h> int main() { int x = 5; int y = 3; int result = ++x+y printf("%d %d %d",x,y,result); return 0; } OUTPUT:  6 3 9
  • 40. An Example  What is the difference between the two lines of output? #include <stdio.h> int main () { int w=10,x=20,y=30,z=40; int temp1, temp2; temp1 = x * x /++y + z / y; printf ("temp1= %d;nw= %d;nx= %d;ny= %d;nz= %dn", temp1, w,x,y,z); y=30; temp2 = x * x /y++ + z / y; printf ("temp2= %d;nw= %d;nx= %d;ny= %d;nz= %dn", temp2, w,x,y,z); return 0; }
  • 41. Conditional Operator  The conditional operator essentially allows you to embed an “if” statement into an expression  Generic Form exp1 ? exp2 : exp3 if exp1 is true (non-zero) value is exp2 (exp3 is not evaluated) if exp1 is false (0), value is exp3 (exp2 is not evaluated)  Example: z = (x > y) ? x : y;  This is equivalent to: if (x > y) z = x; else z = y;
  • 42. Comma Operator  An expression can be composed of multiple subexpressions separated by commas. – Subexpressions are evaluated left to right. – The entire expression evaluates to the value of the rightmost subexpression.  Example: x = (a++, b++);  a is incremented  b is assigned to x  b is incremented – Parenthesis are required because the comma operator has a lower precedence than the assignment operator!  The comma operator is often used in for loops.
  • 43. Comma Operator and For Loop  Example:  int i, sum;  for (i=0,sum=0;i<100;i++){  sum += i;  }  printf(“1+...+100 = %d”, sum);
  • 45. main() { int a, b; } void add(int x, int y) { int sum=0; sum=x+y; printf(“n Sum = %d”, sum); } Local Variable
  • 46. int a, b; main() { printf (“n in main a=%d”,a); } void val(int x) { a=x; printf(“n in Function = %d”,a); } Global Variable
  • 47. 🞂 Arithmetic 🞂 Relational 🞂 Logical 🞂 Assignment 🞂 Increment/ Decrement 🞂 Conditional Opeators
  • 49. 🞂 && 🞂 || 🞂 ! Logical
  • 50. if(age>18) &&(citizen==“Indian”) { printf(“Elegible for voting”); } else { printf(“n Not eligible for voting”); } And &&
  • 51. If(day==“Saturday” ) || (day==“Sunday”) { printf(“Its holiday”); } else { printf(“Working day”); } Or ||
  • 53. 🞂 + + i=1 i++ I is 2 i+2 I is 4 🞂 - - J=5 J- - Jis 4 Increment/decrement
  • 54. 🞂 Ans= (condition) 🞂 A=15 🞂 B =5 Z=A>B ? A:B ? Opt1 :opt2 Conditional operators
  • 56. 🞂 Input means to provide the program with some data to be used in the program and Output means to display data on the screen or write the data to a printer or a file. 🞂 The C programming language provides standard library functions to read any given input and to display data on the console. Input/Output Statement in C
  • 57. The functions used for standard input and output are present in the stdio.h header file. Hence to use the functions we need to include the stdio.h header file #include<stdio.h>
  • 58. Following are the functions used for standard input and output: printf() function - Show Output scanf() function - Take Input getchar() and putchar() function gets() and puts() function
  • 59. 🞂 The printf() function is the most used function in the C language. This function is defined in the stdio.h header file and is used to show output on the console (standard output). 🞂 This function is used to print a simple text sentence or value of any variable which can be of int, char, float, or any other datatype. printf() function
  • 60. 🞂 To print values of different datatypes using the printf() statement, we need to use format specifiers, like we have used in the code examples above. 🞂 Also, when we take input from user using the scanf() function, then also, we have to specify what type of input to expect from the user using these format specifiers. Format Specifiers
  • 61. Datatype Format Specifier int %d, %i char %c float %f double %lf short int %hd unsigned int %u long int %li unsigned long int %lu signed char %c unsigned char %c long double %Lf
  • 62. 🞂 When we want to take input from the user, we use the scanf() function. When we take input from the user, we store the input value into a variable. 🞂 The scanf() function can be used to take any datatype input from user, all we have to take care is that the variable in which we store the value has the same datatype. scanf()
  • 63. 🞂 The getchar() function reads a character from the terminal and returns it as an integer. This function reads only a sin character at a time. 🞂 The putchar() function displays the character passed to it o the screen and returns the same character. This function t displays only a single character at a time. 🞂 In case you want to display more than one character, use putchar() method in a loop. getchar() & putchar()
  • 64. 🞂 The gets() function reads a line from stdin(standard input) into the buffer pointed to by str pointer, until either a terminating newline or EOF (end of file) occurs. 🞂 The puts() function writes the string str and a trailing newline to stdout. gets() & puts()