Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editing the presentation of concepts in 00 and 01 folder. #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions 00_Introduction/introduction.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
[Previous](../README.md) Learn-C
[Next ⏩](../01_Hello_world/hello_world.md) Hello-World

[Next](../01_Hello_world/hello_world.md) Hello-World \
\
\
* [Introduction](./introduction.md#introduction)
* [Requirements](./introduction.md#requirement)
* [Setup](./introduction.md#setup)
* Compiler
* Test Editor
* [Coding Style (Betty)](./introduction.md#coding-style-betty)
* [Keywords](./introduction.md#keywords)
[Previous: ⏪](../README.md) Learn-C

Now ▼


[Introduction](./introduction.md#introduction)
[Requirements](./introduction.md#requirement)
[Setup](./introduction.md#setup)
* Compiler
* Text Editor

[Coding Style (Betty)](./introduction.md#coding-style-betty)
[Keywords](./introduction.md#keywords)

\

# Introduction

C programming language is a procedural and general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972.

The C programming language offers various features and functionalities to the programmers. It includes low-level memory access, simple syntax, and a clean style. It makes the C programming language suitable for system programming like compiler development and operating system development.

C files have the file extension .c\
There are other file extensions in C like the header files, but we would talk about them later.
C files ends with a .c file extension

However, there are other file extensions in C like the header files(.h), but we would talk about them later.

## Requirement

There are two(2) basic requirements to for coding in C:
There are two(2) basic requirements in order to run a C program:

* A text editor to write C code. Examples
* Vim
Expand Down Expand Up @@ -54,7 +57,7 @@ There are 32 keywords in the C programming language.

Keywords are reserved words in the language which has its own meaning to the compiler and cannot be used as a user-defined [identifier](../02_Variables/variables.md#identifiers)

Keywords in C are as follows
The Keywords in C are as follows

|KeyWords |                                                |                                                   |                                                  |
|:-------:|:-------:|:-------:|:-------:|
Expand All @@ -69,11 +72,11 @@ Keywords in C are as follows

You can also checkout my repo showing examples for each keyword [here](TODO:KEYWORD_REPO)

Enough of the talk. In the Next Section, we are going to write some code.
In the Next Section, we are going to write some code.
\
\
\
\
[Previous](../README.md) Learn-C
[Previous](../README.md) Learn-C

[Next](../01_Hello_world/hello_world.md) Hello-World
[Next](../01_Hello_world/hello_world.md) Hello-World
90 changes: 58 additions & 32 deletions 01_Hello_world/hello_world.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
[Previous](../00_introduction/introduction.md) Introduction
[Next: ⏩](../02_Variables/variables.md) VARIABLES

[Next](../02_Variables/variables.md) Variables
[Previous ⏪](../00_introduction/introduction.md) INTRODUCTION

Now ▼

[Hello World ](./hello_world.md#hello-world)

[Comments](./hello_world.md#comments)

* [Hello World](./hello_world.md#hello-world)
* My First Program
* [Comments](./hello_world.md#comments)

# Hello World

Expand All @@ -24,54 +27,68 @@ int main() {
### Syntax Explained:

```
Note: you don't have to understand everything now, it'll all come to you.
Tip💡: It's not necessary to grasp everything immediately; with time, everything will become clear to you.
```

Line 1: `` #include <stdio.h>``.

* stdio.h is an header file. Header files can be used to add functionality to your code, and allow you use other people's code so you don't have to rewrite thesame code
* this line includes the stdio.h file to our code
* checkout [Preprocessor](../08_Preprocessor/)
* `stdio.h` is an header file. The full name of the header file `stdio.h` is "standard input and output header. Header files are used to add functionality to your code, and allow you use other people's code so you don't have to rewrite the same code.
* This line includes the stdio.h file which enables us to display the output of our code.
* For more information on the processes of header files, checkout [Preprocessor](../08_Preprocessor/)

Line 3: ``int main()``
* This is the function Declaration of the main function
* the main function is something that must be in every C program because, this is where the code execution starts.
* The main function is the entry point of every C program. It is the function that calls/activate every other C programs.
* This is where code execution starts.
```
Note: as a function, everything inside the curly braces ``{}`` is executed. More later in [Functions]()
Tip💡: A function is defined and enclosed in curly braces. The code lines are referred to as statements, and the statements within the curly braces ``{}`` are carried out during execution.
```
More later in [Functions](../05_Functions/functions.md)
More of this later in [Functions](../05_Functions/functions.md)

Line 4: this is a comment
Line 4: ``// print hello world``

* This is a comment
* More on comments below.

## Comments
Comments are lines of code that are meant for other humans and hence, ignored by the compiler.
Comments are line(s) of code that are meant for other humans and hence, ignored by the compiler.

Why do we use Comments?
* Comments are used to explain what your code does. Comments improve the readability of code. Comments should be used to explain what your code does and not how.
* Comments can be used to prevent the execution of some parts of the code. But this is not a good practice.
* Comments are used to explain what your code does. It is a convention that comments should be used to explain what your code does and not how.
* Comments can be used to prevent the execution of some parts of the code. But this is arguably not a good practice.

## Importance of comments
* Comments used sparingly improves the readability of code.
* In certain situations where an individual is not acquainted with the programming language, comments provide them with insights into the program's logic.
* In some cases, Comments are used in debugging.

### Types of Comments in C
there are two(2) types of comments in C:
* **Single line comments**: These are comments that start with a double forward slash (//) and extend to the end of the line. Example:
There are two(2) types of comments in C:
* **Single line comments**: These are comments that start with a double forward slash (//) and extend until the end of the line. Example:
```C
//This is a Comment
//This is a single line Comment
```
* **Multiline Comments**: these type of comments start with a slash and asterick and end with a asterick then a slash. It can be extended to a multiple lines. Example:
* **Multiline Comments**: These are enclosed between /* and */. Everything between these delimiters, reardless of line breaks, is considered a comment. It can be extended to a multiple lines. Example:
```C
/* This
is a multiline
comment */
```
Line 5: ``printf()``
* printf() is a function used to output/print text to the screen. In our example it will output "Hello World". it is declared on the ``stdio.h`` file.
* printf() is a function used to output/print text to the standard output (stdout). In our example it will output **Hello World**. The defination of the printf() function is in the ``stdio.h`` file.
```
Note: Every C statement ends with a semicolon ;
Tip💡: Every C statement ends with a semicolon ;
```

Line 6: ``return 0``
* this ends the main() function.
* Returns `0` to the caller of the function. In our case It means a successful compilation of the program.
* This ends the main() function.

And that's it.

One more thing...Betty.
One more thing...Betty. Remember that betty is a coding style checker. This tool is used to enforce a specific set of coding standards and guideline.

[Learn more about Betty](https://github.com/alx-tools/Betty)

if we run this file through the betty linter, it would throw some error, so lets fix that. We can rewrite the code like this:

Expand All @@ -89,18 +106,27 @@ int main()
```

## Compile and Run
Save the Above code in a file ``main.C``
1. Create the program in a file named `main.c`. You might choose any name you prefer, but it's essential to conclude the filename with the `.c ` extension, as is customary for all C programs.
2. In your terminal, type *betty main.c*
This checks your code and will throw out warning if any rules were flaunted or in cases of error.
3. Compile using GCC compiler, use the following command

To compile a C file using GCC compiler, use the following command
```
gcc main.c -o hello
```

To run

``gcc main.c -o hello``
```
./hello
```

And then to run it
Upon Successful compilation, You should see the ouput `Hello World` in your terminal.

``./hello``
markdown
💡 Congratulations on running your first program.

You should see the text "Hello World" in your terminal.

[Previous](../00_introduction/introduction.md) Introduction
[Previous: ⏪](../00_introduction/introduction.md) INTRODUCTION

[Next](../02_Variables/variables.md) Variables
[Next: ⏩](../02_Variables/variables.md) VARIABLES