SlideShare a Scribd company logo
1 of 44
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

What's hot (20)

Chap 5 c++
Chap 5 c++Chap 5 c++
Chap 5 c++
 
Lecture 11 - Functions
Lecture 11 - FunctionsLecture 11 - Functions
Lecture 11 - Functions
 
FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3
 
Lecture 14 - Scope Rules
Lecture 14 - Scope RulesLecture 14 - Scope Rules
Lecture 14 - Scope Rules
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
 
Lecture 13 - Storage Classes
Lecture 13 - Storage ClassesLecture 13 - Storage Classes
Lecture 13 - Storage Classes
 
Overview of c++ language
Overview of c++ language   Overview of c++ language
Overview of c++ language
 
FP 201 Unit 3
FP 201 Unit 3 FP 201 Unit 3
FP 201 Unit 3
 
C++ programming
C++ programmingC++ programming
C++ programming
 
Algorithm and Programming (Branching Structure)
Algorithm and Programming (Branching Structure)Algorithm and Programming (Branching Structure)
Algorithm and Programming (Branching Structure)
 
Unit ii ppt
Unit ii pptUnit ii ppt
Unit ii ppt
 
Iterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingIterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop working
 
4th_Ed_Ch03.pdf
4th_Ed_Ch03.pdf4th_Ed_Ch03.pdf
4th_Ed_Ch03.pdf
 
Lecture 9- Control Structures 1
Lecture 9- Control Structures 1Lecture 9- Control Structures 1
Lecture 9- Control Structures 1
 
Python unit 2 as per Anna university syllabus
Python unit 2 as per Anna university syllabusPython unit 2 as per Anna university syllabus
Python unit 2 as per Anna university syllabus
 
FP 201 - Unit 6
FP 201 - Unit 6FP 201 - Unit 6
FP 201 - Unit 6
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c language
 
Algorithm and Programming (Looping Structure)
Algorithm and Programming (Looping Structure)Algorithm and Programming (Looping Structure)
Algorithm and Programming (Looping Structure)
 
Operators and Control Statements in Python
Operators and Control Statements in PythonOperators and Control Statements in Python
Operators and Control Statements in Python
 
Functional Programming in C#
Functional Programming in C#Functional Programming in C#
Functional Programming in C#
 

Similar to Programming Fundamentals

Similar to Programming Fundamentals (20)

C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
C fundamental
C fundamentalC fundamental
C fundamental
 
What is c
What is cWhat is c
What is c
 
C++ decision making
C++ decision makingC++ decision making
C++ decision making
 
Notes on c++
Notes on c++Notes on c++
Notes on c++
 
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDYC UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
 
[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2
 
C programming session 02
C programming session 02C programming session 02
C programming session 02
 
Programming in C Session 1
Programming in C Session 1Programming in C Session 1
Programming in C Session 1
 
Python programing
Python programingPython programing
Python programing
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
C operators
C operatorsC operators
C operators
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
Python Programming Module 3 (2).pdf
Python Programming Module 3 (2).pdfPython Programming Module 3 (2).pdf
Python Programming Module 3 (2).pdf
 
C important questions
C important questionsC important questions
C important questions
 
pythonQuick.pdf
pythonQuick.pdfpythonQuick.pdf
pythonQuick.pdf
 
python notes.pdf
python notes.pdfpython notes.pdf
python notes.pdf
 
python 34💭.pdf
python 34💭.pdfpython 34💭.pdf
python 34💭.pdf
 

Recently uploaded

Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 

Recently uploaded (20)

Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 

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

  1. 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