[C language ] Background (Chapter 1)


So, the first chapter in Stephen Prata’s book “C Primer Plus”. Since there are no exercises in it (only one, theoretical), I will give a small summary of the chapter for the purpose of familiarization:

The advent of the C language

1972 at Bell Labs by Dennis Ritchie.

Reasons for the popularity of the C language

  • Design features
    – top-down planning
    – structured programming
    – modular design
  • Efficiency: compact and fast (only assembler is faster)
  • Portability

Disadvantages of the C programming language

the possibility of software errors that are difficult to track down and the complexity of the code to understand.

C language standards

  • K&R C or Classic C (classic C)
  • First ANSI/ISO standard
  • C99 standard
  • C11 standard

The Seven Steps of C Programming

  1. definition of program objectives
  2. program design
  3. writing code
  4. compilation
  5. running the program for execution
  6. program testing and debugging
  7. maintenance and modification of the program

Commenting code in C

– in order not to get cumbersome, poorly functioning and difficult to understand programs.

Programming Mechanics

  • .c source code file → compilation → object code file
  • object file+libraries+startup code → link → .exe file

Problem: Disappears from the screen immediately after the program terminates
Solution: getchar(); getchar();

The exercise

You have just been hired by MacroMuscle, Inc. Company
enters the European market and wishes to have at its disposal a program
which converts inches to centimeters (1 inch is 2.54 cm). Company
wants the program to prompt the user for a value
in inches. Your task is to determine the objectives of the program and
develop a draft program (stages 1 and 2 of the programming process).

Answer:

The purpose of the program: the conversion of units of measurement. The program needs to receive from the user numerical values ​​​​of length in inches, which will be re-read using a mathematical formula in centimeters; after which the user will be shown the new length value in centimeters.

Program design

Interface: to begin with, the program needs to display information on the user’s screen about what this program does; then ask the user to enter the numeric value in inches they wish to convert to centimeters. Having received data from the user and shortchanged them, the program displays the result to the user.

Organization of the program: (given that this chapter does not say anything about variables and how the code is structured, this point is simplified at this stage):

  • opening text: Welcome to inches-to-cm calculator! Please enter value in inches
  • value request: <user enters value n>
  • value recalculation: <value is recalculated according to the formula (n*2.54)>
  • output: Result: n inches is … centimetres

I will be glad to see your comments!


This entry was posted in C language (en). Bookmark the permalink.

Leave a Reply

🇬🇧 Attention! Comments with URLs/email are not allowed.
🇷🇺 Комментарии со ссылками/email удаляются автоматически.