Introduction to C programming.

Introduction to C programming.

Prepare to Conquer the Code Seas with C!!!

What is C?

C is an imperative procedural programming language. It was created in the 1970s at Bell Labs. With C, we can write programs, which are sets of instructions for the computer. These instructions can tell the computer to do all sorts of things, like maths, playing games, or even helping us solve big problems.

Brief History of C programming language.

The C programming language was created by Dennis Ritchie. It was designed to assist in the development of operating systems for minicomputers. The UNIX operating system developed by Dennis Ritchie and Ken Thompson required portable software to function. During this period, they developed the C programming language. As the language evolved, Ken Thompson worked on its preprocessor as they partnered on the journey.

Why you should consider learning C.

Learning C should be part of your to-do list in the present as well as in the future. These are the reasons you should consider learning C.

  • Many programming languages are powered by C - Python, Java, Ruby, JS,

  • It is portable and efficient - Can be run on other platforms.

  • It allows you to access many aspects of the computer - low-level programming.

  • The syntax of this language is used in most programming languages.

  • Easy to interface with other programming languages.

  • Easy to debug - it is procedural and has a structure of programming.

  • Has open source code and libraries.

  • C Can be implemented on multiple platforms - Linux, macOS, Windows, Android, gaming consoles, iOS, Embedded systems, etc.

  • Because embedded programming is lightweight, it is efficient in microcontrollers.

  • It is fast - it only needs to be compiled.

NB: Consider using C as your first programming language for learning to code. This is because it has concepts and syntax used in many programming languages.

Just like the Captain's best compass, You can later choose your preferred navigational instruments(other programming languages).

If you comprehend most C concepts, you will easily understand other programming languages and concepts.

C components and features.

  1. Libraries - These are inbuilt and prebuilt functions in C. They can be used by calling them using a header file e.g. #include <unistd.h>

  2. Operators - Arithmetic operators, assignment operators, decrement and increment operators, relational operators, logical operators, and bitwise operators.

  3. Variables - local variables, global variables, static variables, automatic variables, and external variables.

  4. Input and output - scanf, printf, format specifiers, and ASCII values.

  5. Data Types - primitive/primary(Floating-point, integer, double, character.), User Defined Data Types/Derived Types(Structures, arrays, pointers, unions, functions), enum, and void.

  6. Functions and program structure - function prototypes.

  7. Arguments and expressions - An expression is a formula that uses operators to link variables, constants, and other elements to calculate a value. It can include functions, variables, arrays, and constants.

    In C, arguments are variables that are used to pass specific values.

  8. File descriptors and UNIX interfaces - File descriptors are integers that represent open file descriptors or I/O resources. They interact with files, sockets, pipes, and other input/output devices.

  9. Control flow structures and statements. - If Statements, Switch Statements, Conditional Operator Statements, and Goto Statement Loop Statements.

  10. Algorithms and data structures: Arrays, Linked Lists, Stack, Queue, Binary Trees, Binary Search Tree, Heap, Hashing, Graphs.

  11. Compilation process: Pre-processing, compilation, assembly, and linking.

    Preprocessing in C - this involves reading the code and removing unnecessary code and comments from the code. It also adds headers to the code before sending it to the compiler.

    Compiling in C is a series of steps conducted by the compiler to translate the C file into assembler code.

    Assembler in C - this is a tool and process that converts machine language to object code.

    Linking in C - this is where multiple libraries and files are combined. It can be static or dynamic linking. This process creates a .exe file. For execution.

C program syntax:

  1. #include statements (preprocessor directives) - also external files or codes.

  2. Reserved words : (e.g., int, double, return, main, include, etc.)

  3. Variables - stores values for the program.

  4. Builtin functions (library functions) (printf, strings, etc).

  5. {} (start and end of functions). - Code directives and instructions.

  6. Main function -the starting point of program execution.

  7. Comments : (// single line, /* .... */ multiple line

The Process of Compiling in C.

This is the process of converting our C code into a program.

  1. Write our code in C. - use a text editor or code editor.

    Let's name our file maths.c

  2. Debug our code and remove errors.

  3. Use a compiler to execute our code.

    Process:

    1. The compiler preprocesses the code using the CPP tool.

    2. The compiler compiles the code into assembly code. - translating high-level code into machine code(low-level code).

      This process generates a file with a .s extension: a math.s file.

    3. The assembler converts assembly code to machine language. Creates a .o or .obj file extension.

      It converts our code to an a.o file

    4. The code is now linked to other modules it needs to run.

      The file is now converted to execute and another file is generated: math.exe file.

      NB: For Windows, it is converted to the .exe file. For Linux, no specific file but an executable file.

  4. Execute the math.exe file in Windows. For Linux and macOS, just execute the file.

C compilers.

I would like to point out that these recommendations are based on my experiences and are not influenced by any bias:

You can find out what suits your needs and installation preferences:

  1. Codeblocks - Windows, Linux.

  2. VS code - Windows uses MinGW (Minimalist GNU for Windows). MacOS users use Visual Studio for OS X.

  3. CLion - macOS.

  4. Netbeans - Windows Linux.

  5. GCC (GNU Compiler Collection) - Linux.

Online compilers:

  1. Code studio C Compiler - https://www.codingninjas.com/studio/online-compiler/online-c-compiler

  2. OnlineGDB Compiler - https://www.onlinegdb.com/

  3. Programiz Compiler - https://www.programiz.com/c-programming/online-compiler/

What is ANSI-C UNIX?

ANSI C, also known as C89 or C Standard, is a standardized version of the C programming language defined by the American National Standards Institute (ANSI). ANSI C specifies the language's syntax, semantics, and libraries, ensuring portability and compatibility across different systems. Regarding its relationship with UNIX, the C programming language played a significant role in the development of the UNIX operating system. In the early 1970s, UNIX was rewritten in C, replacing an earlier assembly language implementation. This transition to C made UNIX more portable, as C programs could be easily adapted to different hardware architectures without rewriting the entire operating system.

Applications of C programming language.

  1. Embedded systems.

  2. Database creation.

  3. Networking.

  4. Operating Systems and GUI's.

  5. Systems - finance, agriculture, education, etc.

  6. Applications - games, software,

  7. Many more.

Now let's conquer the Seas!!!

Try out this C code snippet.

Hurray!!

Set sail with this code and witness the power of C programming, where the pirate within ye can conquer the code seas!

Conclusion:

Though there are many programming languages out there, programming is all about problem-solving and critical thinking. Programming languages are just tools used for problem-solving an issue.

Join the adventure and follow along!

Twitter - twitter.com/Moses_Morrisdev

Github - github.com/Moses-Morris