SlideShare a Scribd company logo
Prepared By:
Abdullah Iqbal And Umar Aftab
1
1972, AT&T Bell’s laboratories by Denis and Ritchie.
Alphabets Keywords
Digits Constants Statements Program
Symbols Variables
Alphabets :- A,B,C,….,Z.
Digits :- 1,2,3,4….9.
Symbols :- ! # $ % ^ & * ( ) _ + : ; ’ , . Etc.
Keywords:- these are reserve words in compiler.
Constants :-
a. Primary Constants:- Integer : without fractional part/whole numbers.
Real : with both fractional and integer parts.
Character: digit/alphabets/symbol enclosed in ‘ ’ .
b. Secondary Constants:- Arrays, Pointers, Structures Etc. 2
 For Integer Constants:-
a. It must have one digit.
b. May be positive as well as negative.(by default positive)
c. Range : (underflow) -32768 to +32767 (overflow)
 For Real Constants:-
a. May be positive as well as negative.(by default positive)
b. It must have one digit.
c. Range : -3.4 X 1038 to +3.4 X 1038 .
 For Character Constants:-
a. Maximum length of character constant is 1.
3
 Variables means, whose value varies and can be changed
easily.
 Variable is a named memory location.
Rules for Constructing Variables:
a. Variable have maximum length of 31 characters.
b. Variable name must start with alphabet or underscore.
c. No space, commas or special symbols are allowed.
d. Keyword(reserve words) can’t be used as variable name.
Examples:
Valid Invalid
AbCd A bC D
A44o_ @12f
Age printf 4
 Keywords means reserve words.
 There are about 32 keywords in Dev compiler
 Examples:
Auto break if else
While for continue int
Float char scanf printf
dowhile Etc.
5
For Programing there are some important tips Like;
 Every statement end with semicolon. (;)
 There must be execution order.
 Use of Pre-processor Directories. Like main()….
6
Generally we used three types of Datatypes
that is: integer float and character.
Integer:-
short type reserve 2 bytes in memory location. 4 bytes in Dev compiler.
(-32768 to +32767)
Long type reserve 4 bytes in memory location
( -2147483648 to +2147483647)
Character:- written in single comas(‘ A ’),it reserves 1 byte in memory
location .
Float:-
Simple 1.7 X 10-38 to 1.7X 10 38 reserve 4 byte in memory location
Double 2.3 X 10-308 to 1.7X 10 308 reserve 8 byte in memory location
Long Double 2.4 X 10-4932 to 1.1X 10 4932 reserve 4 byte in memory location
7
 Variable Declaration Statement.
Use to declare variable in C.
 Assignment Statements.
It may be variable initialization statement and also
updation.
 Compound Assignment Statements.
Using single variable, same values are assigned.
 Variable Initialization Statements.
initially variable’s value like : num1=10;
 Variable Increment Decrement Statement.
pre inc / dec : first increase/decrease then execute.
post inc / dec : first execute then increase/decrease.
8
Group of operands and operators are called Expressions.
Operands can be constant or variable or other
expressions.
Logical Expressions:
Athematic : + - * / ** % Etc.
Logical : AND (&&) OR (||) NOT (!)
Relational Expressions: for comparing <, =, >, >=,
==.
9
There are two type of type conversion:
Implicit :- Automatically convert by compiler.
integer integer = integer
integer float = float
float float = float
Explicit :- According to our wish.
a=int (4.5)
a=4.
10
Input :- scanf( ) => float/integer/string.
gets() => string.
Output :- printf() => integer/float/string.
puts() => string.
printf(“format string ” , list of arguments)
/t for tab space.
/d for integer
/s for string
/b for bell
/n for new line.
11
In C language Program is written according to proper
syntax:
Pre-processors directories( #include )
Main function ( main() )
Body of the program ( { …… } )
Simple Sum Program
#include<stdio.h>
main()
{
int num1=5,num2=7,sum;
sum=num1+num2;
printf(“SUM OF 2 NUMBER IS = %d “ , sum);
} 12
Decision control structure is actually the divide and
conquer approach.
If Condition:-
If is a conditional statement whose body execute when
the condition is true.
Syntax:-
if(condition/relational expr.)
{ body }
Example:
if(10<=11)
printf(“ YES ”);
13
If-Else Statement:-
Like if condition if else is used that if the if condition is not
true then what would done…. So we use if else condition.
Syntax:-
if(condition/relational expr.)
{ body }
else{ body }
Example:-
if(10<=11)
printf(“ True ”);
else
printf(“ False ”); 14
If else If statement:-
If else if is used when we have multiple conditions. Like if
first condition is not true then one more condition is
applied.
Syntax:-
if(condition/relational expr.)
{ body }
Else if(condition/relational expr.)
{ body }
Example:-
if(11<11)
printf(“ True ”);
Else if(10!=11)
printf(“ Not Equal ”);
15
Nested If:-
Nested if statements are used for condition with nested
condition.
Syntax:-
if(condition/relational expr.)
{ if(condition/relational expr.)
{ body }}
Example:-
if(10<=10)
{ if(1==1)
printf(“11 is not Equal to 10”);
printf(“10 is equal to 10”);
} 16
Conditional Operators:-
Conditional Operators works same as done by if else
statement that if the if condition is not true then what
would done…. So we use conditional operators.
Syntax:-
Condition ? exp1 : exp2; ALSO
!(condition) ? Exp1 : exp2;
Example:-
A>B ? (A>C ? Printf(“A “) : printf(“C”) ) : (B<C ?
Printf(“B”): printf (“C”) ) ;
Suppose A= 1, B=2, C=3 then
Output:- C
17
Switch Statement:-
In computer programming languages, a switch statement is a type of
selection control mechanism used to allow the value of a variable or
expression to change the control flow of program execution via a
multiway branch.
Syntax:
switch ( test ) {
case 0:
Statement/s;
break;
case 1:
Statement/s;
break;
default :
Statement/s;
}
18
Repeats a statement or group of statements while a
given condition is true. It tests the condition before
executing the loop body.
 Initialization
 Condition/ Termination criteria.
 Updation / Incrementation.
19
C provides us three loops.
 While Loop
 Do While loop
 For loop
20
This loop execute until the given condition is true.
In order words, the body of loop execute until the
given condition is true.
Syntax:
while(condition)
{
statement(s);
increment/decrement;
}
21
Example:
Let us considered the following program
main()
{
int i=0 , j ;
while(i<=9)
{
j=i;
printf(“nj=%d”,j);
I++;
}
}
22
We use this loop when we think the body of loop execute
one time without checking the given condition.
Syntax:
do
{
statement(s);
}while(condition);
Here the keyword do allows the control to enter into the
body of loop without checking the condition.
The condition will checked after the execution of the body
of the loop.
23
Example:
main()
{
int x=23,y=45,guess;
do
{
printf(“%d + %d =“);
scanf(“%d”,&guess);
}while((guess!=(x+y));
}
24
A for loop is a repetition control structure that
allows you to efficiently write a loop that needs to
execute a specific number of times.
Syntax:
for( init; condition; increment/decrement)
{
statement(s);
}
25
Example:
main()
{
int i;
for(i=1;i<=10;i++)
{
printf(“%dn”,i);
}
}
26
o Contiguous memory location.
o Same data type.
o Random Access
If we need to store marks of 100 students, instead
of using 100 variables we simply use array.
Syntax:
type Array_name[Size_of_Array];
Example:
int a[10];
27
Program:
main()
{
int a[10],i;
for(i=0 ; i<10 ; i++)
{
printf(“Enter numbern”);
scanf(“%d”,&a[i]);
}
}
28
Representation of data in the form of matrix in
memory.
Syntax:
Type array_name[rows][columns];
Example:
int arr[2][3];
29
Example:
main()
{
int a[2][3];
int row,col;
{
for(row=0;row<2;row++)
{
for(col=0;col<3;col++)
{
scanf(“%d”,&a[row][col];
}
}
}
}
30
Syntax:
type array_name[x][y][z];
Example:
int A[6][4][3];
Program:
main()
{
int a[2][2][3];
int i,j,k;
for( i=0;i<=1;i++)
{
for(j=0;j<=1;j++)
{
for(k=0;k<=2;k++)
{
scanf(“%d”,&a[i][j][k];
}
}
}
31
A function is a self-contained block of statements
that perform a coherent task of some kind.
Every C program begins with a function called
main() function.
Parts:
 Function Prototype
 Function Call
 Function Definition
32
Function Prototype
A function prototype is a declaration of a
function that specifies the function's name and
type signature (arity, parameter types, and return
type).
Semicolon should be implemented at the end.
Syntax:
type function_name ( type arg1, type arg2...... );
33
Function Call:
In this part we call function in another function to
perform specific task.
Syntax:
F=mark();
Example:
main()
{
mark();
}
34
Function Definition:
In function definition, we specify which task will
performed by this function.
Example:
void Mark()
{
printf(“This is a function”):
}
35
Return Statement:
It is used to return control and value to the
location from where the function is call.
It returns only one value.
Example:
int marks(int x ,int y)
{
int sum= (x+y) ;
return sum;
}
36
Call by value:
The call by value method of passing arguments to a
function copies the actual value of an argument into
the formal parameter of the function.
Example:
int marks(int x ,int y)
{
int sum= (x+y) ;
return sum;
}
37
Call by Reference:
The call by reference method of passing
arguments to a function copies the address of an
argument into the formal parameter. We have use
pointers in order to copy address of variable. We
will discuss pointers in next topic.
38
Pointers:
Pointers are used to stored address of variables.
How to declare it?
int *y;
y=&x;
Example:
main()
{
int x=3,*y;
y=&x;
printf(“%d”,*y);
}
39
Pointer to a Pointer:
It contains address of pointer.
How to declare it?
int **k;
40
Example:
41
Structures:
 Arrays allow to define type of variables that can hold
several data items of the same kind.
Similarly structure is another user defined data type
available in C that allows to combine data items of
different kinds.
 Structures are used to represent a record. Suppose you
want to keep track of your books in a library. You
might want to track the following attributes about each
book −
 Title
 Author
 Subject
 Book ID
42
Syntax:
struct structure tag
{
Member definition;
Member definition;
.
.
. Member definition;
};one or more structure variables
43
Example:
struct Book
{
char name[15];
char author [15];
int price;
};
44

More Related Content

What's hot (20)

PDF
Chap 5 c++
Venkateswarlu Vuggam
 
PPT
Lecture 11 - Functions
Md. Imran Hossain Showrov
 
PPT
FP 201 Unit 2 - Part 3
rohassanie
 
PPT
Lecture 14 - Scope Rules
Md. Imran Hossain Showrov
 
PPT
FP 201 - Unit 3 Part 2
rohassanie
 
PPT
Lecture 13 - Storage Classes
Md. Imran Hossain Showrov
 
PPTX
Overview of c++ language
samt7
 
PPT
FP 201 Unit 3
rohassanie
 
PPT
C++ programming
viancagerone
 
PDF
Algorithm and Programming (Branching Structure)
Adam Mukharil Bachtiar
 
PPTX
Iterative control structures, looping, types of loops, loop working
Neeru Mittal
 
PDF
4th_Ed_Ch03.pdf
ShifatiRabbi
 
PPT
Lecture 9- Control Structures 1
Md. Imran Hossain Showrov
 
PDF
Python unit 2 as per Anna university syllabus
DhivyaSubramaniyam
 
PPT
FP 201 - Unit 6
rohassanie
 
PPTX
Storage classes in c language
tanmaymodi4
 
PDF
Algorithm and Programming (Looping Structure)
Adam Mukharil Bachtiar
 
PPTX
Operators and Control Statements in Python
RajeswariA8
 
PDF
Functional Programming in C#
Giorgio Zoppi
 
Lecture 11 - Functions
Md. Imran Hossain Showrov
 
FP 201 Unit 2 - Part 3
rohassanie
 
Lecture 14 - Scope Rules
Md. Imran Hossain Showrov
 
FP 201 - Unit 3 Part 2
rohassanie
 
Lecture 13 - Storage Classes
Md. Imran Hossain Showrov
 
Overview of c++ language
samt7
 
FP 201 Unit 3
rohassanie
 
C++ programming
viancagerone
 
Algorithm and Programming (Branching Structure)
Adam Mukharil Bachtiar
 
Iterative control structures, looping, types of loops, loop working
Neeru Mittal
 
4th_Ed_Ch03.pdf
ShifatiRabbi
 
Lecture 9- Control Structures 1
Md. Imran Hossain Showrov
 
Python unit 2 as per Anna university syllabus
DhivyaSubramaniyam
 
FP 201 - Unit 6
rohassanie
 
Storage classes in c language
tanmaymodi4
 
Algorithm and Programming (Looping Structure)
Adam Mukharil Bachtiar
 
Operators and Control Statements in Python
RajeswariA8
 
Functional Programming in C#
Giorgio Zoppi
 

Similar to Programming Fundamentals (20)

PPT
C programming
Harshit Varshney
 
PPTX
Introduction to c
Ajeet Kumar
 
PPTX
C introduction by thooyavan
Thooyavan Venkatachalam
 
PDF
C programming day#1
Mohamed Fawzy
 
PPSX
Esoft Metro Campus - Certificate in c / c++ programming
Rasan Samarasinghe
 
PPTX
C language
Robo India
 
PPTX
Team-7 SP.pptxdfghjksdfgduytredfghjkjhgffghj
bayazidalom983
 
PPTX
Fundamental programming Nota Topic 2.pptx
UmmuNazieha
 
PPTX
C programming language tutorial
javaTpoint s
 
PPTX
C programming language:- Introduction to C Programming - Overview and Importa...
SebastianFrancis13
 
PDF
The New Yorker cartoon premium membership of the
shubhamgupta7133
 
PPTX
C language
Priya698357
 
PDF
Unit 1
Sowri Rajan
 
PPTX
Cpu
Mohit Jain
 
PPTX
C_Progragramming_language_Tutorial_ppt_f.pptx
maaithilisaravanan
 
PPTX
C Language (All Concept)
sachindane
 
PPTX
C Programming with oops Concept and Pointer
Jeyarajs7
 
PPT
Chap 1 and 2
Selva Arrunaa Mathavan
 
PPTX
Fundamentals of computer programming by Dr. A. Charan Kumari
THE NORTHCAP UNIVERSITY
 
PPTX
What is c
Nitesh Saitwal
 
C programming
Harshit Varshney
 
Introduction to c
Ajeet Kumar
 
C introduction by thooyavan
Thooyavan Venkatachalam
 
C programming day#1
Mohamed Fawzy
 
Esoft Metro Campus - Certificate in c / c++ programming
Rasan Samarasinghe
 
C language
Robo India
 
Team-7 SP.pptxdfghjksdfgduytredfghjkjhgffghj
bayazidalom983
 
Fundamental programming Nota Topic 2.pptx
UmmuNazieha
 
C programming language tutorial
javaTpoint s
 
C programming language:- Introduction to C Programming - Overview and Importa...
SebastianFrancis13
 
The New Yorker cartoon premium membership of the
shubhamgupta7133
 
C language
Priya698357
 
Unit 1
Sowri Rajan
 
C_Progragramming_language_Tutorial_ppt_f.pptx
maaithilisaravanan
 
C Language (All Concept)
sachindane
 
C Programming with oops Concept and Pointer
Jeyarajs7
 
Fundamentals of computer programming by Dr. A. Charan Kumari
THE NORTHCAP UNIVERSITY
 
What is c
Nitesh Saitwal
 
Ad

Recently uploaded (20)

PDF
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
PPTX
Customise Your Correlation Table in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PDF
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PPTX
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
PDF
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PDF
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
Customise Your Correlation Table in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
Ad

Programming Fundamentals

  • 1. Prepared By: Abdullah Iqbal And Umar Aftab 1
  • 2. 1972, AT&T Bell’s laboratories by Denis and Ritchie. Alphabets Keywords Digits Constants Statements Program Symbols Variables Alphabets :- A,B,C,….,Z. Digits :- 1,2,3,4….9. Symbols :- ! # $ % ^ & * ( ) _ + : ; ’ , . Etc. Keywords:- these are reserve words in compiler. Constants :- a. Primary Constants:- Integer : without fractional part/whole numbers. Real : with both fractional and integer parts. Character: digit/alphabets/symbol enclosed in ‘ ’ . b. Secondary Constants:- Arrays, Pointers, Structures Etc. 2
  • 3.  For Integer Constants:- a. It must have one digit. b. May be positive as well as negative.(by default positive) c. Range : (underflow) -32768 to +32767 (overflow)  For Real Constants:- a. May be positive as well as negative.(by default positive) b. It must have one digit. c. Range : -3.4 X 1038 to +3.4 X 1038 .  For Character Constants:- a. Maximum length of character constant is 1. 3
  • 4.  Variables means, whose value varies and can be changed easily.  Variable is a named memory location. Rules for Constructing Variables: a. Variable have maximum length of 31 characters. b. Variable name must start with alphabet or underscore. c. No space, commas or special symbols are allowed. d. Keyword(reserve words) can’t be used as variable name. Examples: Valid Invalid AbCd A bC D A44o_ @12f Age printf 4
  • 5.  Keywords means reserve words.  There are about 32 keywords in Dev compiler  Examples: Auto break if else While for continue int Float char scanf printf dowhile Etc. 5
  • 6. For Programing there are some important tips Like;  Every statement end with semicolon. (;)  There must be execution order.  Use of Pre-processor Directories. Like main()…. 6
  • 7. Generally we used three types of Datatypes that is: integer float and character. Integer:- short type reserve 2 bytes in memory location. 4 bytes in Dev compiler. (-32768 to +32767) Long type reserve 4 bytes in memory location ( -2147483648 to +2147483647) Character:- written in single comas(‘ A ’),it reserves 1 byte in memory location . Float:- Simple 1.7 X 10-38 to 1.7X 10 38 reserve 4 byte in memory location Double 2.3 X 10-308 to 1.7X 10 308 reserve 8 byte in memory location Long Double 2.4 X 10-4932 to 1.1X 10 4932 reserve 4 byte in memory location 7
  • 8.  Variable Declaration Statement. Use to declare variable in C.  Assignment Statements. It may be variable initialization statement and also updation.  Compound Assignment Statements. Using single variable, same values are assigned.  Variable Initialization Statements. initially variable’s value like : num1=10;  Variable Increment Decrement Statement. pre inc / dec : first increase/decrease then execute. post inc / dec : first execute then increase/decrease. 8
  • 9. Group of operands and operators are called Expressions. Operands can be constant or variable or other expressions. Logical Expressions: Athematic : + - * / ** % Etc. Logical : AND (&&) OR (||) NOT (!) Relational Expressions: for comparing <, =, >, >=, ==. 9
  • 10. There are two type of type conversion: Implicit :- Automatically convert by compiler. integer integer = integer integer float = float float float = float Explicit :- According to our wish. a=int (4.5) a=4. 10
  • 11. Input :- scanf( ) => float/integer/string. gets() => string. Output :- printf() => integer/float/string. puts() => string. printf(“format string ” , list of arguments) /t for tab space. /d for integer /s for string /b for bell /n for new line. 11
  • 12. In C language Program is written according to proper syntax: Pre-processors directories( #include ) Main function ( main() ) Body of the program ( { …… } ) Simple Sum Program #include<stdio.h> main() { int num1=5,num2=7,sum; sum=num1+num2; printf(“SUM OF 2 NUMBER IS = %d “ , sum); } 12
  • 13. Decision control structure is actually the divide and conquer approach. If Condition:- If is a conditional statement whose body execute when the condition is true. Syntax:- if(condition/relational expr.) { body } Example: if(10<=11) printf(“ YES ”); 13
  • 14. If-Else Statement:- Like if condition if else is used that if the if condition is not true then what would done…. So we use if else condition. Syntax:- if(condition/relational expr.) { body } else{ body } Example:- if(10<=11) printf(“ True ”); else printf(“ False ”); 14
  • 15. If else If statement:- If else if is used when we have multiple conditions. Like if first condition is not true then one more condition is applied. Syntax:- if(condition/relational expr.) { body } Else if(condition/relational expr.) { body } Example:- if(11<11) printf(“ True ”); Else if(10!=11) printf(“ Not Equal ”); 15
  • 16. Nested If:- Nested if statements are used for condition with nested condition. Syntax:- if(condition/relational expr.) { if(condition/relational expr.) { body }} Example:- if(10<=10) { if(1==1) printf(“11 is not Equal to 10”); printf(“10 is equal to 10”); } 16
  • 17. Conditional Operators:- Conditional Operators works same as done by if else statement that if the if condition is not true then what would done…. So we use conditional operators. Syntax:- Condition ? exp1 : exp2; ALSO !(condition) ? Exp1 : exp2; Example:- A>B ? (A>C ? Printf(“A “) : printf(“C”) ) : (B<C ? Printf(“B”): printf (“C”) ) ; Suppose A= 1, B=2, C=3 then Output:- C 17
  • 18. Switch Statement:- In computer programming languages, a switch statement is a type of selection control mechanism used to allow the value of a variable or expression to change the control flow of program execution via a multiway branch. Syntax: switch ( test ) { case 0: Statement/s; break; case 1: Statement/s; break; default : Statement/s; } 18
  • 19. Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body.  Initialization  Condition/ Termination criteria.  Updation / Incrementation. 19
  • 20. C provides us three loops.  While Loop  Do While loop  For loop 20
  • 21. This loop execute until the given condition is true. In order words, the body of loop execute until the given condition is true. Syntax: while(condition) { statement(s); increment/decrement; } 21
  • 22. Example: Let us considered the following program main() { int i=0 , j ; while(i<=9) { j=i; printf(“nj=%d”,j); I++; } } 22
  • 23. We use this loop when we think the body of loop execute one time without checking the given condition. Syntax: do { statement(s); }while(condition); Here the keyword do allows the control to enter into the body of loop without checking the condition. The condition will checked after the execution of the body of the loop. 23
  • 24. Example: main() { int x=23,y=45,guess; do { printf(“%d + %d =“); scanf(“%d”,&guess); }while((guess!=(x+y)); } 24
  • 25. A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times. Syntax: for( init; condition; increment/decrement) { statement(s); } 25
  • 27. o Contiguous memory location. o Same data type. o Random Access If we need to store marks of 100 students, instead of using 100 variables we simply use array. Syntax: type Array_name[Size_of_Array]; Example: int a[10]; 27
  • 28. Program: main() { int a[10],i; for(i=0 ; i<10 ; i++) { printf(“Enter numbern”); scanf(“%d”,&a[i]); } } 28
  • 29. Representation of data in the form of matrix in memory. Syntax: Type array_name[rows][columns]; Example: int arr[2][3]; 29
  • 31. Syntax: type array_name[x][y][z]; Example: int A[6][4][3]; Program: main() { int a[2][2][3]; int i,j,k; for( i=0;i<=1;i++) { for(j=0;j<=1;j++) { for(k=0;k<=2;k++) { scanf(“%d”,&a[i][j][k]; } } } 31
  • 32. A function is a self-contained block of statements that perform a coherent task of some kind. Every C program begins with a function called main() function. Parts:  Function Prototype  Function Call  Function Definition 32
  • 33. Function Prototype A function prototype is a declaration of a function that specifies the function's name and type signature (arity, parameter types, and return type). Semicolon should be implemented at the end. Syntax: type function_name ( type arg1, type arg2...... ); 33
  • 34. Function Call: In this part we call function in another function to perform specific task. Syntax: F=mark(); Example: main() { mark(); } 34
  • 35. Function Definition: In function definition, we specify which task will performed by this function. Example: void Mark() { printf(“This is a function”): } 35
  • 36. Return Statement: It is used to return control and value to the location from where the function is call. It returns only one value. Example: int marks(int x ,int y) { int sum= (x+y) ; return sum; } 36
  • 37. Call by value: The call by value method of passing arguments to a function copies the actual value of an argument into the formal parameter of the function. Example: int marks(int x ,int y) { int sum= (x+y) ; return sum; } 37
  • 38. Call by Reference: The call by reference method of passing arguments to a function copies the address of an argument into the formal parameter. We have use pointers in order to copy address of variable. We will discuss pointers in next topic. 38
  • 39. Pointers: Pointers are used to stored address of variables. How to declare it? int *y; y=&x; Example: main() { int x=3,*y; y=&x; printf(“%d”,*y); } 39
  • 40. Pointer to a Pointer: It contains address of pointer. How to declare it? int **k; 40
  • 42. Structures:  Arrays allow to define type of variables that can hold several data items of the same kind. Similarly structure is another user defined data type available in C that allows to combine data items of different kinds.  Structures are used to represent a record. Suppose you want to keep track of your books in a library. You might want to track the following attributes about each book −  Title  Author  Subject  Book ID 42
  • 43. Syntax: struct structure tag { Member definition; Member definition; . . . Member definition; };one or more structure variables 43
  • 44. Example: struct Book { char name[15]; char author [15]; int price; }; 44

Editor's Notes

  • #2: Course Content: Variables Datatypes Keywords Conditional Operators Conditional Statements a . if b . if- el if c . Nested if Switch Statements Loops a . For loop b . While loop c . Do-while loop d . Nested loop Arrays a . 1-D arrays b . 2-D arrays Functions Structures