Introduction to C Programming
1. Steps in Development of a C Program
Developing a C program involves several stages. The programmer first writes the source code and then converts it into an executable program that the computer can run.
1 Enter, Edit and Save
Write the C source code using a text editor or an IDE and save the file with the .c extension.
Examples: Notepad, Notepad++, Sublime Text, VS Code, Code::Blocks.
2 Translate the Source Code
The source code must be translated into a form that the computer can understand.
A compiler translates C source code into machine/object code.
3 Linking
The linker combines the object code with required library routines and other necessary code.
For example, functions such as
printf() are provided through standard libraries.
4 Test and Debug
Run the program and check whether it produces the expected output.
Errors are identified and corrected during debugging.
5 Create Executable Program
After successful compilation and linking, an executable program is created.
The executable can then be run by the operating system.
2. Program Development Process
.c file
3. IDE – Integrated Development Environment
IDE stands for Integrated Development Environment.
An IDE is software that provides the facilities required to develop programs and manage software projects. It usually combines a source-code editor, compiler/build tools, debugger, and other development features in one application.
Features of an IDE
- Writing and editing source code
- Compiling programs
- Building and running programs
- Finding and fixing errors
- Debugging programs
- Managing project files
4. Online Compilers
We can also practice programming using online compilers. An online compiler allows us to write, compile, and execute programs through a web browser without installing a compiler locally.
Online compilers are especially useful for beginners because they allow students to quickly test small programs.
5. Popular IDEs / Editors for C Programming
| IDE / Editor | Description |
|---|---|
| Turbo C | A classic environment historically used for learning C. |
| Code::Blocks | A free, open-source IDE commonly used for C and C++. |
| Dev-C++ | A lightweight development environment commonly used for C and C++ programming. |
| VS Code | A lightweight, extensible source-code editor that can be configured for C/C++ development. |
6. Keyboard Shortcuts in Code::Blocks
| Action | Keyboard Shortcut |
|---|---|
| Zoom In | Ctrl + + |
| Zoom Out | Ctrl + – |
| Copy | Ctrl + C |
| Cut | Ctrl + X |
| Paste | Ctrl + V |
| Build and Run | F9 |
7. Program 1 – Display a Welcome Message
This program demonstrates how to display a simple message on the screen.
#include <stdio.h>
int main()
{
printf("Welcome to C Programming");
return 0;
}
Output
Welcome to C Programming
-
#include <stdio.h>includes the standard input/output library. -
printf()displays text on the screen. -
return 0;indicates successful completion of the program.
8. Program 2 – Display the Value of a Number
This program demonstrates how to declare an integer variable,
assign a value to it, and display the value using
printf().
#include <stdio.h>
int main()
{
int x;
x = 10;
printf("Value of x is %d", x);
return 0;
}
Output
Value of x is 10
-
int x;declares an integer variable namedx. -
x = 10;assigns the value 10 tox. -
%dis a format specifier used to display an integer value. -
The value of
xis supplied toprintf()after the format string.
9. Program 3 – Add Two Numbers
This program demonstrates how to store two numbers in variables, add them, and display their sum.
#include <stdio.h>
int main()
{
int a, b;
a = 15;
b = 25;
int sum = a + b;
printf("Sum of the numbers is %d", sum);
return 0;
}
Output
Sum of the numbers is 40
int a, b;declares two integer variables.a = 15;stores 15 ina.b = 25;stores 25 inb.-
int sum = a + b;adds the two values and stores the result insum. - Since 15 + 25 = 40, the output is 40.
10. Important C Programming Concepts Used
| Concept | Example | Purpose |
|---|---|---|
| Header file | #include <stdio.h> |
Provides standard input/output functions. |
| Variable declaration | int x; |
Declares an integer variable. |
| Assignment | x = 10; |
Stores a value in a variable. |
| Arithmetic operator | a + b |
Adds two values. |
| Output function | printf() |
Displays output on the screen. |
| Format specifier | %d |
Used to display an integer. |
11. Practice Questions
A. Multiple Choice Questions
- Integrated Development Environment
- Internet Development Editor
- Integrated Data Editor
- Internal Development Engine
- .cpp
- .java
- .c
- .exe
- input()
- printf()
- display()
- show()
- %c
- %f
- %d
- %s
B. Short Answer Questions
C. Programming Practice
12. Debugging Activity
Find and correct the errors in the following program:
#include <stdio.h>
int main()
{
int a, b
a = 10;
b = 20;
printf("Sum = %d", a + b)
return 0;
}
;.
13. Quick Revision
Write Code → Compile → Link → Debug → Build Executable → Run
main() function. The printf() function
is commonly used to display output, and %d is used
with printf() to display integer values.