madhusudanlive logo
Stay Zen!

Basics of C programming Language: Introduction to the C Programming Language

Basics of C programming language: Understand the keywords, variables, functions, loops, control structures and more for the most popular general purpose programming language.
Illustration of Computer Programs and systems, with text that reads Basics of c programming for beginners'

If you are new to programming or learning the most popular C programming language as a new skill to advance your career, you’ve come to the right place. After mentoring numerous mentees and having extensive expertise in hardcore computer programming, I am here to start with a new series, Beginners Guide To C Programming Language. Although the name mentions C programming Language, however, I’m here to focus more on logic and not the syntactical part, so concepts covered in this series apply to other programming languages as well. I have seen many articles and videos, and I find that most of them are repetitive, but in these tutorials, I will explain every topic in detail and with real-world examples.

This series will cover the fundamental aspects of the C programming Language, We will start with some theoretical parts such as the History of C Programming Language, Keywords, data types and their sizes. After that we will demystify how a C code is written and what’s the significance of each code block, keyword, etc. then we will start with the keywords.

History of C programming

Since our college days, we have heard that the C programming language was developed by the legend Dennis Ritchie, at the AT & T Bell labs situated in the USA in 1972. This has roots in its predecessor languages such as ALGOL COBOL, etc. This programming language was designed for general-purpose programming, and now it powers the Linux kernel.

All the supercomputers, and servers, have used C somewhere, think of its versatility, currently all over the world there are 32.8 billion Linux PCs and C is at their heart. It is the only programming language that existed for the longest period of time since it was developed, otherwise, there are a total of 8000+ programming languages in the world, and roughly only 250 to 500 are in use today.

OK, enough of the history, but you might wonder why this language is named C. As neither Dennis Ritchie has C in his initials nor the lab where it was developed, So from where exactly does the name C come? That’s a good question, actually, there is no logic behind the name C, as it is a successor of language B (BCPL) and covers all the inabilities, it was named C as it comes after B in the alphabet.

Why Learn C Programming?

C is a feature-rich general-purpose programming language when it comes to speed and performance, C is always the first choice and that’s the reason the high-end games, graphics-rich applications, and embedded systems make use of C programming.

C is a powerful and robust programming language that works closely with the hardware. Learn C programming if you want to create something truly exceptional that works and runs faster than the cars in Formula One.

As I mentioned C is faster and works closer to hardware so keep that in mind, in this series somewhere later, I’ll explain this point, why C is faster and why embedded systems prefer it.

Set Up Development Environment for C Programming

Before we start writing our first program, we need to set up our development environment, or an IDE (Integrated Development Environment). There are so many great IDEs out there, however, we will use Dev-C++ or CodeBlocks IDE, feel free to use your favourite IDE, also, we can use the command line interface if on Linux.

How to Write Your First C Program

As per the tradition of software developers, we will start our C programming adventure with a basic Hello World program, at first, it might look difficult to grasp, but we’ll demystify the code line by line.

So here we go with an example of the Hello World Program written in C Language

#include<stdio.h>

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

OK, so these 5 lines of code will print the Hello World! on your Standard Output, which is your terminal.

PS: C uses a semicolon (;) to mark the completion of a statement, so don’t forget to put a semicolon at the end of each statement, otherwise it’ll take endless hours to debug your code.

Well, well, let’s understand how this code is structured and what these symbols and words mean.

#include<stdio.h>

The #include is called a preprocessor directive, as we know C is a compiled language and this fancy thing tells the compiler that along with this code, also add the code from the said file stdio.h.

That’s great, but what’s there in stdio.h and why do we need it? Well, stdio.h is an abbreviation for standard input output. As we are printing Hello World!, on our standard output device which is nothing but the screen/terminal, we use the print function which comes from the stdio.h.

stdio.h contains many other functions related to the input and output, as this series progresses, we will cover some important functions.

int main()

The main is our entry point, the execution of our code starts from here. Here we have defined a function main and the int is its return type. At this point, you don’t need to understand the return type, for now, just think of it as a syntax requirement, and safely skip it for this example, however, a simpler explanation is provided below.

What’s the return type? So when your code has to perform multiple operations, we split the logically similar code into separate functions and the return type is what gives us the intermediate output of these functions.

printf("Hello World!");

We are using the built-in function in the C programming language, which is responsible for printing the information on our screen. This function is available to us as we’re including the stdio.h file. The function printf takes the message we want to display and prints it on the screen, here the quoted part is our message "Hello World!" and the parenthesis is the way to call a function in C programming Language.

    return 0;

As discussed earlier functions return the values to the callers, as this is an entry point, the return value does not really matter here. However, on Linux systems, if the script or program completes the execution successfully, it returns 0 and if some error occurs during execution, the error code is returned. For our case, as our execution is successful, we’re returning 0.

{
// This is the body of function

}

Now the only thing left is the curly braces, these curly braces hold the statements and are generally called as the blocks or code blocks.

Terms used in this article

  • Variables : Variables are used to store the information. Think of them as containers, in our code we use them to store data, results of our computation and any information.
  • Statement: In programming language, a single logical action is called as a statement.
    e.g.
    printf("hello world");
  • Block: A group of statements enclosed in curly braces or some other syntax are called as a block, these are nothing but just a bunch of statements. e.g.
    if(isEven) {
        int a = a + 10;
        print("even number");
    }
  • Expression: Expression in programming refers to the combination of operators and operands that evaluate to give results. e.g.
    int c = 5 + 9;
  • Assignment: As the name suggests, assignment in programming is a way of providing values to the variables e.g.
    a = 9;
  • Declaration: The declaration is used to define new variables, In programming, when you specify a new variable it’s called a declaration. e.g.
    int a;

    Note: declaration and assignment can be done as a single statement or they can be split as well
    int a = 9;

    In the example above, the variable a is declared and also assigned a value of 9
    the same can be also split into declaration and assignment as follows
    int a;
    a = 9;
  • Debugging: Debugging in programming languages refers to the act of finding the cause that made the program unstable or fail to run.
  • Header files: Header files are nothing but libraries, in C programming language, there are so many functions, and utilities developed to ease our job and these built-in functions,

Conclusion

To sum it up, we've covered the history of C, why it's named as C, also we saw how a C program is written and what things are there, now in the upcoming posts, we will explore each construct in C Language, we will cover the topics from not only syntax perspective but also focus on the logic behind it, so do not forget to my newsletter. Stay tuned for more in this Beginners Guide To C Programming series, where I will simplify concepts with real-world examples. Happy coding!

Prev article Install Java 17 On Linux in 2 Ways: Step-By-Step GuideNext article EDI Electronic Data Interchange Basics, Examples, Benefits PDF

photo of Madhusudan Babar
Say Hello

Thanks for visiting my site, if you have any questions or just want to say hello, feel free to reach out to me. You can also mail me directly at krypton@madhusudan.live