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.
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>
Operators - Arithmetic operators, assignment operators, decrement and increment operators, relational operators, logical operators, and bitwise operators.
Variables - local variables, global variables, static variables, automatic variables, and external variables.
Input and output - scanf, printf, format specifiers, and ASCII values.
Data Types - primitive/primary(Floating-point, integer, double, character.), User Defined Data Types/Derived Types(Structures, arrays, pointers, unions, functions), enum, and void.
Functions and program structure - function prototypes.
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.
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.
Control flow structures and statements. - If Statements, Switch Statements, Conditional Operator Statements, and Goto Statement Loop Statements.
Algorithms and data structures: Arrays, Linked Lists, Stack, Queue, Binary Trees, Binary Search Tree, Heap, Hashing, Graphs.
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:
#include statements (preprocessor directives) - also external files or codes.
Reserved words : (e.g., int, double, return, main, include, etc.)
Variables - stores values for the program.
Builtin functions (library functions) (printf, strings, etc).
{} (start and end of functions). - Code directives and instructions.
Main function -the starting point of program execution.
Comments : (// single line, /* .... */ multiple line
The Process of Compiling in C.
This is the process of converting our C code into a program.
Write our code in C. - use a text editor or code editor.
Let's name our file maths.c
Debug our code and remove errors.
Use a compiler to execute our code.
Process:
The compiler preprocesses the code using the CPP tool.
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.
The assembler converts assembly code to machine language. Creates a .o or .obj file extension.
It converts our code to an a.o file
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.
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:
Codeblocks - Windows, Linux.
VS code - Windows uses MinGW (Minimalist GNU for Windows). MacOS users use Visual Studio for OS X.
CLion - macOS.
Netbeans - Windows Linux.
GCC (GNU Compiler Collection) - Linux.
Online compilers:
Code studio C Compiler - https://www.codingninjas.com/studio/online-compiler/online-c-compiler
OnlineGDB Compiler - https://www.onlinegdb.com/
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.
Embedded systems.
Database creation.
Networking.
Operating Systems and GUI's.
Systems - finance, agriculture, education, etc.
Applications - games, software,
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.