What is C? 💻
C is a programming language developed in 1972 by Dennis Ritchie. It is considered one of the most powerful languages and is used to create operating systems (e.g. Linux), drivers, games, embedded systems and high-performance applications. 🚀
Why study C? 🔥
High performance: allows you to write fast code.
Flexibility: is used in different areas, from embedded systems to server solutions.
Memory control: allows you to manage memory directly through pointers.
Basics for other languages: knowledge of C will help you master C++, Java and other languages.
How to install C? 💻
To work with C, you will need:
✅ Compiler. Can be used GCC (Linux, macOS) or MSVC (Windows).
✅ Code editor. Recommended Visual Studio Code or CLion.
How to check if the C compiler is installed? 🛠
Open the terminal and enter:
gcc --versionIf GCC is installed, its version will appear.
C Syntax Basics 📚
1. Variables 📦
In C, you must specify the type of variable.
Example of declaring variables:
#include <stdio.h>
int main() {
char name[] = "Alice"; // Line
int age = 25; // Integer
float pi = 3.14; // Floating point number
printf("Name: %s, Age: %d, Pi: %.2f\n", name, age, pi);
return 0;
}2. Data output 📤
To display information, use printf().
Example:
#include <stdio.h>
int main() {
printf("Hello world!\n");
return 0;
}3. Conditional operators (if...else) 🧐
Allow the program to make decisions.
Example:
#include <stdio.h>
int main() {
int age = 20;
if (age >= 18) {
printf("You're an adult!\n");
} else {
printf("You're still a child.\n");
}
return 0;
}4. Loops (for, while) 🔄
Loops allow you to repeat actions.
Example:
#include <stdio.h>
int main() {
for (int i = 1; i <= 5; i++) {
printf("%d\n", i);
}
return 0;
}5. Functions 📐
Functions help to structure the code.
Example:
#include <stdio.h>
int square(int x) {
return x * x;
}
int main() {
printf("Square of 5: %d\n", square(5));
return 0;
}Simple projects in C 💡
1. Random number generator 🎲
The program generates a random number from 1 to 100.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
srand(time(0)); // Initialization of the random number generator
int number = rand() % 100 + 1;
printf("Random number: %d\n", number);
return 0;
}2. Multiplication table 📊
The program displays a multiplication table from 1 to 10.
#include <stdio.h>
int main() {
for (int i = 1; i <= 10; i++) {
for (int j = 1; j <= 10; j++) {
printf("%d\t", i * j);
}
printf("\n");
}
return 0;
}3. Counting the number of characters in a string 🔢
The program counts the characters in the string.
#include <stdio.h>
#include <string.h>
int main() {
char text[] = "Hello, C!";
printf("Number of characters: %lu\n", strlen(text));
return 0;
}4. Checking the number for evenness 🔍
The program determines whether the number is even.
#include <stdio.h>
int main() {
int number = 42;
if (number % 2 == 0) {
printf("%d - even number\n", number);
} else {
printf("%d - odd number\n", number);
}
return 0;
}5. Calculating the factorial of a number 🎯
This code calculates the factorial of a given number.
#include <stdio.h>
int factorial(int n) {
int result = 1;
for (int i = 1; i <= n; i++) {
result *= i;
}
return result;
}
int main() {
printf("Factorial 5: %d\n", factorial(5));
return 0;
}Conclusion 🎉
C is a powerful programming language that is easy to learn. We have analyzed its basics: variables, input/output, conditions, loops and functions. Now you can write your first programs! 🚀
The more you practice, the better your code becomes. Experiment, try new tasks and master programming! Good luck learning C! 😊
