SlideShare a Scribd company logo
Recall
• What is a variable?
• How doe the CPU Execution flow occurs?
Random or sequential?
• What are the options to control the normal
flow of executions?
• What is a function? When do we use
functions?
Introduction to C
Week 2
How does human perform simple task; for
Eg: add 456 and 44
Add 456
and 44 500
How does human perform simple task;
Eg: add 456 and 44
1 We Hear it through our input senses
2 We store the numbers 456 and 44 in our memory
456
44
456+44 3 We calculate the result in our brain and store it in
memory
500
3 We say the answer through our output senses
1 Computer use keyboard to receive inputs
2 Computer store the numbers 456 and 44 in Ram
456
44
456+44
3
Computer calculate the result in CPU (ALU within
CPU) and stores result back in ram
500
4 Computer use monitor to display outputs
How does computer perform simple
task; Eg: add 456 and 44
– Start
– Get two numbers and
store them
– Add them and store
the result
– Print the answer
– End
Algorithm
– Start
– Get two numbers and
store them
– Add them and store
the result
– Print the answer
– End
Main
{
int a,b,c;
a=456,b=44;
c= a+b;
// something to print the value
from c, will discuss soon
}
Algorithm Vs
Program
500
44
456
b
a
c
main()
{
int a=456, b=44,c;
c= a+b;
printf (“%d”,c); // So who defined this function??
Where is it located?
}
#include < stdio.h >
main()
{
int a=456, b=44,c;
c= a+b;
printf (“%d”,c);
}
........
Printf(..)
{
........
}
Scanf (..)
{.....
}
Stdio . h
Printf()
• Printf(“%d”,c)
– %d refers to Format specifier which is used
to specify the type and format of the data to
be taken to the stream and to be printed on
screen
• %f -> for float data type
• %c for Char data type
• %s for string data type
–c refers to the value of location named
c
500
44
456
b
a
c
–%d refers to Format specifies
which is used to specify the type
and format of the data to be
retrieved from the stream and
stored into the locations pointed by
&a.
–&a refers to the memory address of
location named a
scanf()
Complete Program
#include < stdio.h >
main()
{
int a,b,c;
Scanf(“%d %d”,&a,&b);
c= a+b;
printf (“%d”,c);
}
Elements of C
• Variables
• Operators
• Control structures
 Decision
 Loops
• functions
Variables in C
Variables
int a;
Data type variable name
Variables
Data type
• Data type is the type of data we are going to store
in the reserved Ram location.
• We need to specify the data type so that size to be
allocated will be done automatically.
 Int -> reserves 2 bytes of memory
 Char -> reserves 1 byte of memory
 float -> reserves 4 bytes of memory
Variable Name
• Variable is the name we give to access the value
from the memory space we allocate.
• Variable name should begin with characters or _ ;But
Variables
• Naming a Variable
– Must be a valid identifier.
– Must not be a keyword
– Names are case sensitive.
– Variables are identified by only first 32
characters.
– Library commonly uses names beginning with
_.
– Naming Styles: Uppercase style and
Underscore style
Decisions in C
N Y
Start
i=1
If
i<100
Print iStop
Print all the numbers up to 100
i=i+1
Decisions
• Eg: if(i=100)
{
printf(“You are a low performer”);
}
else
{
printf(“You are a top performer”);
}
Nested if
• Eg: if(i==0)
{
printf(“You are a low performer”);
}
else if(i==200)
{
printf(“You are a top performer”);
}
Else if (i==300)
{
…
}
What is “=“ and “==“
=
– As discussed earlier = is used to assign a
value into a location we reserved already/or to
assign value in to a variable
– Eg: a=10
==
– Is used to check whether the value of a
variable is equal to the value provided in the
other side of operand
switch
Switch(i)
{
Case 0:
printf(“poor performer”);
break;
Case 100:
printf(“Good performer”);
break;
Case default:
printf(“performer”);
break;
}
switch
Switch(i)
{
Case 0:
printf(“poor performer”);
break;
Case 100:
printf(“Good performer”);
break;
Case default:
printf(“performer”);
break;
}
if(i==0)
{
printf(“Poor Performer”)
}
else if(i==100)
{
printf(“Good performer”
}
Else {
Printf(“performer”);
}
Loops in c
N Y
Start
i=1
If
i<100
Print iStop
Print all the numbers up to 100
i=i+1
Loops in C
• For loop
• While Loop
• Do While Loop
For Loop
for
(i=0;i<50;i++)
{
printf(“%d ”, i);
} // {braces} are not
necessary if there is only
one statement inside for
loop
Step 1 : i=0 :
initialization
Step 2 : i<50 : if
true step 3
or else step 6
Step 3 : {
executes }
Step 4 : i++
While Loop
i=0;
While(i<50)
{
printf(“%d ”, i);
i++;
} // {braces} are not
necessary if there is only
Step 1 : i=0 :
initialization
Step 2 : i<50 : if
true step 3
or else step 6
Step 3 : {
executes }
Step 4 : i++
Do while Loop
i=0;
Do
{
printf(“%d ”, i);
i++;
} While(i<50)
Step 1 : i=0 :
initialization
Step 3 : {
executes }
Step 4 : i++
Step 2 : i<50 : if
true step 3 or
Other Control statements
• Break Statements
– The break statement terminates the
execution of the nearest
enclosing do, for, switch, or while statement
in which it appears.
• Continue statements
– The continue statement works like
the break statement. Instead of forcing
termination, however, continue forces the next
iteration of the loop to take place, skipping
Example
int a = 10;
while( a < 20 )
{
printf("value of a: %d n", a);
a++;
if( a > 15) {
break;
}
}
Example
int a = 10;
while( a < 20 )
{
printf("value of a: %d n", a);
a++;
if( a > 15) {
break;
}
}
Output
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
Example
int a = 10;
do
{
If( a == 15)
{
a = a + 1;
continue;
}
printf("value of a: %dn", a);
a++;
} while( a < 20 );
Example
int a = 10;
do
{
If( a == 15)
{
a = a + 1;
continue;
}
printf("value of a: %dn", a);
a++;
} while( a < 20 );
Output
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 16
value of a: 17
value of a: 18
value of a: 19
Operators
• Arithmetic Operators
+, - , *, / and the modulus operator %.
• Relational operators
<, <=, > >=, ==, !=
• Logical operators
&&, ||, ! eg : If (a<10 && b>9)
• Assignment Operators
=, += ,-= eg: a+=10//same as
a=a+10
• Increment and decrement operators
Difference between i++ and ++i
• ++i Increments i by one, then returns i.
• i++ Returns i, then increments i by one.
i=10,j=20
Z=++i;
W=j++;
Printf(“%d %d”, z,w); // w=20; z=11
Questions?
“A good question deserve a good
grade…”
Self Check !!
Self-Check
• What is a difference between a declaration and a
definition of a variable?
– Both can occur multiple times, but a
declaration must occur first.
– There is no difference between them.
– A definition occurs once, but a declaration
may occur many times.
– A declaration occurs once, but a definition
may occur many times.
– Both can occur multiple times, but a definition
Self-Check
• What is a difference between a declaration and a
definition of a variable?
– Both can occur multiple times, but a
declaration must occur first.
– There is no difference between them.
– A definition occurs once, but a declaration
may occur many times.
– A declaration occurs once, but a definition
may occur many times.
– Both can occur multiple times, but a definition
Self-Check
• How many times “baabtra“ get printed?
main()
{
int x;
for(x=-1; x<=10; x++)
{
if(x < 5)
continue;
else
break;
printf(“baabtra");
}
}
1.Infinite
times
2.11 Times
3.0 times
4.10 times
Self-Check
• How many times “baabtra“ get printed?
main()
{
int x;
for(x=-1; x<=10; x++)
{
if(x < 5)
continue;
else
break;
printf(“baabtra");
}
}
1.Infinite
times
2.11 Times
3.0 times
4.10 times
Self-Check
What is the output of the following program?
void main()
{
int i=10;
switch(i)
{
case 1: printf(" i=1");
break;
case 10: printf(" i=10");
case 11: printf(" i=11");
break;
case 12: printf(" i=12");
}
}
1. i=10 i=11
i=12
2. i=1 i=10
i=11 i=12
3. i=10 i=11
4. None of
above
Self-Check
What is the output of the following program?
void main()
{
int i=10;
switch(i)
{
case 1: printf(" i=1");
break;
case 10: printf(" i=10");
case 11: printf(" i=11");
break;
case 12: printf(" i=12");
}
}
1. i=10 i=11
i=12
2. i=1 i=10
i=11 i=12
3. i=10 i=11
4. None of
above
Self-Check
What is the output of the following program?
void main()
{
int i=1,j=1;
while (++i < 10)
printf("%d ",i);
printf("n");
while (j++ < 10)
printf("%d ",j);
}
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10
2 3 4 5 6 7 8 9
2 3 4 5 6 7 8 9 10
2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10
Self-Check
What is the output of the following program?
void main()
{
int i=1,j=1;
while (++i < 10)
printf("%d ",i);
printf("n");
while (j++ < 10)
printf("%d ",j);
}
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10
2 3 4 5 6 7 8 9
2 3 4 5 6 7 8 9 10
2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10
End of Day 1

More Related Content

What's hot

C programming
C programmingC programming
C programming
Samsil Arefin
 
Issta13 workshop on debugging
Issta13 workshop on debuggingIssta13 workshop on debugging
Issta13 workshop on debugging
Abhik Roychoudhury
 
Fucntions & Pointers in C
Fucntions & Pointers in CFucntions & Pointers in C
Fucntions & Pointers in C
Janani Satheshkumar
 
6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping
MomenMostafa
 
Ansi c
Ansi cAnsi c
Chapter 5
Chapter 5Chapter 5
Chapter 5
EasyStudy3
 
9 character string &amp; string library
9  character string &amp; string library9  character string &amp; string library
9 character string &amp; string library
MomenMostafa
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
Saranya saran
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
sajidpk92
 
C important questions
C important questionsC important questions
C important questions
JYOTI RANJAN PAL
 
C PROGRAMS
C PROGRAMSC PROGRAMS
C programms
C programmsC programms
C programms
Mukund Gandrakota
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
Rahul Pandit
 
Expressions using operator in c
Expressions using operator in cExpressions using operator in c
Expressions using operator in c
Saranya saran
 
C programming Lab 2
C programming Lab 2C programming Lab 2
C programming Lab 2
Zaibi Gondal
 
C operators
C operators C operators
C operators
AbiramiT9
 
Chapter 5 Balagurusamy Programming ANSI in c
Chapter 5 Balagurusamy Programming ANSI  in cChapter 5 Balagurusamy Programming ANSI  in c
Chapter 5 Balagurusamy Programming ANSI in c
BUBT
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
Leandro Schenone
 
7 functions
7  functions7  functions
7 functions
MomenMostafa
 
02 Control Structures - Loops & Conditions
02 Control Structures - Loops & Conditions02 Control Structures - Loops & Conditions
02 Control Structures - Loops & Conditions
Ebad ullah Qureshi
 

What's hot (20)

C programming
C programmingC programming
C programming
 
Issta13 workshop on debugging
Issta13 workshop on debuggingIssta13 workshop on debugging
Issta13 workshop on debugging
 
Fucntions & Pointers in C
Fucntions & Pointers in CFucntions & Pointers in C
Fucntions & Pointers in C
 
6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping
 
Ansi c
Ansi cAnsi c
Ansi c
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
9 character string &amp; string library
9  character string &amp; string library9  character string &amp; string library
9 character string &amp; string library
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
C important questions
C important questionsC important questions
C important questions
 
C PROGRAMS
C PROGRAMSC PROGRAMS
C PROGRAMS
 
C programms
C programmsC programms
C programms
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
 
Expressions using operator in c
Expressions using operator in cExpressions using operator in c
Expressions using operator in c
 
C programming Lab 2
C programming Lab 2C programming Lab 2
C programming Lab 2
 
C operators
C operators C operators
C operators
 
Chapter 5 Balagurusamy Programming ANSI in c
Chapter 5 Balagurusamy Programming ANSI  in cChapter 5 Balagurusamy Programming ANSI  in c
Chapter 5 Balagurusamy Programming ANSI in c
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
 
7 functions
7  functions7  functions
7 functions
 
02 Control Structures - Loops & Conditions
02 Control Structures - Loops & Conditions02 Control Structures - Loops & Conditions
02 Control Structures - Loops & Conditions
 

Viewers also liked

Database design
Database designDatabase design
Xml passing in java
Xml passing in javaXml passing in java
Threads in python
Threads in pythonThreads in python
Jquery library
Jquery libraryJquery library
Ajax
AjaxAjax
File oparation in c
File oparation in cFile oparation in c
Ajax
AjaxAjax

Viewers also liked (7)

Database design
Database designDatabase design
Database design
 
Xml passing in java
Xml passing in javaXml passing in java
Xml passing in java
 
Threads in python
Threads in pythonThreads in python
Threads in python
 
Jquery library
Jquery libraryJquery library
Jquery library
 
Ajax
AjaxAjax
Ajax
 
File oparation in c
File oparation in cFile oparation in c
File oparation in c
 
Ajax
AjaxAjax
Ajax
 

Similar to Introduction to c part -1

12 lec 12 loop
12 lec 12 loop 12 lec 12 loop
12 lec 12 loop
kapil078
 
Looping
LoopingLooping
COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops
Hemantha Kulathilake
 
1 introduction to c program
1 introduction to c program1 introduction to c program
1 introduction to c program
NishmaNJ
 
02 Java Language And OOP PART II
02 Java Language And OOP PART II02 Java Language And OOP PART II
02 Java Language And OOP PART II
Hari Christian
 
Vcs5
Vcs5Vcs5
Learning C programming - from lynxbee.com
Learning C programming - from lynxbee.comLearning C programming - from lynxbee.com
Learning C programming - from lynxbee.com
Green Ecosystem
 
Code optimization
Code optimization Code optimization
Code optimization
Code optimization Code optimization
Understand more about C
Understand more about CUnderstand more about C
Understand more about C
Yi-Hsiu Hsu
 
Chapter06.PPT
Chapter06.PPTChapter06.PPT
Chapter06.PPT
vamsiKrishnasai3
 
C tutorial
C tutorialC tutorial
C tutorial
Anurag Sukhija
 
5 c control statements looping
5  c control statements looping5  c control statements looping
5 c control statements looping
MomenMostafa
 
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
Chandrakant Divate
 
Cse115 lecture08repetitionstructures part02
Cse115 lecture08repetitionstructures part02Cse115 lecture08repetitionstructures part02
Cse115 lecture08repetitionstructures part02
Md. Ashikur Rahman
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
Wingston
 
Week2 ch4 part1edited 2020
Week2 ch4 part1edited 2020Week2 ch4 part1edited 2020
Week2 ch4 part1edited 2020
Osama Ghandour Geris
 
Week2 ch4 part1edited 2020
Week2 ch4 part1edited 2020Week2 ch4 part1edited 2020
Week2 ch4 part1edited 2020
Osama Ghandour Geris
 
C tutorial
C tutorialC tutorial
Acm aleppo cpc training introduction 1
Acm aleppo cpc training introduction 1Acm aleppo cpc training introduction 1
Acm aleppo cpc training introduction 1
Ahmad Bashar Eter
 

Similar to Introduction to c part -1 (20)

12 lec 12 loop
12 lec 12 loop 12 lec 12 loop
12 lec 12 loop
 
Looping
LoopingLooping
Looping
 
COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops
 
1 introduction to c program
1 introduction to c program1 introduction to c program
1 introduction to c program
 
02 Java Language And OOP PART II
02 Java Language And OOP PART II02 Java Language And OOP PART II
02 Java Language And OOP PART II
 
Vcs5
Vcs5Vcs5
Vcs5
 
Learning C programming - from lynxbee.com
Learning C programming - from lynxbee.comLearning C programming - from lynxbee.com
Learning C programming - from lynxbee.com
 
Code optimization
Code optimization Code optimization
Code optimization
 
Code optimization
Code optimization Code optimization
Code optimization
 
Understand more about C
Understand more about CUnderstand more about C
Understand more about C
 
Chapter06.PPT
Chapter06.PPTChapter06.PPT
Chapter06.PPT
 
C tutorial
C tutorialC tutorial
C tutorial
 
5 c control statements looping
5  c control statements looping5  c control statements looping
5 c control statements looping
 
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
 
Cse115 lecture08repetitionstructures part02
Cse115 lecture08repetitionstructures part02Cse115 lecture08repetitionstructures part02
Cse115 lecture08repetitionstructures part02
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
Week2 ch4 part1edited 2020
Week2 ch4 part1edited 2020Week2 ch4 part1edited 2020
Week2 ch4 part1edited 2020
 
Week2 ch4 part1edited 2020
Week2 ch4 part1edited 2020Week2 ch4 part1edited 2020
Week2 ch4 part1edited 2020
 
C tutorial
C tutorialC tutorial
C tutorial
 
Acm aleppo cpc training introduction 1
Acm aleppo cpc training introduction 1Acm aleppo cpc training introduction 1
Acm aleppo cpc training introduction 1
 

More from baabtra.com - No. 1 supplier of quality freshers

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
baabtra.com - No. 1 supplier of quality freshers
 
Best coding practices
Best coding practicesBest coding practices
Core java - baabtra
Core java - baabtraCore java - baabtra
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
baabtra.com - No. 1 supplier of quality freshers
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
baabtra.com - No. 1 supplier of quality freshers
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
baabtra.com - No. 1 supplier of quality freshers
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php database connectivity
Php database connectivityPhp database connectivity
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Blue brain
Blue brainBlue brain
5g
5g5g
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Gd baabtra
Gd baabtraGd baabtra

More from baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 

Recently uploaded

Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 

Recently uploaded (20)

Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 

Introduction to c part -1

  • 1. Recall • What is a variable? • How doe the CPU Execution flow occurs? Random or sequential? • What are the options to control the normal flow of executions? • What is a function? When do we use functions?
  • 3. How does human perform simple task; for Eg: add 456 and 44 Add 456 and 44 500
  • 4. How does human perform simple task; Eg: add 456 and 44 1 We Hear it through our input senses 2 We store the numbers 456 and 44 in our memory 456 44 456+44 3 We calculate the result in our brain and store it in memory 500 3 We say the answer through our output senses
  • 5. 1 Computer use keyboard to receive inputs 2 Computer store the numbers 456 and 44 in Ram 456 44 456+44 3 Computer calculate the result in CPU (ALU within CPU) and stores result back in ram 500 4 Computer use monitor to display outputs How does computer perform simple task; Eg: add 456 and 44
  • 6. – Start – Get two numbers and store them – Add them and store the result – Print the answer – End Algorithm
  • 7. – Start – Get two numbers and store them – Add them and store the result – Print the answer – End Main { int a,b,c; a=456,b=44; c= a+b; // something to print the value from c, will discuss soon } Algorithm Vs Program 500 44 456 b a c
  • 8. main() { int a=456, b=44,c; c= a+b; printf (“%d”,c); // So who defined this function?? Where is it located? }
  • 9. #include < stdio.h > main() { int a=456, b=44,c; c= a+b; printf (“%d”,c); } ........ Printf(..) { ........ } Scanf (..) {..... } Stdio . h
  • 10. Printf() • Printf(“%d”,c) – %d refers to Format specifier which is used to specify the type and format of the data to be taken to the stream and to be printed on screen • %f -> for float data type • %c for Char data type • %s for string data type –c refers to the value of location named c 500 44 456 b a c
  • 11. –%d refers to Format specifies which is used to specify the type and format of the data to be retrieved from the stream and stored into the locations pointed by &a. –&a refers to the memory address of location named a scanf()
  • 12. Complete Program #include < stdio.h > main() { int a,b,c; Scanf(“%d %d”,&a,&b); c= a+b; printf (“%d”,c); }
  • 13. Elements of C • Variables • Operators • Control structures  Decision  Loops • functions
  • 15. Variables int a; Data type variable name
  • 16. Variables Data type • Data type is the type of data we are going to store in the reserved Ram location. • We need to specify the data type so that size to be allocated will be done automatically.  Int -> reserves 2 bytes of memory  Char -> reserves 1 byte of memory  float -> reserves 4 bytes of memory Variable Name • Variable is the name we give to access the value from the memory space we allocate. • Variable name should begin with characters or _ ;But
  • 17. Variables • Naming a Variable – Must be a valid identifier. – Must not be a keyword – Names are case sensitive. – Variables are identified by only first 32 characters. – Library commonly uses names beginning with _. – Naming Styles: Uppercase style and Underscore style
  • 19. N Y Start i=1 If i<100 Print iStop Print all the numbers up to 100 i=i+1
  • 20. Decisions • Eg: if(i=100) { printf(“You are a low performer”); } else { printf(“You are a top performer”); }
  • 21. Nested if • Eg: if(i==0) { printf(“You are a low performer”); } else if(i==200) { printf(“You are a top performer”); } Else if (i==300) { … }
  • 22. What is “=“ and “==“ = – As discussed earlier = is used to assign a value into a location we reserved already/or to assign value in to a variable – Eg: a=10 == – Is used to check whether the value of a variable is equal to the value provided in the other side of operand
  • 23. switch Switch(i) { Case 0: printf(“poor performer”); break; Case 100: printf(“Good performer”); break; Case default: printf(“performer”); break; }
  • 24. switch Switch(i) { Case 0: printf(“poor performer”); break; Case 100: printf(“Good performer”); break; Case default: printf(“performer”); break; } if(i==0) { printf(“Poor Performer”) } else if(i==100) { printf(“Good performer” } Else { Printf(“performer”); }
  • 26. N Y Start i=1 If i<100 Print iStop Print all the numbers up to 100 i=i+1
  • 27. Loops in C • For loop • While Loop • Do While Loop
  • 28. For Loop for (i=0;i<50;i++) { printf(“%d ”, i); } // {braces} are not necessary if there is only one statement inside for loop Step 1 : i=0 : initialization Step 2 : i<50 : if true step 3 or else step 6 Step 3 : { executes } Step 4 : i++
  • 29. While Loop i=0; While(i<50) { printf(“%d ”, i); i++; } // {braces} are not necessary if there is only Step 1 : i=0 : initialization Step 2 : i<50 : if true step 3 or else step 6 Step 3 : { executes } Step 4 : i++
  • 30. Do while Loop i=0; Do { printf(“%d ”, i); i++; } While(i<50) Step 1 : i=0 : initialization Step 3 : { executes } Step 4 : i++ Step 2 : i<50 : if true step 3 or
  • 31. Other Control statements • Break Statements – The break statement terminates the execution of the nearest enclosing do, for, switch, or while statement in which it appears. • Continue statements – The continue statement works like the break statement. Instead of forcing termination, however, continue forces the next iteration of the loop to take place, skipping
  • 32. Example int a = 10; while( a < 20 ) { printf("value of a: %d n", a); a++; if( a > 15) { break; } }
  • 33. Example int a = 10; while( a < 20 ) { printf("value of a: %d n", a); a++; if( a > 15) { break; } } Output value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 15
  • 34. Example int a = 10; do { If( a == 15) { a = a + 1; continue; } printf("value of a: %dn", a); a++; } while( a < 20 );
  • 35. Example int a = 10; do { If( a == 15) { a = a + 1; continue; } printf("value of a: %dn", a); a++; } while( a < 20 ); Output value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 16 value of a: 17 value of a: 18 value of a: 19
  • 36. Operators • Arithmetic Operators +, - , *, / and the modulus operator %. • Relational operators <, <=, > >=, ==, != • Logical operators &&, ||, ! eg : If (a<10 && b>9) • Assignment Operators =, += ,-= eg: a+=10//same as a=a+10 • Increment and decrement operators
  • 37. Difference between i++ and ++i • ++i Increments i by one, then returns i. • i++ Returns i, then increments i by one. i=10,j=20 Z=++i; W=j++; Printf(“%d %d”, z,w); // w=20; z=11
  • 38. Questions? “A good question deserve a good grade…”
  • 40. Self-Check • What is a difference between a declaration and a definition of a variable? – Both can occur multiple times, but a declaration must occur first. – There is no difference between them. – A definition occurs once, but a declaration may occur many times. – A declaration occurs once, but a definition may occur many times. – Both can occur multiple times, but a definition
  • 41. Self-Check • What is a difference between a declaration and a definition of a variable? – Both can occur multiple times, but a declaration must occur first. – There is no difference between them. – A definition occurs once, but a declaration may occur many times. – A declaration occurs once, but a definition may occur many times. – Both can occur multiple times, but a definition
  • 42. Self-Check • How many times “baabtra“ get printed? main() { int x; for(x=-1; x<=10; x++) { if(x < 5) continue; else break; printf(“baabtra"); } } 1.Infinite times 2.11 Times 3.0 times 4.10 times
  • 43. Self-Check • How many times “baabtra“ get printed? main() { int x; for(x=-1; x<=10; x++) { if(x < 5) continue; else break; printf(“baabtra"); } } 1.Infinite times 2.11 Times 3.0 times 4.10 times
  • 44. Self-Check What is the output of the following program? void main() { int i=10; switch(i) { case 1: printf(" i=1"); break; case 10: printf(" i=10"); case 11: printf(" i=11"); break; case 12: printf(" i=12"); } } 1. i=10 i=11 i=12 2. i=1 i=10 i=11 i=12 3. i=10 i=11 4. None of above
  • 45. Self-Check What is the output of the following program? void main() { int i=10; switch(i) { case 1: printf(" i=1"); break; case 10: printf(" i=10"); case 11: printf(" i=11"); break; case 12: printf(" i=12"); } } 1. i=10 i=11 i=12 2. i=1 i=10 i=11 i=12 3. i=10 i=11 4. None of above
  • 46. Self-Check What is the output of the following program? void main() { int i=1,j=1; while (++i < 10) printf("%d ",i); printf("n"); while (j++ < 10) printf("%d ",j); } 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 10 2 3 4 5 6 7 8 9 2 3 4 5 6 7 8 9 10 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 10
  • 47. Self-Check What is the output of the following program? void main() { int i=1,j=1; while (++i < 10) printf("%d ",i); printf("n"); while (j++ < 10) printf("%d ",j); } 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 10 2 3 4 5 6 7 8 9 2 3 4 5 6 7 8 9 10 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 10

Editor's Notes

  1. Printf(“%d”,i) o/p = 11Printf(“%d’,j) o/p = 21
  2. X=-1,0,1,2
  3. i=10