SlideShare a Scribd company logo
1 of 41
Computer Science: A Structured Programming Approach Using C 1
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.
Chapter 2
Introduction to the C Language
Computer Science: A Structured Programming Approach Using C 2
2-1 Background
C is a structured programming language. It is
considered a high-level language because it allows the
programmer to concentrate on the problem at hand
and not worry about the machine that the program
will be using. That is another reason why it is used by
software developers whose applications have to run on
many different hardware platforms.
Computer Science: A Structured Programming Approach Using C 3
2-2 C Programs
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:
Computer Science: A Structured Programming Approach Using C 4
FIGURE 2-2 Structure of a C Program
Computer Science: A Structured Programming Approach Using C 5
FIGURE 2-3 The Greeting Program
Computer Science: A Structured Programming Approach Using C 6
PROGRAM 2-1 The Greeting Program
Computer Science: A Structured Programming Approach Using C 7
FIGURE 2-4 Examples of Block Comments
Computer Science: A Structured Programming Approach Using C 8
FIGURE 2-5 Examples of Line Comments
Computer Science: A Structured Programming Approach Using C 9
FIGURE 2-6 Nested Block Comments Are Invalid
Computer Science: A Structured Programming Approach Using C 10
2-3 Identifiers
One feature present in all computer languages is the
identifier. Identifiers allow us to name data and other
objects in the program. Each identified object in the
computer is stored at a unique address.
Computer Science: A Structured Programming Approach Using C 11
Table 2-1 Rules for Identifiers
Computer Science: A Structured Programming Approach Using C 12
An identifier must start with a letter or underscore:
it may not have a space or a hyphen.
Note
Computer Science: A Structured Programming Approach Using C 13
C is a case-sensitive language.
Note
Computer Science: A Structured Programming Approach Using C 14
Table 2-2 Examples of Valid and Invalid Names
Computer Science: A Structured Programming Approach Using C 15
2-4 Types
A type defines a set of values and a set of operations
that can be applied on those values.
Void Type
Integral Type
Floating-Point Types
Topics discussed in this section:
Computer Science: A Structured Programming Approach Using C 16
FIGURE 2-7 Data Types
Computer Science: A Structured Programming Approach Using C 17
FIGURE 2-8 Character Types
Computer Science: A Structured Programming Approach Using C 18
FIGURE 2-9 Integer Types
Computer Science: A Structured Programming Approach Using C 19
sizeof (short) ≤ sizeof (int) ≤ sizeof (long) ≤ sizeof (long long)
Note
Computer Science: A Structured Programming Approach Using C 20
Table 2-3 Typical Integer Sizes and Values for Signed Integers
Computer Science: A Structured Programming Approach Using C 21
FIGURE 2-10 Floating-point Types
Computer Science: A Structured Programming Approach Using C 22
sizeof (float) ≤ sizeof (double) ≤ sizeof (long double)
Note
Computer Science: A Structured Programming Approach Using C 23
Table 2-4 Type Summary
Computer Science: A Structured Programming Approach Using C 24
2-5 Variables
Variables are named memory locations that have a type,
such as integer or character, which is inherited from
their type. The type determines the values that a variable
may contain and the operations that may be used with
its values.
Variable Declaration
Variable Initialization
Topics discussed in this section:
Computer Science: A Structured Programming Approach Using C 25
FIGURE 2-11 Variables
Computer Science: A Structured Programming Approach Using C 26
Table 2-5 Examples of Variable Declarations and Definitions
Computer Science: A Structured Programming Approach Using C 27
FIGURE 2-12 Variable Initialization
‘B’
Computer Science: A Structured Programming Approach Using C 28
When a variable is defined, it is not initialized.
We must initialize any variable requiring
prescribed data when the function starts.
Note
Computer Science: A Structured Programming Approach Using C 29
PROGRAM 2-2 Print Sum of Three Numbers
Computer Science: A Structured Programming Approach Using C 30
PROGRAM 2-2 Print Sum of Three Numbers (continued)
Computer Science: A Structured Programming Approach Using C 31
PROGRAM 2-2 Print Sum of Three Numbers (continued)
Computer Science: A Structured Programming Approach Using C 32
2-6 Constants
Constants are data values that cannot be changed
during the execution of a program. Like variables,
constants have a type. In this section, we discuss
Boolean, character, integer, real, complex, and string
constants.
Constant Representation
Coding Constants
Topics discussed in this section:
Computer Science: A Structured Programming Approach Using C 33
A character constant is enclosed in single quotes.
Note
Computer Science: A Structured Programming Approach Using C 34
Table 2-6 Symbolic Names for Control Characters
Computer Science: A Structured Programming Approach Using C 35
Table 2-7 Examples of Integer Constants
Computer Science: A Structured Programming Approach Using C 36
Table 2-8 Examples of Real Constants
Computer Science: A Structured Programming Approach Using C 37
FIGURE 2-13 Some Strings
Computer Science: A Structured Programming Approach Using C 38
FIGURE 2-14 Null Characters and Null Strings
Computer Science: A Structured Programming Approach Using C 39
Use single quotes for character constants.
Use double quotes for string constants.
Note
Computer Science: A Structured Programming Approach Using C 40
PROGRAM 2-3 Memory Constants
Computer Science: A Structured Programming Approach Using C 41
PROGRAM 2-3 Memory Constants (continued)

More Related Content

Similar to Chap-02-01.ppt

Chap-14-1 (1).ppt
Chap-14-1 (1).pptChap-14-1 (1).ppt
Chap-14-1 (1).pptOmPrakasDas
 
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
 
Computer programming all chapters
Computer programming all chaptersComputer programming all chapters
Computer programming all chaptersIbrahim Elewah
 
CHAPTER-2.ppt
CHAPTER-2.pptCHAPTER-2.ppt
CHAPTER-2.pptTekle12
 
Lecture 3.2.4 C pointer to Structure.pptx
Lecture 3.2.4 C pointer to Structure.pptxLecture 3.2.4 C pointer to Structure.pptx
Lecture 3.2.4 C pointer to Structure.pptxravi2692kumar
 
ch01_an overview of computers and programming languages
ch01_an overview of computers and programming languagesch01_an overview of computers and programming languages
ch01_an overview of computers and programming languagesLiemLe21
 
Unit-2_Getting Started With ‘C’ Language (3).pptx
Unit-2_Getting Started With ‘C’ Language (3).pptxUnit-2_Getting Started With ‘C’ Language (3).pptx
Unit-2_Getting Started With ‘C’ Language (3).pptxSanketShah544615
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to cHattori Sidek
 
C programming notes.pdf
C programming notes.pdfC programming notes.pdf
C programming notes.pdfAdiseshaK
 
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 SEMMansi Tyagi
 

Similar to Chap-02-01.ppt (20)

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
 
Chap-14-1 (1).ppt
Chap-14-1 (1).pptChap-14-1 (1).ppt
Chap-14-1 (1).ppt
 
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
 
C AND DATASTRUCTURES PREPARED BY M V B REDDY
C AND DATASTRUCTURES PREPARED BY M V B REDDYC AND DATASTRUCTURES PREPARED BY M V B REDDY
C AND DATASTRUCTURES PREPARED BY M V B REDDY
 
Chap 11-1
Chap 11-1Chap 11-1
Chap 11-1
 
Computer programming all chapters
Computer programming all chaptersComputer programming all chapters
Computer programming all chapters
 
CHAPTER-2.ppt
CHAPTER-2.pptCHAPTER-2.ppt
CHAPTER-2.ppt
 
Session1 c1
Session1 c1Session1 c1
Session1 c1
 
trial
trialtrial
trial
 
Lecture 3.2.4 C pointer to Structure.pptx
Lecture 3.2.4 C pointer to Structure.pptxLecture 3.2.4 C pointer to Structure.pptx
Lecture 3.2.4 C pointer to Structure.pptx
 
ch01_an overview of computers and programming languages
ch01_an overview of computers and programming languagesch01_an overview of computers and programming languages
ch01_an overview of computers and programming languages
 
Chap-03-1.ppt
Chap-03-1.pptChap-03-1.ppt
Chap-03-1.ppt
 
Unit-2_Getting Started With ‘C’ Language (3).pptx
Unit-2_Getting Started With ‘C’ Language (3).pptxUnit-2_Getting Started With ‘C’ Language (3).pptx
Unit-2_Getting Started With ‘C’ Language (3).pptx
 
Programming C Part 01
Programming C Part 01 Programming C Part 01
Programming C Part 01
 
C LANGUAGE NOTES
C LANGUAGE NOTESC LANGUAGE NOTES
C LANGUAGE NOTES
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
 
C programming notes.pdf
C programming notes.pdfC programming notes.pdf
C programming notes.pdf
 
C programming notes
C programming notesC programming notes
C programming notes
 
Cs8251 faq1
Cs8251 faq1Cs8251 faq1
Cs8251 faq1
 
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
 

Recently uploaded

BEST ✨ Call Girls In Shangri-La Eros New Delhi✔️ 9871031762 ✔️ Escorts Servic...
BEST ✨ Call Girls In Shangri-La Eros New Delhi✔️ 9871031762 ✔️ Escorts Servic...BEST ✨ Call Girls In Shangri-La Eros New Delhi✔️ 9871031762 ✔️ Escorts Servic...
BEST ✨ Call Girls In Shangri-La Eros New Delhi✔️ 9871031762 ✔️ Escorts Servic...noida100girls
 
Call Girls In Hauz Khas Delhi 9654467111 Independent Escorts Service
Call Girls In Hauz Khas Delhi 9654467111 Independent Escorts ServiceCall Girls In Hauz Khas Delhi 9654467111 Independent Escorts Service
Call Girls In Hauz Khas Delhi 9654467111 Independent Escorts ServiceSapana Sha
 
Russian ​❤️ Call Girls In The Grand New Delhi Near By Vasant Kunj ✔️ 9871031...
Russian ​❤️ Call Girls In The Grand New Delhi Near By Vasant Kunj  ✔️ 9871031...Russian ​❤️ Call Girls In The Grand New Delhi Near By Vasant Kunj  ✔️ 9871031...
Russian ​❤️ Call Girls In The Grand New Delhi Near By Vasant Kunj ✔️ 9871031...noida100girls
 
BEST ✨ Call Girls In Park Plaza Faridabad ✔️ 9871031762 ✔️ Escorts Service In...
BEST ✨ Call Girls In Park Plaza Faridabad ✔️ 9871031762 ✔️ Escorts Service In...BEST ✨ Call Girls In Park Plaza Faridabad ✔️ 9871031762 ✔️ Escorts Service In...
BEST ✨ Call Girls In Park Plaza Faridabad ✔️ 9871031762 ✔️ Escorts Service In...noida100girls
 
Best VIP Call Girls Noida Sector 62 Call Me: 8448380779
Best VIP Call Girls Noida Sector 62 Call Me: 8448380779Best VIP Call Girls Noida Sector 62 Call Me: 8448380779
Best VIP Call Girls Noida Sector 62 Call Me: 8448380779Delhi Call girls
 
Call girls in Jaipur 9358660226 escort service in Jaipur
Call girls in Jaipur 9358660226 escort service in JaipurCall girls in Jaipur 9358660226 escort service in Jaipur
Call girls in Jaipur 9358660226 escort service in Jaipurrahul222jai
 
BEST ✨ Call Girls In MG Road Gurgaon ✔️ 9871031762 ✔️ Escorts Service In De...
BEST ✨ Call Girls In  MG Road Gurgaon  ✔️ 9871031762 ✔️ Escorts Service In De...BEST ✨ Call Girls In  MG Road Gurgaon  ✔️ 9871031762 ✔️ Escorts Service In De...
BEST ✨ Call Girls In MG Road Gurgaon ✔️ 9871031762 ✔️ Escorts Service In De...noida100girls
 
BEST ✨Call Girls In Park Plaza Gurugram ✔️9773824855✔️ Escorts Service In Del...
BEST ✨Call Girls In Park Plaza Gurugram ✔️9773824855✔️ Escorts Service In Del...BEST ✨Call Girls In Park Plaza Gurugram ✔️9773824855✔️ Escorts Service In Del...
BEST ✨Call Girls In Park Plaza Gurugram ✔️9773824855✔️ Escorts Service In Del...noida100girls
 
BEST ✨ Call Girls In Noida Electronic City ✔️ 9871031762 ✔️ Escorts Service I...
BEST ✨ Call Girls In Noida Electronic City ✔️ 9871031762 ✔️ Escorts Service I...BEST ✨ Call Girls In Noida Electronic City ✔️ 9871031762 ✔️ Escorts Service I...
BEST ✨ Call Girls In Noida Electronic City ✔️ 9871031762 ✔️ Escorts Service I...noida100girls
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual serviceanilsa9823
 
Best VIP Call Girls Noida Sector 49 Call Me: 8448380779
Best VIP Call Girls Noida Sector 49 Call Me: 8448380779Best VIP Call Girls Noida Sector 49 Call Me: 8448380779
Best VIP Call Girls Noida Sector 49 Call Me: 8448380779Delhi Call girls
 
BEST ✨ Call Girls In Greater Noida ✔️ 9871031762 ✔️ Escorts Service In Delhi ...
BEST ✨ Call Girls In Greater Noida ✔️ 9871031762 ✔️ Escorts Service In Delhi ...BEST ✨ Call Girls In Greater Noida ✔️ 9871031762 ✔️ Escorts Service In Delhi ...
BEST ✨ Call Girls In Greater Noida ✔️ 9871031762 ✔️ Escorts Service In Delhi ...noida100girls
 
Russian ​❤️ Call Girls In Malviya Nagar ✔️9773824855✔️ Escorts Service In Del...
Russian ​❤️ Call Girls In Malviya Nagar ✔️9773824855✔️ Escorts Service In Del...Russian ​❤️ Call Girls In Malviya Nagar ✔️9773824855✔️ Escorts Service In Del...
Russian ​❤️ Call Girls In Malviya Nagar ✔️9773824855✔️ Escorts Service In Del...noida100girls
 
Best VIP Call Girls Noida Sector 63 Call Me: 8448380779
Best VIP Call Girls Noida Sector 63 Call Me: 8448380779Best VIP Call Girls Noida Sector 63 Call Me: 8448380779
Best VIP Call Girls Noida Sector 63 Call Me: 8448380779Delhi Call girls
 
Russian ​❤️ Call Girls In Radisson Blu MBD Hotel, Noida ✔️ 9871031762 ✔️ Esco...
Russian ​❤️ Call Girls In Radisson Blu MBD Hotel, Noida ✔️ 9871031762 ✔️ Esco...Russian ​❤️ Call Girls In Radisson Blu MBD Hotel, Noida ✔️ 9871031762 ✔️ Esco...
Russian ​❤️ Call Girls In Radisson Blu MBD Hotel, Noida ✔️ 9871031762 ✔️ Esco...noida100girls
 
CALL ON ➥8923113531 🔝Call Girls Vikas Nagar Lucknow best Female service 🧥
CALL ON ➥8923113531 🔝Call Girls Vikas Nagar Lucknow best Female service  🧥CALL ON ➥8923113531 🔝Call Girls Vikas Nagar Lucknow best Female service  🧥
CALL ON ➥8923113531 🔝Call Girls Vikas Nagar Lucknow best Female service 🧥anilsa9823
 
Maya❤️Call girls in Mohali ☎️7435815124☎️ Call Girl service in Mohali☎️ Mohal...
Maya❤️Call girls in Mohali ☎️7435815124☎️ Call Girl service in Mohali☎️ Mohal...Maya❤️Call girls in Mohali ☎️7435815124☎️ Call Girl service in Mohali☎️ Mohal...
Maya❤️Call girls in Mohali ☎️7435815124☎️ Call Girl service in Mohali☎️ Mohal...Sheetaleventcompany
 
Cheap Rate ➥8448380779 ▻Call Girls In Sector 57 Gurgaon
Cheap Rate ➥8448380779 ▻Call Girls In Sector 57 GurgaonCheap Rate ➥8448380779 ▻Call Girls In Sector 57 Gurgaon
Cheap Rate ➥8448380779 ▻Call Girls In Sector 57 GurgaonDelhi Call girls
 

Recently uploaded (18)

BEST ✨ Call Girls In Shangri-La Eros New Delhi✔️ 9871031762 ✔️ Escorts Servic...
BEST ✨ Call Girls In Shangri-La Eros New Delhi✔️ 9871031762 ✔️ Escorts Servic...BEST ✨ Call Girls In Shangri-La Eros New Delhi✔️ 9871031762 ✔️ Escorts Servic...
BEST ✨ Call Girls In Shangri-La Eros New Delhi✔️ 9871031762 ✔️ Escorts Servic...
 
Call Girls In Hauz Khas Delhi 9654467111 Independent Escorts Service
Call Girls In Hauz Khas Delhi 9654467111 Independent Escorts ServiceCall Girls In Hauz Khas Delhi 9654467111 Independent Escorts Service
Call Girls In Hauz Khas Delhi 9654467111 Independent Escorts Service
 
Russian ​❤️ Call Girls In The Grand New Delhi Near By Vasant Kunj ✔️ 9871031...
Russian ​❤️ Call Girls In The Grand New Delhi Near By Vasant Kunj  ✔️ 9871031...Russian ​❤️ Call Girls In The Grand New Delhi Near By Vasant Kunj  ✔️ 9871031...
Russian ​❤️ Call Girls In The Grand New Delhi Near By Vasant Kunj ✔️ 9871031...
 
BEST ✨ Call Girls In Park Plaza Faridabad ✔️ 9871031762 ✔️ Escorts Service In...
BEST ✨ Call Girls In Park Plaza Faridabad ✔️ 9871031762 ✔️ Escorts Service In...BEST ✨ Call Girls In Park Plaza Faridabad ✔️ 9871031762 ✔️ Escorts Service In...
BEST ✨ Call Girls In Park Plaza Faridabad ✔️ 9871031762 ✔️ Escorts Service In...
 
Best VIP Call Girls Noida Sector 62 Call Me: 8448380779
Best VIP Call Girls Noida Sector 62 Call Me: 8448380779Best VIP Call Girls Noida Sector 62 Call Me: 8448380779
Best VIP Call Girls Noida Sector 62 Call Me: 8448380779
 
Call girls in Jaipur 9358660226 escort service in Jaipur
Call girls in Jaipur 9358660226 escort service in JaipurCall girls in Jaipur 9358660226 escort service in Jaipur
Call girls in Jaipur 9358660226 escort service in Jaipur
 
BEST ✨ Call Girls In MG Road Gurgaon ✔️ 9871031762 ✔️ Escorts Service In De...
BEST ✨ Call Girls In  MG Road Gurgaon  ✔️ 9871031762 ✔️ Escorts Service In De...BEST ✨ Call Girls In  MG Road Gurgaon  ✔️ 9871031762 ✔️ Escorts Service In De...
BEST ✨ Call Girls In MG Road Gurgaon ✔️ 9871031762 ✔️ Escorts Service In De...
 
BEST ✨Call Girls In Park Plaza Gurugram ✔️9773824855✔️ Escorts Service In Del...
BEST ✨Call Girls In Park Plaza Gurugram ✔️9773824855✔️ Escorts Service In Del...BEST ✨Call Girls In Park Plaza Gurugram ✔️9773824855✔️ Escorts Service In Del...
BEST ✨Call Girls In Park Plaza Gurugram ✔️9773824855✔️ Escorts Service In Del...
 
BEST ✨ Call Girls In Noida Electronic City ✔️ 9871031762 ✔️ Escorts Service I...
BEST ✨ Call Girls In Noida Electronic City ✔️ 9871031762 ✔️ Escorts Service I...BEST ✨ Call Girls In Noida Electronic City ✔️ 9871031762 ✔️ Escorts Service I...
BEST ✨ Call Girls In Noida Electronic City ✔️ 9871031762 ✔️ Escorts Service I...
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service
 
Best VIP Call Girls Noida Sector 49 Call Me: 8448380779
Best VIP Call Girls Noida Sector 49 Call Me: 8448380779Best VIP Call Girls Noida Sector 49 Call Me: 8448380779
Best VIP Call Girls Noida Sector 49 Call Me: 8448380779
 
BEST ✨ Call Girls In Greater Noida ✔️ 9871031762 ✔️ Escorts Service In Delhi ...
BEST ✨ Call Girls In Greater Noida ✔️ 9871031762 ✔️ Escorts Service In Delhi ...BEST ✨ Call Girls In Greater Noida ✔️ 9871031762 ✔️ Escorts Service In Delhi ...
BEST ✨ Call Girls In Greater Noida ✔️ 9871031762 ✔️ Escorts Service In Delhi ...
 
Russian ​❤️ Call Girls In Malviya Nagar ✔️9773824855✔️ Escorts Service In Del...
Russian ​❤️ Call Girls In Malviya Nagar ✔️9773824855✔️ Escorts Service In Del...Russian ​❤️ Call Girls In Malviya Nagar ✔️9773824855✔️ Escorts Service In Del...
Russian ​❤️ Call Girls In Malviya Nagar ✔️9773824855✔️ Escorts Service In Del...
 
Best VIP Call Girls Noida Sector 63 Call Me: 8448380779
Best VIP Call Girls Noida Sector 63 Call Me: 8448380779Best VIP Call Girls Noida Sector 63 Call Me: 8448380779
Best VIP Call Girls Noida Sector 63 Call Me: 8448380779
 
Russian ​❤️ Call Girls In Radisson Blu MBD Hotel, Noida ✔️ 9871031762 ✔️ Esco...
Russian ​❤️ Call Girls In Radisson Blu MBD Hotel, Noida ✔️ 9871031762 ✔️ Esco...Russian ​❤️ Call Girls In Radisson Blu MBD Hotel, Noida ✔️ 9871031762 ✔️ Esco...
Russian ​❤️ Call Girls In Radisson Blu MBD Hotel, Noida ✔️ 9871031762 ✔️ Esco...
 
CALL ON ➥8923113531 🔝Call Girls Vikas Nagar Lucknow best Female service 🧥
CALL ON ➥8923113531 🔝Call Girls Vikas Nagar Lucknow best Female service  🧥CALL ON ➥8923113531 🔝Call Girls Vikas Nagar Lucknow best Female service  🧥
CALL ON ➥8923113531 🔝Call Girls Vikas Nagar Lucknow best Female service 🧥
 
Maya❤️Call girls in Mohali ☎️7435815124☎️ Call Girl service in Mohali☎️ Mohal...
Maya❤️Call girls in Mohali ☎️7435815124☎️ Call Girl service in Mohali☎️ Mohal...Maya❤️Call girls in Mohali ☎️7435815124☎️ Call Girl service in Mohali☎️ Mohal...
Maya❤️Call girls in Mohali ☎️7435815124☎️ Call Girl service in Mohali☎️ Mohal...
 
Cheap Rate ➥8448380779 ▻Call Girls In Sector 57 Gurgaon
Cheap Rate ➥8448380779 ▻Call Girls In Sector 57 GurgaonCheap Rate ➥8448380779 ▻Call Girls In Sector 57 Gurgaon
Cheap Rate ➥8448380779 ▻Call Girls In Sector 57 Gurgaon
 

Chap-02-01.ppt

  • 1. Computer Science: A Structured Programming Approach Using C 1 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. Chapter 2 Introduction to the C Language
  • 2. Computer Science: A Structured Programming Approach Using C 2 2-1 Background C is a structured programming language. It is considered a high-level language because it allows the programmer to concentrate on the problem at hand and not worry about the machine that the program will be using. That is another reason why it is used by software developers whose applications have to run on many different hardware platforms.
  • 3. Computer Science: A Structured Programming Approach Using C 3 2-2 C Programs 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:
  • 4. Computer Science: A Structured Programming Approach Using C 4 FIGURE 2-2 Structure of a C Program
  • 5. Computer Science: A Structured Programming Approach Using C 5 FIGURE 2-3 The Greeting Program
  • 6. Computer Science: A Structured Programming Approach Using C 6 PROGRAM 2-1 The Greeting Program
  • 7. Computer Science: A Structured Programming Approach Using C 7 FIGURE 2-4 Examples of Block Comments
  • 8. Computer Science: A Structured Programming Approach Using C 8 FIGURE 2-5 Examples of Line Comments
  • 9. Computer Science: A Structured Programming Approach Using C 9 FIGURE 2-6 Nested Block Comments Are Invalid
  • 10. Computer Science: A Structured Programming Approach Using C 10 2-3 Identifiers One feature present in all computer languages is the identifier. Identifiers allow us to name data and other objects in the program. Each identified object in the computer is stored at a unique address.
  • 11. Computer Science: A Structured Programming Approach Using C 11 Table 2-1 Rules for Identifiers
  • 12. Computer Science: A Structured Programming Approach Using C 12 An identifier must start with a letter or underscore: it may not have a space or a hyphen. Note
  • 13. Computer Science: A Structured Programming Approach Using C 13 C is a case-sensitive language. Note
  • 14. Computer Science: A Structured Programming Approach Using C 14 Table 2-2 Examples of Valid and Invalid Names
  • 15. Computer Science: A Structured Programming Approach Using C 15 2-4 Types A type defines a set of values and a set of operations that can be applied on those values. Void Type Integral Type Floating-Point Types Topics discussed in this section:
  • 16. Computer Science: A Structured Programming Approach Using C 16 FIGURE 2-7 Data Types
  • 17. Computer Science: A Structured Programming Approach Using C 17 FIGURE 2-8 Character Types
  • 18. Computer Science: A Structured Programming Approach Using C 18 FIGURE 2-9 Integer Types
  • 19. Computer Science: A Structured Programming Approach Using C 19 sizeof (short) ≤ sizeof (int) ≤ sizeof (long) ≤ sizeof (long long) Note
  • 20. Computer Science: A Structured Programming Approach Using C 20 Table 2-3 Typical Integer Sizes and Values for Signed Integers
  • 21. Computer Science: A Structured Programming Approach Using C 21 FIGURE 2-10 Floating-point Types
  • 22. Computer Science: A Structured Programming Approach Using C 22 sizeof (float) ≤ sizeof (double) ≤ sizeof (long double) Note
  • 23. Computer Science: A Structured Programming Approach Using C 23 Table 2-4 Type Summary
  • 24. Computer Science: A Structured Programming Approach Using C 24 2-5 Variables Variables are named memory locations that have a type, such as integer or character, which is inherited from their type. The type determines the values that a variable may contain and the operations that may be used with its values. Variable Declaration Variable Initialization Topics discussed in this section:
  • 25. Computer Science: A Structured Programming Approach Using C 25 FIGURE 2-11 Variables
  • 26. Computer Science: A Structured Programming Approach Using C 26 Table 2-5 Examples of Variable Declarations and Definitions
  • 27. Computer Science: A Structured Programming Approach Using C 27 FIGURE 2-12 Variable Initialization ‘B’
  • 28. Computer Science: A Structured Programming Approach Using C 28 When a variable is defined, it is not initialized. We must initialize any variable requiring prescribed data when the function starts. Note
  • 29. Computer Science: A Structured Programming Approach Using C 29 PROGRAM 2-2 Print Sum of Three Numbers
  • 30. Computer Science: A Structured Programming Approach Using C 30 PROGRAM 2-2 Print Sum of Three Numbers (continued)
  • 31. Computer Science: A Structured Programming Approach Using C 31 PROGRAM 2-2 Print Sum of Three Numbers (continued)
  • 32. Computer Science: A Structured Programming Approach Using C 32 2-6 Constants Constants are data values that cannot be changed during the execution of a program. Like variables, constants have a type. In this section, we discuss Boolean, character, integer, real, complex, and string constants. Constant Representation Coding Constants Topics discussed in this section:
  • 33. Computer Science: A Structured Programming Approach Using C 33 A character constant is enclosed in single quotes. Note
  • 34. Computer Science: A Structured Programming Approach Using C 34 Table 2-6 Symbolic Names for Control Characters
  • 35. Computer Science: A Structured Programming Approach Using C 35 Table 2-7 Examples of Integer Constants
  • 36. Computer Science: A Structured Programming Approach Using C 36 Table 2-8 Examples of Real Constants
  • 37. Computer Science: A Structured Programming Approach Using C 37 FIGURE 2-13 Some Strings
  • 38. Computer Science: A Structured Programming Approach Using C 38 FIGURE 2-14 Null Characters and Null Strings
  • 39. Computer Science: A Structured Programming Approach Using C 39 Use single quotes for character constants. Use double quotes for string constants. Note
  • 40. Computer Science: A Structured Programming Approach Using C 40 PROGRAM 2-3 Memory Constants
  • 41. Computer Science: A Structured Programming Approach Using C 41 PROGRAM 2-3 Memory Constants (continued)

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