42 Piscine/42 Piscine: Preparation Day 1

# Basics of C Programming

Welcome to the first day of your preparation for the 42 Piscine selection pool! Explore the core concepts of C programming in our comprehensive guide. Whether you're a beginner or looking to refresh your skills, this article offers a curated collection of simple C programs with detailed, step-by-step explanations and valuable resources. Dive into the world of variables, data types, syntax, and more as you embark on your journey to master one of the most influential programming languages globally. Begin your C programming adventure today! You have the option to watch tutorials on YouTube or read articles on C fundamentals. By creating basic programs, you'll build a strong understanding of variables, data types, and fundamental syntax. These straightforward C programs cover key topics such as variables, data types, input/output, arithmetic operations, and conditional statements, laying a solid foundation for your C programming journey.

## Guide

C is a popular and powerful programming language. Here are some basic concepts and syntax to get you started:
### Hello, World!

To begin, let's create a simple "Hello, World!" program. Here's the code:

```
   #include <stdio.h>

   int main() {
       printf("Hello, World!\n");
       return 0;
   }

```

* **`#include <stdio.h>`** This line includes the standard input/output library.
* **`int main()`** Every C program starts with a `main` function. It's the entry point for your program.
* **`printf()`** This function is used to print text to the console.

### Variables and Data Types

C supports various data types such as `int`, `float`, `char`, etc. You can declare variables like this:

```
   int age = 25;
   float temperature = 98.6;
   char grade = 'A';

```

### Operators

C has a range of operators for performing arithmetic, comparison, and logical operations. For example:

```
   int x = 5;
   int y = 3;
   int sum = x + y;
   int product = x * y;

```

### Control Structures

C provides control structures like `if`, `for`, and `while` for decision-making and looping. For instance:

```
   if (x > y) {
       printf("x is greater than y\n");
   }

   for (int i = 0; i < 5; i++) {
       printf("%d\n", i);
   }

```

### Functions

You can define your own functions to organize your code. Here's an example:

```
   int add(int a, int b) {
       return a + b;
   }

```

You can call this function as `int result = add(3, 4);`.

### Arrays

C supports arrays for storing collections of data. For example:

```
   int numbers[5] = {1, 2, 3, 4, 5};

```

### Pointers

Pointers allow you to work with memory addresses. They are a powerful feature in C, but they require careful handling.

```
   int number = 42;
   int* pointer = &number; // pointer stores the address of 'number'

```

### Comments

You can add comments to your code for documentation. Single-line comments start with `//`, and multi-line comments are enclosed in `/\* ... \*/`.

```
   // This is a single-line comment

   /*
   This is a
   multi-line comment
   */

```

This provides a concise summary of each section related to the topic. To delve deeper into a specific area, simply click on the section titles, and they will direct you to comprehensive articles for further exploration.

## Resources

Below are valuable resources for mastering the fundamentals of C programming. These materials cater to diverse learning preferences, spanning interactive tutorials, educational books, and online courses. You have the flexibility to select the resources that align most closely with your personal preferences and learning tempo.
* Learn C.org's C Programming Tutorial A beginner-friendly interactive tutorial. The site offers interactive lessons with hands-on coding exercises.
* Cprogramming.com Provides tutorials, examples, and a forum for C programmers.
* C Programming Absolute Beginner's Guide by Perry and Miller A great choice for those new to programming.
* C Programming for the Absolute Beginner, First & Second Edition by Vine Focuses on fundamentals for beginners.
* edX - Introduction to C Offers free courses on C programming.
* Udemy - C Programming for Beginners Provides video courses for various skill levels.
* C Programming - Tutorials Point Offers comprehensive C programming tutorials.
* C Standard (C11) Draft The official C standard documentation.
* HackerRank Offers a 10-day C programming tutorial with coding challenges.
* LeetCode Provides coding challenges in C to test and improve your skills.
* Stack Overflow - C Tag A great place to ask questions and learn from experienced programmers.
* Reddit - r/learnprogramming A supportive community for beginners.

## Practice Programs

* Hello World
* Variables and Data Types
* Basic Arithmetic
* User Input