Compilation and Execution

in C

Introduction

Once you have written the program, you need to type it and instruct the machine to execute it.

You need an Editor to type the C program, and a Compiler to convert it into machine language instructions.

Compiler vendors provide Integrated Development Environments (IDEs) with both an Editor and Compiler.

IDEs and Setup

IDEs are available for various operating systems and microprocessors.

Details on choosing and setting up the right IDE can be found in Appendix A.

Make sure to have the right IDE installed before proceeding.

Compilation Steps

1. Write your C program using an Editor.

2. Compile the program using a Compiler to generate machine code.

3. Execute the machine code.

Receiving Input

Programs should be general enough to accept user input.

Use the `scanf()` function to receive values from the keyboard.

Always use the `&` (Address of) operator with `scanf()`.

Code Example 1


/* Calculation of simple interest */
/* Author: gekay Date: 25/06/2016 */
#include <stdio.h>
int main() {
int p, n;
float r, si;
printf("Enter values of p, n, r: ");
scanf("%d %d %f", &p, &n, &r);
si = p * n * r / 100;
printf("%f\n", si);
return 0;
}
    

Code Example 2


/* Just for fun. Author: Bozo */
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
printf("Now I am letting you in on a secret...\n");
printf("You have just entered the number %d\n", num);
return 0;
}
    

Summary

  • Constants and variables
  • Keywords
  • Rules for constants and variables
  • We should not use a keyword as a variable name
  • Comments can be single line or multi-line
  • Input/output with `scanf()` and `printf()`

Questions and Answers

Open the floor for questions.