Translate

Featured post

Blog Introduction: What we do... ?

  Hello everyone,  Welcome to my startup blog that talks about computer science stuff and its related topics. We will try to explain and fig...

26 Nov 2023

Introduction to C programming language #1




Hello everybody to our first article that talks about C programming language.

We will start from very basics concepts in this language and will try to figure out some general programming concepts that work for all languages, not only C!

From zero to hero -1 (step before hero ) because the hero step is not my responsibility, It's yours!


-----------------------------------------------------------------------------------------------------------------------------

C programming language:




First, let us know a bit more theoretical information about C;

According to Wikipedia, It is developed by Dennis Ritchie at Bell Labs between 1972 and 1973. C was designed to provide a flexible and efficient alternative to assembly language programming. 

In C, all executable code is contained within subroutines (functions), this means that your code is written under a function as we will see later.

C used and still used in a lot of fields in the technology world such as: Developing compilers (Clang C, MinGW), Operating Systems (Microsoft’s Windows kernel, Linux kernel, Apple’s OS X kernel (iOS), Microsoft Windows utilities, Symbian (Nokia), Android, Windows Phone Kernel),

Browser Engines (Google Chromium browser), Gaming (Tic-Tac-Toe, Chess), Animation and Embedded Systems (Coffee Maker, Microwave), it is even can be used in Developing another programming language such as C++, Java, Python (so that Called as the mother of all programming languages), and many others.

C is a middle-level language, Now you ask WTF that's means, just chill!


The programming languages are divided into 2 types and sometimes 3 types:

High Level language :

A high-level programming language is one that's more user-friendly, languages are considered high-level because they are closer to human languages and further from machine languages.


Low Level Language :

A low-level programming language is a one that is more machine specific, the only language which can be understood by the computer, have the ability to access the memory directly unlike high-level languages.


The code written in system programs using a high-level language like PHP, Python, etc., is not directly understood by the CPU and this is the reason why it is compiled into a low-level language. 

C is often called a middle-level computer language as it is a combination of the elements of high-level languages with the functionalism of assembly language.


So for now, low-level languages refer to machine code (0, 1) and assembly, anything else is a high-level language but we call C as a middle-level because it's between high-level  (because we understand it) and low-level (has some functionalism of assembly).

We call the languages as low-level, middle-level and high-level depending on how close they are to what the computer's actually understanding and it just understand the machine code(0, 1).


After we knew the importance of C and why we should to pay attention for learning it, let's learn it '-'

To write a program in C, you have to get one compiler from these: Visual Studio, Visual Studio Code, Code Blocks, Atom and others... Pick one of them and download it or search on YouTube how to download it . 

>> If you can't download such platforms on your computer, simply you can write your code on online compilers such OnlineGDB, Programiz C compiler, OneCompiler and much more if you just searched...

Maybe now you are asking what's the meaning of compiler and what it does? Simply, The Compiler is where you write your code in, It's used to translate the C code you write to a language the computer understand (machine code 0&1). There are many types of compilers that differ according to their uses. 


-----------------------------------------------------------------------------------------------------------------------------

Writing C code:

The basic structure for C; Every C program consists of a libraries (we include them and these libraries contain a lot of functions we use them in our program) and functions we write our code under it as we mentioned above.

Now, we have two concepts: A big container named library(1) and this library consists of a number of functions someone else wrote, it's not different to the functions I write to my program. And the function(2) from its name, it's just a number of lines of instructions we write to do something specific as we will see later.

Now we write a simple program to print what we tell:

We start with including a library that has a the print function, without including it we can't print:
#include <stdio.h>

Then we write the main function, from its name it is the main function that our program starts with, the compilation process searches for it to start its work (the translation) so we write our code under it:

int main(){ // our code here}

*** We will learn the structure of function later, Just consider this for now ***


Using "printf" function that's defined at the library "stdio.h" we can print what we want:

printf("Hello friend, \n");

*** "\n" used for new line, we tell the compiler to write the new sentence in a new line ***


We can add more sentences by calling the function once again:

printf("Welcome to my world \n");

*** If you noticed we put our sentence inside a quotation mark because it's string ***


Finally, we have to know that's our code is done successfully, so we write the returned code at the end. This tells the compiler if our code is done successfully, return the program with this code:

return 0;

* The 0 can be 1, 2 or any number, doesn't matter but in the programmers world it's common to be 0 *


Let's put all together:

    #include <stdio.h>
    int main(){

        printf("Hello friend, \n");
        printf("Welcome to my world 7");

        return 0;
    }

The output will be:
	Hello friend,
	Welcome to my world 7

-----------------------------------------------------------------------------------------------------------------------------

Conclusion:

For now we knew some information about C programming language and learned about its basic structure. Next article will explore more concepts such as variables, format codes and maybe more.

Make sure to follow me if you liked what I do and don't be shy to tell me about any improvements you'd like to see here '-'

See you soon, friend <3

No comments:

Post a Comment