SlideShare a Scribd company logo
A Structured Programming Approach Using C1
Objectives
❏ To understand the structure of a C-language program.
❏ To write your first C program.
❏ To introduce the include preprocessor command.
❏ To be able to create good identifiers for objects in a program.
❏ To be able to list, describe, and use the C basic data types.
❏ To be able to create and use variables and constants.
❏ To understand input and output concepts.
❏ To be able to use simple input and output statements.
Introduction to the C LanguageIntroduction to the C Language
A Structured Programming Approach Using C2
2-1 Background
C is a structured programming language. It isC is a structured programming language. It is
considered a high-level language because it allows theconsidered a high-level language because it allows the
programmer to concentrate on the problem at handprogrammer to concentrate on the problem at hand
and not worry about the machine that the programand not worry about the machine that the program
will be using. That is another reason why it is used bywill be using. That is another reason why it is used by
software developers whose applications have to run onsoftware developers whose applications have to run on
many different hardware platforms.many different hardware platforms.
A Structured Programming Approach Using C3
2-2 C Programs
It's time to write your first C program.It's time to write your first C program.
Structure of a C Program
Your First C Program
Comments
The Greeting Program
Topics discussed in this section:Topics discussed in this section:
A Structured Programming Approach Using C4
FIGURE 2-2 Structure of a C Program
A Structured Programming Approach Using C5
FIGURE 2-3 The Greeting Program
A Structured Programming Approach Using C6
PROGRAM 2-1 The Greeting Program
A Structured Programming Approach Using C7
FIGURE 2-4 Examples of Block Comments
A Structured Programming Approach Using C8
FIGURE 2-5 Examples of Line Comments
#include <stdio.h>
// program prints a number of type int
int main() {
int number = 4;
printf (“Number is %d”, number);
return 0;
}
Output: Number is 4
A Structured Programming Approach Using C9
Errors
Compilation
Compiler generally gives the line number at
which the error is present.
Run time
C programs are sequential making the
debugging easier.
A Structured Programming Approach Using C10
FIGURE 2-6 Nested Block Comments Are Invalid
A Structured Programming Approach Using C11
2-3 Identifiers
One feature present in all computer languages is theOne feature present in all computer languages is the
identifier. Identifiers allow us to name data and otheridentifier. Identifiers allow us to name data and other
objects in the program. Each identified object in theobjects in the program. Each identified object in the
computer is stored at a unique address.computer is stored at a unique address.
A Structured Programming Approach Using C12
Table 2-1 Rules for Identifiers
A Structured Programming Approach Using C13
An identifier must start with a letter or underscore:
it may not have a space or a hyphen.
NoteNote
C is a case-sensitive language.
A Structured Programming Approach Using C14
Table 2-2 Examples of Valid and Invalid Names
A Structured Programming Approach Using C15
2-4 Types
A type defines a set of values and a set of operationsA type defines a set of values and a set of operations
that can be applied on those values.that can be applied on those values.
Void Type
Integral Type
Floating-Point Types
Topics discussed in this section:Topics discussed in this section:
A Structured Programming Approach Using C16
FIGURE 2-7 Data Types
A Structured Programming Approach Using C17
FIGURE 2-8 Character Types
A Structured Programming Approach Using C18
FIGURE 2-9 Integer Types
A Structured Programming Approach Using C19
sizeof (short) ≤ sizeof (int) ≤ sizeof (long) ≤ sizeof (long long)
NoteNote
A Structured Programming Approach Using C20
Table 2-3 Typical Integer Sizes and Values for Signed Integers
A Structured Programming Approach Using C21
FIGURE 2-10 Floating-point Types
A Structured Programming Approach Using C22
sizeof (float) ≤ sizeof (double) ≤ sizeof (long double)
NoteNote
A Structured Programming Approach Using C23
Table 2-4 Type Summary
A Structured Programming Approach Using C24
2-5 Variables
Variables are named memory locations that have a type,Variables are named memory locations that have a type,
such as integer or character, which is inherited fromsuch as integer or character, which is inherited from
their type. The type determines the values that a variabletheir type. The type determines the values that a variable
may contain and the operations that may be used withmay contain and the operations that may be used with
its values.its values.
Variable Declaration
Variable Initialization
Topics discussed in this section:Topics discussed in this section:
A Structured Programming Approach Using C25
FIGURE 2-11 Variables
A Structured Programming Approach Using C26
Table 2-5 Examples of Variable Declarations and Definitions
A Structured Programming Approach Using C27
FIGURE 2-12 Variable Initialization
‘B’
A Structured Programming Approach Using C28
When a variable is defined, it is not initialized.
We must initialize any variable requiring
prescribed data when the function starts.
NoteNote
A Structured Programming Approach Using C29
PROGRAM 2-2 Print Sum of Three Numbers
A Structured Programming Approach Using C30
PROGRAM 2-2 Print Sum of Three Numbers (continued)
A Structured Programming Approach Using C31
PROGRAM 2-2 Print Sum of Three Numbers (continued)
A Structured Programming Approach Using C32
2-6 Constants
Constants are data values that cannot be changedConstants are data values that cannot be changed
during the execution of a program. Like variables,during the execution of a program. Like variables,
constants have a type. In this section, we discussconstants have a type. In this section, we discuss
Boolean, character, integer, real, complex, and stringBoolean, character, integer, real, complex, and string
constants.constants.
Constant Representation
Coding Constants
Topics discussed in this section:Topics discussed in this section:
A Structured Programming Approach Using C33
A character constant is enclosed in single quotes.
NoteNote
A Structured Programming Approach Using C34
Table 2-6 Symbolic Names for Control Characters
A Structured Programming Approach Using C35
Table 2-7 Examples of Integer Constants
A Structured Programming Approach Using C36
Table 2-8 Examples of Real Constants
A Structured Programming Approach Using C37
FIGURE 2-13 Some Strings
A Structured Programming Approach Using C38
FIGURE 2-14 Null Characters and Null Strings
A Structured Programming Approach Using C39
Use single quotes for character constants.
Use double quotes for string constants.
NoteNote
A Structured Programming Approach Using C40
PROGRAM 2-3 Memory Constants
A Structured Programming Approach Using C41
PROGRAM 2-3 Memory Constants (continued)
A Structured Programming Approach Using C42
Some more Arithmetic Operators
C Course, Programming club, Fall 200843
Prefix Increment : ++a
example:
o int a=5;
o b=++a; // value of b=6; a=6;
Postfix Increment: a++
example
o int a=5;
o b=a++; //value of b=5; a=6;
Contd…
C Course, Programming club, Fall 200844
Modulus (remainder): %
example:
o 12%5 = 2;
Assignment by addition: +=
example:
o int a=4;
o a+=1; //(means a=a+1) value of a becomes 5
Can use -, /, *, % also
Contd…
C Course, Programming club, Fall 200845
Comparision Operators: <, > , <=, >= , !=, ==, !,
&&, || .
example:
o int a=4, b=5;
o a<b returns a true(non zero number) value.
Bitwise Operators: <<, >>, ~, &, | ,^ .
example
o int a=8;
o a= a>>1; // value of a becomes 4
Operator Precedence
C Course, Programming club, Fall 200846
Meaning of a + b * c ?
is it a+(b*c) or (a+b)*c ?
All operators have precedence over each other
*, / have more precedence over +, - .
If both *, / are used, associativity comes into picture. (more on
this later)
example :
o 5+4*3 = 5+12= 17.
Precedence Table
C Course, Programming club, Fall 200847
Highest on top
++ -- (Postfix)
++ -- (Prefix)
* / %
+ -
<< >>
< >
&
|
&&
||
Input / Output
C Course, Programming club, Fall 200848
 printf (); //used to print to console(screen)
 scanf (); //used to take an input from console(user).
 example: printf(“%c”, ’a’); scanf(“%d”, &a);
 More format specifiers
%c     The character format specifier.
%d     The integer format specifier.
%i     The integer format specifier (same as %d).
%f     The floating-point format specifier.
%o     The unsigned octal format specifier.
%s     The string format specifier.
%u     The unsigned integer format specifier.
%x     The unsigned hexadecimal format specifier.
%%     Outputs a percent sign.
Some more geek stuff
C Course, Programming club, Fall 200849
& in scanf.
It is used to access the address of the variable used.
example:
o scanf(%d,&a);
o we are reading into the address of a.
Data Hierarchy.
example:
int value can be assigned to float not vice-versa.
Type casting.
Home Work
C Course, Programming club, Fall 200850
Meaning of
Syntax
Semantics of a programming language
Find the Output:
value=value++ + value++;
Value=++value + ++value;
value=value++ + ++value;
End of Today’s Lecture
C Course, Programming club, Fall 200851
Doubts && Queries?
THANK YOU
C Course, Programming club, Fall 200852

More Related Content

What's hot

C language
C languageC language
C language
Rohit Singh
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
amol_chavan
 
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
C notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit orderC notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit order
C notes by m v b reddy(gitam)imp notes all units notes 5 unit orderMalikireddy Bramhananda Reddy
 
Notes of c programming 1st unit BCA I SEM
Notes of c programming  1st unit BCA I SEMNotes of c programming  1st unit BCA I SEM
Notes of c programming 1st unit BCA I SEM
Mansi Tyagi
 
Programming in c notes
Programming in c notesProgramming in c notes
Programming in c notes
Sudharasanam Babu
 
best notes in c language
best notes in c languagebest notes in c language
best notes in c language
India
 
C basics
C   basicsC   basics
C Programming
C ProgrammingC Programming
C Programming
Rumman Ansari
 
C language industrial training report
C language industrial training reportC language industrial training report
C language industrial training report
Raushan Pandey
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
JAYA
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)indrasir
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
Rokonuzzaman Rony
 
C Language
C LanguageC Language
C Language
Aakash Singh
 
COM1407: Introduction to C Programming
COM1407: Introduction to C Programming COM1407: Introduction to C Programming
COM1407: Introduction to C Programming
Hemantha Kulathilake
 
Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
nTier Custom Solutions
 
C language
C languageC language
C language
Yasir Khan
 
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTTC programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
Batra Centre
 

What's hot (20)

C language
C languageC language
C language
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
 
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
C notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit orderC notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit order
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
 
Notes of c programming 1st unit BCA I SEM
Notes of c programming  1st unit BCA I SEMNotes of c programming  1st unit BCA I SEM
Notes of c programming 1st unit BCA I SEM
 
Programming in c notes
Programming in c notesProgramming in c notes
Programming in c notes
 
best notes in c language
best notes in c languagebest notes in c language
best notes in c language
 
Unit4
Unit4Unit4
Unit4
 
C basics
C   basicsC   basics
C basics
 
C Programming
C ProgrammingC Programming
C Programming
 
C programming
C programmingC programming
C programming
 
C language industrial training report
C language industrial training reportC language industrial training report
C language industrial training report
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
 
C Language
C LanguageC Language
C Language
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
COM1407: Introduction to C Programming
COM1407: Introduction to C Programming COM1407: Introduction to C Programming
COM1407: Introduction to C Programming
 
Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
 
C language
C languageC language
C language
 
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTTC programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
 

Similar to Intro

Chap-02-01.ppt
Chap-02-01.pptChap-02-01.ppt
Chap-02-01.ppt
ssuser5ad1571
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
Vamshi171
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
ShraddhaPattnaik
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
UdhayaKumar175069
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
hamsa72
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
ssusere6f5a11
 
Chap 02-1
Chap 02-1Chap 02-1
Chap 02-1
Navjot Singh
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to cHattori Sidek
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
Vikram Nandini
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
AbdulSacur2
 
CODING-DAY-2-INTRODUCTION TO C PROGRAMMING.ppt
CODING-DAY-2-INTRODUCTION TO C PROGRAMMING.pptCODING-DAY-2-INTRODUCTION TO C PROGRAMMING.ppt
CODING-DAY-2-INTRODUCTION TO C PROGRAMMING.ppt
adamjackson818417
 
UNIT 1 NOTES.docx
UNIT 1 NOTES.docxUNIT 1 NOTES.docx
UNIT 1 NOTES.docx
Revathiparamanathan
 
Features and Fundamentals of C Language for Beginners
Features and Fundamentals of C Language for BeginnersFeatures and Fundamentals of C Language for Beginners
Features and Fundamentals of C Language for Beginners
Chandrakant Divate
 
c++ referesher 1.pdf
c++ referesher 1.pdfc++ referesher 1.pdf
c++ referesher 1.pdf
AnkurSingh656748
 
Unit 1.1 - Introduction to C.pptx
Unit 1.1 - Introduction to C.pptxUnit 1.1 - Introduction to C.pptx
Unit 1.1 - Introduction to C.pptx
NandhaGopal Subramani
 
Programming with c language practical manual
Programming with c language practical manualProgramming with c language practical manual
Programming with c language practical manual
Anil Bishnoi
 
Chapter 02-02.pptx
Chapter 02-02.pptxChapter 02-02.pptx
Chapter 02-02.pptx
ssuser5ad1571
 
C prog ppt
C prog pptC prog ppt
C prog ppt
xinoe
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptx
RohitRaj744272
 

Similar to Intro (20)

Chap-02-01.ppt
Chap-02-01.pptChap-02-01.ppt
Chap-02-01.ppt
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
 
C programming-1.pptx
C programming-1.pptxC programming-1.pptx
C programming-1.pptx
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
 
Chap 02-1
Chap 02-1Chap 02-1
Chap 02-1
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
 
CODING-DAY-2-INTRODUCTION TO C PROGRAMMING.ppt
CODING-DAY-2-INTRODUCTION TO C PROGRAMMING.pptCODING-DAY-2-INTRODUCTION TO C PROGRAMMING.ppt
CODING-DAY-2-INTRODUCTION TO C PROGRAMMING.ppt
 
UNIT 1 NOTES.docx
UNIT 1 NOTES.docxUNIT 1 NOTES.docx
UNIT 1 NOTES.docx
 
Features and Fundamentals of C Language for Beginners
Features and Fundamentals of C Language for BeginnersFeatures and Fundamentals of C Language for Beginners
Features and Fundamentals of C Language for Beginners
 
c++ referesher 1.pdf
c++ referesher 1.pdfc++ referesher 1.pdf
c++ referesher 1.pdf
 
Unit 1.1 - Introduction to C.pptx
Unit 1.1 - Introduction to C.pptxUnit 1.1 - Introduction to C.pptx
Unit 1.1 - Introduction to C.pptx
 
Programming with c language practical manual
Programming with c language practical manualProgramming with c language practical manual
Programming with c language practical manual
 
Chapter 02-02.pptx
Chapter 02-02.pptxChapter 02-02.pptx
Chapter 02-02.pptx
 
C prog ppt
C prog pptC prog ppt
C prog ppt
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptx
 

More from CGC Technical campus,Mohali

Gender Issues CS.pptx
Gender Issues CS.pptxGender Issues CS.pptx
Gender Issues CS.pptx
CGC Technical campus,Mohali
 
Intellectual Property Rights.pptx
Intellectual Property Rights.pptxIntellectual Property Rights.pptx
Intellectual Property Rights.pptx
CGC Technical campus,Mohali
 
Cyber Safety ppt.pptx
Cyber Safety ppt.pptxCyber Safety ppt.pptx
Cyber Safety ppt.pptx
CGC Technical campus,Mohali
 
Python Modules .pptx
Python Modules .pptxPython Modules .pptx
Python Modules .pptx
CGC Technical campus,Mohali
 
Dynamic allocation
Dynamic allocationDynamic allocation
Dynamic allocation
CGC Technical campus,Mohali
 
Arrays in c
Arrays in cArrays in c
Control statments in c
Control statments in cControl statments in c
Control statments in c
CGC Technical campus,Mohali
 
Operators in c by anupam
Operators in c by anupamOperators in c by anupam
Operators in c by anupam
CGC Technical campus,Mohali
 
Datatypes in c
Datatypes in cDatatypes in c
Fundamentals of-computer
Fundamentals of-computerFundamentals of-computer
Fundamentals of-computer
CGC Technical campus,Mohali
 
Searching
Searching Searching
File handling-c
File handling-cFile handling-c
Structure in C language
Structure in C languageStructure in C language
Structure in C language
CGC Technical campus,Mohali
 
Function in c program
Function in c programFunction in c program
Function in c program
CGC Technical campus,Mohali
 
Function in c
Function in cFunction in c
string in C
string in Cstring in C
C arrays
C arraysC arrays
Data processing and Report writing in Research(Section E)
Data processing and Report writing in Research(Section E)Data processing and Report writing in Research(Section E)
Data processing and Report writing in Research(Section E)
CGC Technical campus,Mohali
 
data analysis and report wring in research (Section d)
data analysis and report wring  in research (Section d)data analysis and report wring  in research (Section d)
data analysis and report wring in research (Section d)
CGC Technical campus,Mohali
 
Section C(Analytical and descriptive surveys... )
Section C(Analytical and descriptive surveys... )Section C(Analytical and descriptive surveys... )
Section C(Analytical and descriptive surveys... )
CGC Technical campus,Mohali
 

More from CGC Technical campus,Mohali (20)

Gender Issues CS.pptx
Gender Issues CS.pptxGender Issues CS.pptx
Gender Issues CS.pptx
 
Intellectual Property Rights.pptx
Intellectual Property Rights.pptxIntellectual Property Rights.pptx
Intellectual Property Rights.pptx
 
Cyber Safety ppt.pptx
Cyber Safety ppt.pptxCyber Safety ppt.pptx
Cyber Safety ppt.pptx
 
Python Modules .pptx
Python Modules .pptxPython Modules .pptx
Python Modules .pptx
 
Dynamic allocation
Dynamic allocationDynamic allocation
Dynamic allocation
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Control statments in c
Control statments in cControl statments in c
Control statments in c
 
Operators in c by anupam
Operators in c by anupamOperators in c by anupam
Operators in c by anupam
 
Datatypes in c
Datatypes in cDatatypes in c
Datatypes in c
 
Fundamentals of-computer
Fundamentals of-computerFundamentals of-computer
Fundamentals of-computer
 
Searching
Searching Searching
Searching
 
File handling-c
File handling-cFile handling-c
File handling-c
 
Structure in C language
Structure in C languageStructure in C language
Structure in C language
 
Function in c program
Function in c programFunction in c program
Function in c program
 
Function in c
Function in cFunction in c
Function in c
 
string in C
string in Cstring in C
string in C
 
C arrays
C arraysC arrays
C arrays
 
Data processing and Report writing in Research(Section E)
Data processing and Report writing in Research(Section E)Data processing and Report writing in Research(Section E)
Data processing and Report writing in Research(Section E)
 
data analysis and report wring in research (Section d)
data analysis and report wring  in research (Section d)data analysis and report wring  in research (Section d)
data analysis and report wring in research (Section d)
 
Section C(Analytical and descriptive surveys... )
Section C(Analytical and descriptive surveys... )Section C(Analytical and descriptive surveys... )
Section C(Analytical and descriptive surveys... )
 

Recently uploaded

Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
zwunae
 
An Approach to Detecting Writing Styles Based on Clustering Techniques
An Approach to Detecting Writing Styles Based on Clustering TechniquesAn Approach to Detecting Writing Styles Based on Clustering Techniques
An Approach to Detecting Writing Styles Based on Clustering Techniques
ambekarshweta25
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
dxobcob
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
aqil azizi
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 

Recently uploaded (20)

Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
 
An Approach to Detecting Writing Styles Based on Clustering Techniques
An Approach to Detecting Writing Styles Based on Clustering TechniquesAn Approach to Detecting Writing Styles Based on Clustering Techniques
An Approach to Detecting Writing Styles Based on Clustering Techniques
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 

Intro

  • 1. A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C program. ❏ To introduce the include preprocessor command. ❏ To be able to create good identifiers for objects in a program. ❏ To be able to list, describe, and use the C basic data types. ❏ To be able to create and use variables and constants. ❏ To understand input and output concepts. ❏ To be able to use simple input and output statements. Introduction to the C LanguageIntroduction to the C Language
  • 2. A Structured Programming Approach Using C2 2-1 Background C is a structured programming language. It isC is a structured programming language. It is considered a high-level language because it allows theconsidered a high-level language because it allows the programmer to concentrate on the problem at handprogrammer to concentrate on the problem at hand and not worry about the machine that the programand not worry about the machine that the program will be using. That is another reason why it is used bywill be using. That is another reason why it is used by software developers whose applications have to run onsoftware developers whose applications have to run on many different hardware platforms.many different hardware platforms.
  • 3. A Structured Programming Approach Using C3 2-2 C Programs It's time to write your first C program.It's time to write your first C program. Structure of a C Program Your First C Program Comments The Greeting Program Topics discussed in this section:Topics discussed in this section:
  • 4. A Structured Programming Approach Using C4 FIGURE 2-2 Structure of a C Program
  • 5. A Structured Programming Approach Using C5 FIGURE 2-3 The Greeting Program
  • 6. A Structured Programming Approach Using C6 PROGRAM 2-1 The Greeting Program
  • 7. A Structured Programming Approach Using C7 FIGURE 2-4 Examples of Block Comments
  • 8. A Structured Programming Approach Using C8 FIGURE 2-5 Examples of Line Comments #include <stdio.h> // program prints a number of type int int main() { int number = 4; printf (“Number is %d”, number); return 0; } Output: Number is 4
  • 9. A Structured Programming Approach Using C9 Errors Compilation Compiler generally gives the line number at which the error is present. Run time C programs are sequential making the debugging easier.
  • 10. A Structured Programming Approach Using C10 FIGURE 2-6 Nested Block Comments Are Invalid
  • 11. A Structured Programming Approach Using C11 2-3 Identifiers One feature present in all computer languages is theOne feature present in all computer languages is the identifier. Identifiers allow us to name data and otheridentifier. Identifiers allow us to name data and other objects in the program. Each identified object in theobjects in the program. Each identified object in the computer is stored at a unique address.computer is stored at a unique address.
  • 12. A Structured Programming Approach Using C12 Table 2-1 Rules for Identifiers
  • 13. A Structured Programming Approach Using C13 An identifier must start with a letter or underscore: it may not have a space or a hyphen. NoteNote C is a case-sensitive language.
  • 14. A Structured Programming Approach Using C14 Table 2-2 Examples of Valid and Invalid Names
  • 15. A Structured Programming Approach Using C15 2-4 Types A type defines a set of values and a set of operationsA type defines a set of values and a set of operations that can be applied on those values.that can be applied on those values. Void Type Integral Type Floating-Point Types Topics discussed in this section:Topics discussed in this section:
  • 16. A Structured Programming Approach Using C16 FIGURE 2-7 Data Types
  • 17. A Structured Programming Approach Using C17 FIGURE 2-8 Character Types
  • 18. A Structured Programming Approach Using C18 FIGURE 2-9 Integer Types
  • 19. A Structured Programming Approach Using C19 sizeof (short) ≤ sizeof (int) ≤ sizeof (long) ≤ sizeof (long long) NoteNote
  • 20. A Structured Programming Approach Using C20 Table 2-3 Typical Integer Sizes and Values for Signed Integers
  • 21. A Structured Programming Approach Using C21 FIGURE 2-10 Floating-point Types
  • 22. A Structured Programming Approach Using C22 sizeof (float) ≤ sizeof (double) ≤ sizeof (long double) NoteNote
  • 23. A Structured Programming Approach Using C23 Table 2-4 Type Summary
  • 24. A Structured Programming Approach Using C24 2-5 Variables Variables are named memory locations that have a type,Variables are named memory locations that have a type, such as integer or character, which is inherited fromsuch as integer or character, which is inherited from their type. The type determines the values that a variabletheir type. The type determines the values that a variable may contain and the operations that may be used withmay contain and the operations that may be used with its values.its values. Variable Declaration Variable Initialization Topics discussed in this section:Topics discussed in this section:
  • 25. A Structured Programming Approach Using C25 FIGURE 2-11 Variables
  • 26. A Structured Programming Approach Using C26 Table 2-5 Examples of Variable Declarations and Definitions
  • 27. A Structured Programming Approach Using C27 FIGURE 2-12 Variable Initialization ‘B’
  • 28. A Structured Programming Approach Using C28 When a variable is defined, it is not initialized. We must initialize any variable requiring prescribed data when the function starts. NoteNote
  • 29. A Structured Programming Approach Using C29 PROGRAM 2-2 Print Sum of Three Numbers
  • 30. A Structured Programming Approach Using C30 PROGRAM 2-2 Print Sum of Three Numbers (continued)
  • 31. A Structured Programming Approach Using C31 PROGRAM 2-2 Print Sum of Three Numbers (continued)
  • 32. A Structured Programming Approach Using C32 2-6 Constants Constants are data values that cannot be changedConstants are data values that cannot be changed during the execution of a program. Like variables,during the execution of a program. Like variables, constants have a type. In this section, we discussconstants have a type. In this section, we discuss Boolean, character, integer, real, complex, and stringBoolean, character, integer, real, complex, and string constants.constants. Constant Representation Coding Constants Topics discussed in this section:Topics discussed in this section:
  • 33. A Structured Programming Approach Using C33 A character constant is enclosed in single quotes. NoteNote
  • 34. A Structured Programming Approach Using C34 Table 2-6 Symbolic Names for Control Characters
  • 35. A Structured Programming Approach Using C35 Table 2-7 Examples of Integer Constants
  • 36. A Structured Programming Approach Using C36 Table 2-8 Examples of Real Constants
  • 37. A Structured Programming Approach Using C37 FIGURE 2-13 Some Strings
  • 38. A Structured Programming Approach Using C38 FIGURE 2-14 Null Characters and Null Strings
  • 39. A Structured Programming Approach Using C39 Use single quotes for character constants. Use double quotes for string constants. NoteNote
  • 40. A Structured Programming Approach Using C40 PROGRAM 2-3 Memory Constants
  • 41. A Structured Programming Approach Using C41 PROGRAM 2-3 Memory Constants (continued)
  • 42. A Structured Programming Approach Using C42
  • 43. Some more Arithmetic Operators C Course, Programming club, Fall 200843 Prefix Increment : ++a example: o int a=5; o b=++a; // value of b=6; a=6; Postfix Increment: a++ example o int a=5; o b=a++; //value of b=5; a=6;
  • 44. Contd… C Course, Programming club, Fall 200844 Modulus (remainder): % example: o 12%5 = 2; Assignment by addition: += example: o int a=4; o a+=1; //(means a=a+1) value of a becomes 5 Can use -, /, *, % also
  • 45. Contd… C Course, Programming club, Fall 200845 Comparision Operators: <, > , <=, >= , !=, ==, !, &&, || . example: o int a=4, b=5; o a<b returns a true(non zero number) value. Bitwise Operators: <<, >>, ~, &, | ,^ . example o int a=8; o a= a>>1; // value of a becomes 4
  • 46. Operator Precedence C Course, Programming club, Fall 200846 Meaning of a + b * c ? is it a+(b*c) or (a+b)*c ? All operators have precedence over each other *, / have more precedence over +, - . If both *, / are used, associativity comes into picture. (more on this later) example : o 5+4*3 = 5+12= 17.
  • 47. Precedence Table C Course, Programming club, Fall 200847 Highest on top ++ -- (Postfix) ++ -- (Prefix) * / % + - << >> < > & | && ||
  • 48. Input / Output C Course, Programming club, Fall 200848  printf (); //used to print to console(screen)  scanf (); //used to take an input from console(user).  example: printf(“%c”, ’a’); scanf(“%d”, &a);  More format specifiers %c     The character format specifier. %d     The integer format specifier. %i     The integer format specifier (same as %d). %f     The floating-point format specifier. %o     The unsigned octal format specifier. %s     The string format specifier. %u     The unsigned integer format specifier. %x     The unsigned hexadecimal format specifier. %%     Outputs a percent sign.
  • 49. Some more geek stuff C Course, Programming club, Fall 200849 & in scanf. It is used to access the address of the variable used. example: o scanf(%d,&a); o we are reading into the address of a. Data Hierarchy. example: int value can be assigned to float not vice-versa. Type casting.
  • 50. Home Work C Course, Programming club, Fall 200850 Meaning of Syntax Semantics of a programming language Find the Output: value=value++ + value++; Value=++value + ++value; value=value++ + ++value;
  • 51. End of Today’s Lecture C Course, Programming club, Fall 200851 Doubts && Queries?
  • 52. THANK YOU C Course, Programming club, Fall 200852

Editor's Notes

  1. Developed early 1970’s
  2. wchar_t is a wide character:  The increased datatype size allows for the use of larger coded character sets. Width is compiler specific (not portable).