C Programming F-WPS Office
C Programming F-WPS Office
Table of Contents
1. Introduction
4. Data Types
5. Operators
6. Control Structures
7. Functions
8. Compiling and Running a C Program
9. Conclusion
---
Introduction
C is a powerful and efficient programming language widely used for system programming,
embedded systems, and software development. Developed in the early 1970s, C is known for its
performance and control over system resources. This guide is designed for beginners to
develop an understanding of the basic building blocks of C programming.
---
Use Cases: Operating systems, embedded systems, and application software often rely on C for
its efficiency and low-level memory manipulation.
Structure of a C Program
Example:
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
---
Variables
Variables are memory locations that store data during the execution of a program. In C, you
must declare the type of a variable when you define it.
Key Points:
Naming Conventions: Variable names should be descriptive and start with a letter or underscore.
Avoid reserved keywords.
Constants
Constants represent values that cannot change once defined. They provide clarity and prevent
accidental modifications.
Examples:
Using #define:
#define PI 3.14159
---
Data Types
int a = 10;
struct Person {
char name[50];
int age;
};
void: Indicates that a function does not return a value or that a pointer does not point to any type.
---
Operators
Arithmetic Operators: +, -, *, /, %
int sum = 5 + 3;
if (a > b) { /* ... */ }
int x = 10;
x += 5; // Same as x = x + 5
x++; // Increment by 1
---
Control Structures
Control structures allow for decision making and repetitive execution in programs.
Conditional Statements
if-else:
} else {
switch-case:
int day = 3;
switch (day) {
case 1:
printf("Monday\n");
break;
case 2:
printf("Tuesday\n");
break;
// ...
default:
printf("Other day\n");
break;
Loops
for Loop:
while Loop:
int j = 0;
while (j < 5) {
j++;
do-while Loop:
int k = 0;
do {
k++;
---
Functions
Functions are blocks of code that perform a specific task. They help make your code modular
and reusable.
Defining a Function
#include <stdio.h>
// Function prototype
int main() {
return 0;
// Function definition
return a + b;
Benefits
---
1. Write Your Code: Save your code with a .c extension (e.g., program.c).
On Linux/macOS:
./program
On Windows:
program.exe
Popular IDEs for C include Code::Blocks, Visual Studio, and CLion. These environments often
provide tools for writing, compiling, and debugging code with user-friendly interfaces.
---
Conclusion
Data Types: Types define the kind of data variables can store.
Operators and Control Structures: Tools to manipulate and control program flow.
---
Further Resources