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

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

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
 
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
 
C programming-1.pptx
C programming-1.pptxC programming-1.pptx
C programming-1.pptx
 
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
 
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
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 

More from CGC Technical campus,Mohali

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

Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 

Recently uploaded (20)

Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 

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