SlideShare a Scribd company logo
Introduction to C program
Structure of C program
Preprocessor directives
Global variables
Main(void)
{
Local variables
Statements
…..………
…………….
Return 0;
}
Function()
{
Local variables
Statements
…………..
}
#include<stdio.h>
#define num 10
Static Int I; //static or extern
Main()
{
Int I, num; /* static, global, auto or registers
declaration*/
Int a=5; // initialization
Scanf(“%d”,&i);
Printf(“i=%d,num=%d,a=%d”,I,num,a);
}
Compilation and execution of c program
Pre-processor
Compiler
Assembler
Linker
Source code
Expanded code
Assembly code
Object code
Executable code
.c C code
.i intermediate code
.s assembly code
.o object code
.exe / a.out
Errors in c program
Compile time error Run time error
Pre processor
error
Translator error
Linker error Segmentation error
Bus error
…….
……..
...…….64 types of errors
Data types
 Character data type (char)
 Signed - 1 byte (-128 to 127)
 Unsigned - 1 byte (0 to 255)
 Integer data type (int)
 Short int : signed - 1 byte (-128 to 127)
Unsigned - 1 byte (0 to 255)
 int : signed - 2 byte (-2G to 2G)
Unsigned - 2 byte (0 to 4G)
 long int : signed - 4 byte (-4G to 4G)
Unsigned - 4 byte (0 to 8G)
 Real data type (float and double)
 Float - 4bytes (3.4e-38 to 3.4e+38)
 Double - 8 bytes (1.7e-308 to 1.7e+308)
 Long double - 10 bytes (3.4e-4932 to 3.4e+4932)
 String data type (string)
‘a’ , ’1’
123 , 0X1223
Float (0.25f) and double (0.25)
“1234”, “nishma”
Operators
• Arithmetic operator ( + , - , * , / , % ) – binary – doesn’t change the value – result (value)
• Relational operator ( > , >= , < , <= , == , != ) – binary – doesn’t change the value – result (0 or 1)
• Logical or Boolean operator (&& , || , ! ) – binary – doesn’t change the value – result (0 or 1)
• Conditional operator ( [? :] ) – ternary – doesn’t change the value – result (true stat or false stat)
• Bitwise operator ( & , | , ~ , << , >> ,^ ) – binary – changes the value
• Increment and decrement operator ( ++ , -- ) – unary – changes the value
• Size of operator ( sizeof() ) –unary –doesn’t change the value
Control statements
Iterative Non - iterative
Conditional Unconditional
 For
 While
 Do while
 If
 Else if
 Switch - case
 Goto
 Break
 Return
 Continue
If statement
If (condition)
{
Statement1;
Statement2;
Statement3;
}
If (condition)
Statement1;
Statement2;
Statement3;
If (condition);
{
Statement1;
Statement2;
Statement3;
}
true
Example
#include<stdio.h>
Main()
{
Int a=10,b=20;
If (a<b)
{
a=b;
Printf(“greater=%d”,a);
}
}
#include<stdio.h>
Main()
{
Int a=10,b=20;
If (a<b)
a=b;
Printf(“greater=%d”,a);
}
If esle statement
If (condition)
Statement 1;
Else
Statement 2;
If (condition)
{
Statement 1;
}
Else
{
Statement 2;
}
If (condition)
{
Statement 1;
}
Else
Statement 2;
If (condition)
Statement 1;
Else
{
Statement 2;
}
Condition
Statement 1 Statement 2
Next statement
True False
Example
#include<stdio.h>
Main()
{
Int a=10,b=20;
If (a<b)
{
a=b;
Printf(“greater=%d”,a);
}
else
Printf(“greater=%d”,a);
}
#include<stdio.h>
Main()
{
Int a=10,b=20;
If (a<b)
a=b;
Printf(“greater=%d”,a);
else
Printf(“greater=%d”,a);
}
Else if ladder
If (expression 1)
Statement 1;
Else if (expression 2)
Statement 2;
Else if (expression 3)
Statement 3;
Else
Statement 4;
Nested if else ladder
If (exp 1)
{
If (exp 2)
{
if (exp 3)
{
S1;
}
else
S2;
}
else
S3;
}
Else
S4;
Switch case statement
Switch (expression)
{
Case label 1 : S1;
S2;
break;
Case label 2 : S1;
S2;
break;
Default : S1;
Result should be in
Char, short int, int.
Strings and float are not allowed
Not mandatory
Example
#include<stdio.h>
Main()
{
Int a;
Scanf(“%d”,&a);
Switch (a)
{
Case 1 : printf(“%d”,a++);
break;
Case 2 : printf(“%d”,++a);
break;
Default:printf(“%d”,--a);
For statement
For (exp 1 ; exp 2 ; exp 3)
{
Statement 1;
Statement 2;
}
Initialization
Condition checking
Control variable
operators
Body of the
loop
For (exp 1 ; exp 2 ; exp 3);
{
Statement 1;
Statement 2;
}
Example
For (i=0 ; i<=10 ; i++)
{
Printf(“%d”,i);
}
For (i=0 ; i<=10 ; i++);
{
Printf(“%d”,i);
}
o/p:
0 1 2 3 4 5 6 7 8 9 10
o/p:
i=11
Nesting For statement
For (exp 1 ; exp 2 ; exp 3)
{
Statement 1;
Statement 2;
for (exp 4 ; exp 5 ; exp 6)
{
statement 3;
statement 4;
}
}
Outer loop control
variables and inner loop
control variables will not
be the same
1 2
3
8
4 5
6
7
For (i=0 ; i<4 ; i++)
{
n=i;
for (j=0 ; j<n ; j++)
{
printf(“ %d ”,j);
}
printf(“n”);
}
o/p:
i=0 , i<4 , n=0 ; j=0 , j<0;
i=1 , i<4 , n=1 ; j=0 , j<1; j=1 , j<1;
i=2 , i<4 , n=2 ; j=0 , j<2; j=1 , j<2;j=2 , j<2
i=3 , i<4 , n=1 ; j=0 , j<3; j=1 , j<3;j=2 , j<3; j=3 , j<3
i=4 , i<4
0
0 1
0 1 2
While statement
While (expression)
{
Statement 1;
Statement 2;
}
Expression
Body of the loop
True
False
Next statements
While (exp1 ; exp2 ; exp3)
{
Statement 1;
Statement 2;
}
Last exp (exp3)
decides whether
to enter the loop
or not
While (expression)
Statement 1;
Example
Int i=0;
While (i==0)
{
Printf(“i=%dn”, i++);
Printf(“i=%dn”,++i);
}
o/p:
i=0
i=2
Int i=0;
While (i==0);
{
Printf(“i=%dn”, i++);
Printf(“i=%dn”,++i);
}
o/p:
Infinite loop
Doesn’t print any value
Do While statement
Do
{
Statement 1;
Statement 2;
}
While (expression);
Expression
Body of the loop
True
False
Next statements
Do
Statement 1;
While (expression);
Example
Int i=0;
Do
{
Printf(“i=%dn”, i++);
Printf(“i=%dn”,++i);
}
While(i<10); o/p:
i=0 , i=2
i<10 , i=2 , i=4
…………
i<10 , i=8 , i=10
i<10 next statement
Goto statement
Forward jump
Goto label;
Statements;
…………
……………
Label:
Statements;
…………
……………
Backward jump
Label:
Statements;
…………
……………
Goto label;
Statements;
…………
……………
Example
Int a;
Start:
Printf(“enter the valuen”);
Scanf(“%d”,&a);
Printf(“%d”,++a);
Goto start;
Break statement
Break;
Arrays
Data_type array_name [index];
No of elements
in the array
To scan
For (i=0 ; a[i] ; i++)
{
Scanf(“%d”,&a[i]);
}
To print
For (i=0 ; a[i] ; i++)
{
printf(“%d”,a[i]);
}
Array representation
A[i]=i[a]=*(a+i)
Example:
Int a[6];
Int a[6] = {10,20,30,40,50,60};
1D array
2D array
To scan
For (i=0 ; i<n ; i++)
{
for(j=0 ; j<m ; j++)
Scanf(“%d”,&a[i]);
}
To print
For (i=0 ; a[i] ; i++)
{
for(j=0 ; j<m ; j++)
printf(“%d”,a[i]);
}
Strings
Data_type string_name [index];
Example:
char s[6];
char s[6] = “hello”;
No of elements
in the string
To scan
For (i=0 ; s[i] ; i++)
{
Scanf(“%c”,&s[i]);
}
Or
Scanf(“%s”,s);
To print
For (i=0 ; s[i] ; i++)
{
printf(“%c”,s[i]);
}
Or
Printf(“%s”,s);
It is a collection of characters terminated by a null symbol (‘o’)
Functions
Library function
User defined function
Example:
Sqrt();
Function declaration
Function call
Function definition
Return_type fun_name (type1 par1, type2 par2,…..);
Fun_name (arg1, arg2, arg3);
Return_type fun_name (parameter declarations)
Return (exp);
Storage classes
Auto Static Extern Register
Default Garbage 0 0 Garbage
Memory Stack frame Data segment Data segment Stack frame
Scope locally Accessed directly
within a fun or
block
Accessed within
a fun
Accessed within
a fun
Accessed directly
within a fun or
block
globally Cannot be
declared globally
can access
throughout the
file.
can access
throughout the
file.
Cannot be
declared globally
Life Start When fun stack
frame created
When program
is loaded into
RAM
Same as static When fun
execution starts
End When it gets
deallocated
When execution
is completed
Same as static When execution
ends

More Related Content

What's hot

Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
nTier Custom Solutions
 
C fundamentals
C fundamentalsC fundamentals
C structure
C structureC structure
C structure
ankush9927
 
C Programming Language Part 6
C Programming Language Part 6C Programming Language Part 6
C Programming Language Part 6
Rumman Ansari
 
C preprocesor
C preprocesorC preprocesor
C preprocesor
preetikapri1
 
Important C program of Balagurusamy Book
Important C program of Balagurusamy BookImportant C program of Balagurusamy Book
Important C program of Balagurusamy Book
Abir Hossain
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
Abhishek Sinha
 
Simple c program
Simple c programSimple c program
Simple c program
Ravi Singh
 
CPU INPUT OUTPUT
CPU INPUT OUTPUT CPU INPUT OUTPUT
CPU INPUT OUTPUT
Aditya Vaishampayan
 
Programming Global variable
Programming Global variableProgramming Global variable
Programming Global variable
imtiazalijoono
 
UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
JavvajiVenkat
 
Programming in C [Module One]
Programming in C [Module One]Programming in C [Module One]
Programming in C [Module One]
Abhishek Sinha
 
Chap 2 structure of c programming dti2143
Chap 2  structure of c programming dti2143Chap 2  structure of c programming dti2143
Chap 2 structure of c programming dti2143
alish sha
 
Fundamentals of computer programming by Dr. A. Charan Kumari
Fundamentals of computer programming by Dr. A. Charan KumariFundamentals of computer programming by Dr. A. Charan Kumari
Fundamentals of computer programming by Dr. A. Charan Kumari
THE NORTHCAP UNIVERSITY
 
Programming basics
Programming basicsProgramming basics
Programming basics
246paa
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c language
tanmaymodi4
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
Tarun Sharma
 
7 functions
7  functions7  functions
7 functions
MomenMostafa
 
Managing input and output operation in c
Managing input and output operation in cManaging input and output operation in c
Managing input and output operation in c
yazad dumasia
 
C lab-programs
C lab-programsC lab-programs
C lab-programs
Tony Kurishingal
 

What's hot (20)

Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
 
C fundamentals
C fundamentalsC fundamentals
C fundamentals
 
C structure
C structureC structure
C structure
 
C Programming Language Part 6
C Programming Language Part 6C Programming Language Part 6
C Programming Language Part 6
 
C preprocesor
C preprocesorC preprocesor
C preprocesor
 
Important C program of Balagurusamy Book
Important C program of Balagurusamy BookImportant C program of Balagurusamy Book
Important C program of Balagurusamy Book
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 
Simple c program
Simple c programSimple c program
Simple c program
 
CPU INPUT OUTPUT
CPU INPUT OUTPUT CPU INPUT OUTPUT
CPU INPUT OUTPUT
 
Programming Global variable
Programming Global variableProgramming Global variable
Programming Global variable
 
UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
 
Programming in C [Module One]
Programming in C [Module One]Programming in C [Module One]
Programming in C [Module One]
 
Chap 2 structure of c programming dti2143
Chap 2  structure of c programming dti2143Chap 2  structure of c programming dti2143
Chap 2 structure of c programming dti2143
 
Fundamentals of computer programming by Dr. A. Charan Kumari
Fundamentals of computer programming by Dr. A. Charan KumariFundamentals of computer programming by Dr. A. Charan Kumari
Fundamentals of computer programming by Dr. A. Charan Kumari
 
Programming basics
Programming basicsProgramming basics
Programming basics
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c language
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
 
7 functions
7  functions7  functions
7 functions
 
Managing input and output operation in c
Managing input and output operation in cManaging input and output operation in c
Managing input and output operation in c
 
C lab-programs
C lab-programsC lab-programs
C lab-programs
 

Similar to 1 introduction to c program

Vcs5
Vcs5Vcs5
18CSS101J PROGRAMMING FOR PROBLEM SOLVING
18CSS101J PROGRAMMING FOR PROBLEM SOLVING18CSS101J PROGRAMMING FOR PROBLEM SOLVING
18CSS101J PROGRAMMING FOR PROBLEM SOLVING
GOWSIKRAJAP
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
Komal Kotak
 
Introduction to c part -1
Introduction to c   part -1Introduction to c   part -1
PROGRAMMING IN C - Operators.pptx
PROGRAMMING IN C - Operators.pptxPROGRAMMING IN C - Operators.pptx
PROGRAMMING IN C - Operators.pptx
Nithya K
 
3. chapter ii
3. chapter ii3. chapter ii
3. chapter ii
Chhom Karath
 
SPL 8 | Loop Statements in C
SPL 8 | Loop Statements in CSPL 8 | Loop Statements in C
SPL 8 | Loop Statements in C
Mohammad Imam Hossain
 
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
 
Program flowchart
Program flowchartProgram flowchart
Program flowchart
Sowri Rajan
 
Intro to c chapter cover 1 4
Intro to c chapter cover 1 4Intro to c chapter cover 1 4
Intro to c chapter cover 1 4
Hazwan Arif
 
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
 
Session05 iteration structure
Session05 iteration structureSession05 iteration structure
Session05 iteration structure
HarithaRanasinghe
 
12 lec 12 loop
12 lec 12 loop 12 lec 12 loop
12 lec 12 loop
kapil078
 
Unit 1- PROGRAMMING IN C OPERATORS LECTURER NOTES
Unit 1- PROGRAMMING IN C OPERATORS LECTURER NOTESUnit 1- PROGRAMMING IN C OPERATORS LECTURER NOTES
Unit 1- PROGRAMMING IN C OPERATORS LECTURER NOTES
LeahRachael
 
Code optimization
Code optimization Code optimization
Code optimization
Code optimization Code optimization
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
sana shaikh
 
C tutorial
C tutorialC tutorial
C tutorial
Anurag Sukhija
 
C_Language_PS&PC_Notes.ppt
C_Language_PS&PC_Notes.pptC_Language_PS&PC_Notes.ppt
C_Language_PS&PC_Notes.ppt
ganeshkarthy
 
C++ Programming.pdf
C++ Programming.pdfC++ Programming.pdf
C++ Programming.pdf
MrRSmey
 

Similar to 1 introduction to c program (20)

Vcs5
Vcs5Vcs5
Vcs5
 
18CSS101J PROGRAMMING FOR PROBLEM SOLVING
18CSS101J PROGRAMMING FOR PROBLEM SOLVING18CSS101J PROGRAMMING FOR PROBLEM SOLVING
18CSS101J PROGRAMMING FOR PROBLEM SOLVING
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 
Introduction to c part -1
Introduction to c   part -1Introduction to c   part -1
Introduction to c part -1
 
PROGRAMMING IN C - Operators.pptx
PROGRAMMING IN C - Operators.pptxPROGRAMMING IN C - Operators.pptx
PROGRAMMING IN C - Operators.pptx
 
3. chapter ii
3. chapter ii3. chapter ii
3. chapter ii
 
SPL 8 | Loop Statements in C
SPL 8 | Loop Statements in CSPL 8 | Loop Statements in C
SPL 8 | Loop Statements in C
 
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
 
Program flowchart
Program flowchartProgram flowchart
Program flowchart
 
Intro to c chapter cover 1 4
Intro to c chapter cover 1 4Intro to c chapter cover 1 4
Intro to c chapter cover 1 4
 
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
 
Session05 iteration structure
Session05 iteration structureSession05 iteration structure
Session05 iteration structure
 
12 lec 12 loop
12 lec 12 loop 12 lec 12 loop
12 lec 12 loop
 
Unit 1- PROGRAMMING IN C OPERATORS LECTURER NOTES
Unit 1- PROGRAMMING IN C OPERATORS LECTURER NOTESUnit 1- PROGRAMMING IN C OPERATORS LECTURER NOTES
Unit 1- PROGRAMMING IN C OPERATORS LECTURER NOTES
 
Code optimization
Code optimization Code optimization
Code optimization
 
Code optimization
Code optimization Code optimization
Code optimization
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
C tutorial
C tutorialC tutorial
C tutorial
 
C_Language_PS&PC_Notes.ppt
C_Language_PS&PC_Notes.pptC_Language_PS&PC_Notes.ppt
C_Language_PS&PC_Notes.ppt
 
C++ Programming.pdf
C++ Programming.pdfC++ Programming.pdf
C++ Programming.pdf
 

Recently uploaded

How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 

Recently uploaded (20)

How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 

1 introduction to c program

  • 2. Structure of C program Preprocessor directives Global variables Main(void) { Local variables Statements …..……… ……………. Return 0; } Function() { Local variables Statements ………….. } #include<stdio.h> #define num 10 Static Int I; //static or extern Main() { Int I, num; /* static, global, auto or registers declaration*/ Int a=5; // initialization Scanf(“%d”,&i); Printf(“i=%d,num=%d,a=%d”,I,num,a); }
  • 3. Compilation and execution of c program Pre-processor Compiler Assembler Linker Source code Expanded code Assembly code Object code Executable code .c C code .i intermediate code .s assembly code .o object code .exe / a.out
  • 4. Errors in c program Compile time error Run time error Pre processor error Translator error Linker error Segmentation error Bus error ……. …….. ...…….64 types of errors
  • 5. Data types  Character data type (char)  Signed - 1 byte (-128 to 127)  Unsigned - 1 byte (0 to 255)  Integer data type (int)  Short int : signed - 1 byte (-128 to 127) Unsigned - 1 byte (0 to 255)  int : signed - 2 byte (-2G to 2G) Unsigned - 2 byte (0 to 4G)  long int : signed - 4 byte (-4G to 4G) Unsigned - 4 byte (0 to 8G)  Real data type (float and double)  Float - 4bytes (3.4e-38 to 3.4e+38)  Double - 8 bytes (1.7e-308 to 1.7e+308)  Long double - 10 bytes (3.4e-4932 to 3.4e+4932)  String data type (string) ‘a’ , ’1’ 123 , 0X1223 Float (0.25f) and double (0.25) “1234”, “nishma”
  • 6. Operators • Arithmetic operator ( + , - , * , / , % ) – binary – doesn’t change the value – result (value) • Relational operator ( > , >= , < , <= , == , != ) – binary – doesn’t change the value – result (0 or 1) • Logical or Boolean operator (&& , || , ! ) – binary – doesn’t change the value – result (0 or 1) • Conditional operator ( [? :] ) – ternary – doesn’t change the value – result (true stat or false stat) • Bitwise operator ( & , | , ~ , << , >> ,^ ) – binary – changes the value • Increment and decrement operator ( ++ , -- ) – unary – changes the value • Size of operator ( sizeof() ) –unary –doesn’t change the value
  • 7. Control statements Iterative Non - iterative Conditional Unconditional  For  While  Do while  If  Else if  Switch - case  Goto  Break  Return  Continue
  • 8. If statement If (condition) { Statement1; Statement2; Statement3; } If (condition) Statement1; Statement2; Statement3; If (condition); { Statement1; Statement2; Statement3; } true
  • 10. If esle statement If (condition) Statement 1; Else Statement 2; If (condition) { Statement 1; } Else { Statement 2; } If (condition) { Statement 1; } Else Statement 2; If (condition) Statement 1; Else { Statement 2; } Condition Statement 1 Statement 2 Next statement True False
  • 12. Else if ladder If (expression 1) Statement 1; Else if (expression 2) Statement 2; Else if (expression 3) Statement 3; Else Statement 4; Nested if else ladder If (exp 1) { If (exp 2) { if (exp 3) { S1; } else S2; } else S3; } Else S4;
  • 13. Switch case statement Switch (expression) { Case label 1 : S1; S2; break; Case label 2 : S1; S2; break; Default : S1; Result should be in Char, short int, int. Strings and float are not allowed Not mandatory
  • 14. Example #include<stdio.h> Main() { Int a; Scanf(“%d”,&a); Switch (a) { Case 1 : printf(“%d”,a++); break; Case 2 : printf(“%d”,++a); break; Default:printf(“%d”,--a);
  • 15. For statement For (exp 1 ; exp 2 ; exp 3) { Statement 1; Statement 2; } Initialization Condition checking Control variable operators Body of the loop For (exp 1 ; exp 2 ; exp 3); { Statement 1; Statement 2; }
  • 16. Example For (i=0 ; i<=10 ; i++) { Printf(“%d”,i); } For (i=0 ; i<=10 ; i++); { Printf(“%d”,i); } o/p: 0 1 2 3 4 5 6 7 8 9 10 o/p: i=11
  • 17. Nesting For statement For (exp 1 ; exp 2 ; exp 3) { Statement 1; Statement 2; for (exp 4 ; exp 5 ; exp 6) { statement 3; statement 4; } } Outer loop control variables and inner loop control variables will not be the same 1 2 3 8 4 5 6 7 For (i=0 ; i<4 ; i++) { n=i; for (j=0 ; j<n ; j++) { printf(“ %d ”,j); } printf(“n”); } o/p: i=0 , i<4 , n=0 ; j=0 , j<0; i=1 , i<4 , n=1 ; j=0 , j<1; j=1 , j<1; i=2 , i<4 , n=2 ; j=0 , j<2; j=1 , j<2;j=2 , j<2 i=3 , i<4 , n=1 ; j=0 , j<3; j=1 , j<3;j=2 , j<3; j=3 , j<3 i=4 , i<4 0 0 1 0 1 2
  • 18. While statement While (expression) { Statement 1; Statement 2; } Expression Body of the loop True False Next statements While (exp1 ; exp2 ; exp3) { Statement 1; Statement 2; } Last exp (exp3) decides whether to enter the loop or not While (expression) Statement 1;
  • 19. Example Int i=0; While (i==0) { Printf(“i=%dn”, i++); Printf(“i=%dn”,++i); } o/p: i=0 i=2 Int i=0; While (i==0); { Printf(“i=%dn”, i++); Printf(“i=%dn”,++i); } o/p: Infinite loop Doesn’t print any value
  • 20. Do While statement Do { Statement 1; Statement 2; } While (expression); Expression Body of the loop True False Next statements Do Statement 1; While (expression);
  • 21. Example Int i=0; Do { Printf(“i=%dn”, i++); Printf(“i=%dn”,++i); } While(i<10); o/p: i=0 , i=2 i<10 , i=2 , i=4 ………… i<10 , i=8 , i=10 i<10 next statement
  • 22. Goto statement Forward jump Goto label; Statements; ………… …………… Label: Statements; ………… …………… Backward jump Label: Statements; ………… …………… Goto label; Statements; ………… …………… Example Int a; Start: Printf(“enter the valuen”); Scanf(“%d”,&a); Printf(“%d”,++a); Goto start;
  • 24. Arrays Data_type array_name [index]; No of elements in the array To scan For (i=0 ; a[i] ; i++) { Scanf(“%d”,&a[i]); } To print For (i=0 ; a[i] ; i++) { printf(“%d”,a[i]); } Array representation A[i]=i[a]=*(a+i) Example: Int a[6]; Int a[6] = {10,20,30,40,50,60}; 1D array
  • 25. 2D array To scan For (i=0 ; i<n ; i++) { for(j=0 ; j<m ; j++) Scanf(“%d”,&a[i]); } To print For (i=0 ; a[i] ; i++) { for(j=0 ; j<m ; j++) printf(“%d”,a[i]); }
  • 26. Strings Data_type string_name [index]; Example: char s[6]; char s[6] = “hello”; No of elements in the string To scan For (i=0 ; s[i] ; i++) { Scanf(“%c”,&s[i]); } Or Scanf(“%s”,s); To print For (i=0 ; s[i] ; i++) { printf(“%c”,s[i]); } Or Printf(“%s”,s); It is a collection of characters terminated by a null symbol (‘o’)
  • 27. Functions Library function User defined function Example: Sqrt(); Function declaration Function call Function definition Return_type fun_name (type1 par1, type2 par2,…..); Fun_name (arg1, arg2, arg3); Return_type fun_name (parameter declarations) Return (exp);
  • 28. Storage classes Auto Static Extern Register Default Garbage 0 0 Garbage Memory Stack frame Data segment Data segment Stack frame Scope locally Accessed directly within a fun or block Accessed within a fun Accessed within a fun Accessed directly within a fun or block globally Cannot be declared globally can access throughout the file. can access throughout the file. Cannot be declared globally Life Start When fun stack frame created When program is loaded into RAM Same as static When fun execution starts End When it gets deallocated When execution is completed Same as static When execution ends