Keywords, Constants, Variables: C

Computers do not understand English language. It can only understand machine code, a binary stream of 1s and 0s.

Learning The Building Blocks of C programming Language

To learn any language we need to first learn alphabets, then we learn to write sentences and then to write paragraphs. Similarly, in learning C programming language, we first learn about the Character Set(Alphabets, Digits, Special Symbols), next we learn words(keywords, variables, constants), and then we learn statements(C programming instructions), and then we write C programs.

Keywords, Identifiers And Literals: C


[youtube https://www.youtube.com/watch?v=D4ePj0ill5k]

YouTube Link: https://www.youtube.com/watch?v=D4ePj0ill5k [Watch the Video In Full Screen.]


Keywords

Every word in a C program is classified as either a keyword or an identifier. All keywords have fixed meanings predefined in the language and these meanings can not be changed.

Identifier / Literals

In programming languages, constants are usually called as literals and variables are called as identifiers.

Constants / Variables

As name suggests, a constant is an entity whose value doesn’t change during the course of program execution. A variable, on the other hand, is an entity whose value may change during the course of program execution.



C Constants

C Constants can be divided into 2 categories.
1. Primary Constants.
2. Secondary Constants.

Primary Constants are further divided into Integer Constants, Real Constants and Character constants.

Keyword for Integer is int and the format specifier is %d.
Keyword for Real is float or double and the format specifier is %f.
Keyword for Character is char and the format specifier is %c.

 
#include < stdio.h >
int main()
{
    const int a = 5;

    a = a + 1;

    printf("Value of a is %d", a);
}

Output:
error: Assignment of read-only variable ‘a’.

a is a constant variable and thus its value can not be changed through the course of program execution.

 
#include < stdio.h >
int main()
{
    int a = 5;

    a = a + 1;

    printf("Value of a is %d", a);
}

Output:
Value of a is 6

Note: Literals are constant values and not constant variables.

include directive in C Program

Usually you can see these “include” directive at the very top of your source code. It’s called a preprocessor directive.

All preprocessor statements in C start with a hash(#) symbol. include directive is similar to imports statement in Java.

 
#include < stdio.h >
int main()
{
    printf("Microsoft\n Apple\n Oracle\n Google\n Yahoo\n");
    return 0;
}

Output:
Microsoft
Apple
Oracle
Google
Yahoo

include Preprocessor Directive In C Program


[youtube https://www.youtube.com/watch?v=4BBml3T8WK4]

YouTube Link: https://www.youtube.com/watch?v=4BBml3T8WK4 [Watch the Video In Full Screen.]


This “include” directive causes one file to be included in another. For example, when we include stdio.h (header file) in our above program, all the content(code) gets imported or included in our program source code. This way we can make use of any function present inside stdio.h library file in our c program.

Car Program

We are writing Car simulation program in C – we write all the related code in different files by group them together and then include it in our main Car program. For example, we can separate wheels, color and display related things and then include all those things in our main Car program. This way our main Car program source code looks less clumsy and more over we need not worry about the implementation details present in those files.

Ex: When we include stdio.h file, we do not worry about the implementation details of printf() method. We simply use it for displaying content to the console. All the implementation details are present in stdio.h header file.

There are 2 ways of including header files

 
#include < stdio.h >

#include "Mylib.h"

When we use < and > to wrap around the file name, the linker looks for the files in standard library storage folder. When we wrap the file name in double quotes it looks for the file in current directory.

Usually user written, custom header files are wrapped in double quotes.

We’ll be writing our own library files in this video series. But for now it’ll get too complicated if we go any further.

Note: There are many preprocessor statements other than include directive. We’ll discuss them as and when we use it in our C programs.

Structure of a basic C Program

Lets write our first C program – the typical “Hello World!” program.

In this video tutorial lets learn the structure of a basic C program:
1. Preprocessors – include directive.
2. Main method/function.
3. printf method/function.
4. Semicolon syntax.
5. Indentation for readability of code.

Source Code: A Simple C Program

#include<stdio.h>

int main()
{
    printf("Microsoft\n Apple\n Oracle\n Google\n Yahoo\n");
    return 0;
}

Output:
Microsoft
Apple
Oracle
Google
Yahoo

Structure of a basic C Program


[youtube https://www.youtube.com/watch?v=3Yu6u3tmBS4]

YouTube Link: https://www.youtube.com/watch?v=3Yu6u3tmBS4 [Watch the Video In Full Screen.]


Preprocessor statement

The “include” directive which we see in the first line is a preprocessor directive. Here we are including a standard library file which has some set of useful functions in it, which we are using in our “Hello World” C Program.

stdio stands for “Standard Input Output”. As the name suggests this library file has functions to read and write data to console window, along with other many useful functions. For example, printf() is a function present in stdio.h library file. We simply use it in our program to print data on to the console window. We need not know the implementation details of printf method/function.

main() method

Main method or function is part of all ‘C’ programs. It’s entry point of any C program execution. Function is a way of grouping some code together. We can write any logic/statements inside a function.

It’s a standard that main always returns a integer value. Thus main is preceded by a keyword called int, which means integer. It’s a keyword or reserve word. We’ll know more about keywords(or reserve words) in a separate video tutorial. Since main method needs to return a integer value, we explicitly return 0 at the end.

Readability of code

It’s very important that we write code which is readable. It helps in maintaining the code. Large programs get too clumsy very easily and reading and understanding code often becomes difficult. So we need to indent the code and make sure its readable as far as possible.

Note:
Main method/function doesn’t take any argument.

The Best IDE For C Programming

There are many IDE(Integrated Development Environment) available for C programming language, but I would prefer using Code::Blocks or Visual Studio Editor.

For this video tutorial series we’ll be using Code::Blocks.

You can visit CodeBlocks website and navigate to Downloads section, and then to Binaries section and depending upon your Operating System, download the IDE and install it. Downloading and installation of Code::Blocks is shown in the video posted below. You can follow along and get started with programming in C language.

 
#include < stdio.h >
int main()
{
    printf("Microsoft\n Apple\n Oracle\n Google\n Yahoo\n");
    return 0;
}

Output:
Microsoft
Apple
Oracle
Google
Yahoo

Above program is just an example. You need not worry if you didn’t understand it. I’ll be explaining it in the next video, in detail. For now, if possible type the program as it is and try to compile and execute it on your own by seeing the video. Try to change the content inside printf function and run compilation(Build) and execution(Run) once again and see the results for yourself.

The Best IDE For C Programming


[youtube https://www.youtube.com/watch?v=xsWy-sMzIj0]

YouTube Link: https://www.youtube.com/watch?v=xsWy-sMzIj0 [Watch the Video In Full Screen.]


Note:
1. Code::Blocks is available for all the popular Operating Systems. So whatever I show in the video tutorial is applicable for everyone irrespective of the OS they’re using.

2. Code::Blocks comes with C/C++ compiler, so you need not install compiler or any other plugins separately.

3. Make sure to download the latest version of the IDE. And make sure the file you download has ( codeblocks-17.12mingw-setup ) mingw in it. That’s how we can know it comes shipped with c/c++ compiler by default.

Why Learn ‘C’ As Your First Programming Language?

Let’s know a little bit of history of C programming. Many of you may not be interested in knowing the history of C – you maybe here just to learn how to get started with Coding in C Program. I understand that. You’ll want to know the history soon, once you learn the basics of C programming. History is very important. But for now I’ll let you know about it in 1 line!

History of C Programming Language

C Programming language was developed at AT&T’s Bell Lab in 1972. It was designed and developed by a man called Dennis Ritchie (September 9, 1941 – October 12, 2011).

Why name it as C?
Before designing C, there was a programming language called “B”. So Dennis Ritchie named it as “C”. Little did he know “C Programming” language would get so popular among programmers – even after 3 decades of its inception.


C programming language

Why Learn C As A First Programming Language?

Beginners tend to get into arguments/discussion as to how C++, C#, Java has improved upon C and how “Object Oriented Programming” has so many advantages over C. But let me tell you, Operating Systems like Windows, iOS, OSx, Unix/Linux(Kernel), android are all written in C. Looks like there is something which is good in C because of which companies like Microsoft, Apple, Unix/Linux Foundation, Google are choosing C Programming language to develop and maintain their Operating Systems. These are only a few popular companies I’ve listed. There are many many companies solely dependent upon C programming for their software development. We’ll learn more along the course of these video tutorials.

Why Learn C As A First Programming Language?


[youtube https://www.youtube.com/watch?v=s88KJDI1P_o]

YouTube Link: https://www.youtube.com/watch?v=s88KJDI1P_o [Watch the Video In Full Screen.]


Advantages of learning C

1. Object Oriented Programming(OOP) method present in C++, C#, Java provides a huge advantage for programmers. But the basic programming elements like looping, variables, declaration, arithmetic operations, logical operations etc are almost similar to what you learn in C. Learning C definitely gives you an extra edge before jumping on to learn C++ or C# or Java.

2. Programs written in C are very efficient. It’s performance and speed of execution is unique. Even today device drivers are written in C for this reason. The code is compact and has high performance even in low memory availability.

3. Your smartphone, digital camera, washing machine, microwave oven, refrigerator, smart bulbs, smart fans etc you name it, all these have microprocessors attached to it, which has program embedded in it. Since these micro-processor in these devices have limited memory and need to respond to user inputs instantly, the program of choice is inevitably C, in most cases.

4. Most 3D gaming frameworks like “DirectX” are built using the C Programming language. Because for good gaming experience speed of execution matters a lot. Since C programs are robust, reliable and fast these 3D gaming framework choose C programming over others. Even animation special effects in movies are done using C programs.

5. Its flexible and portable: Since C program allows user to handle memory directly we can write programs very flexibly according to our needs. We can manage memory flexibly. “Portable” because the same program source code works on all operating systems without the need for much modification. All Operating System have C Compiler and they compile and give object code and executable which suits and works for that particular OS.

6. Did you know, many compilers and interpreters for other languages like FORTRAN, Pascal, Perl, Python etc are written in C. Why is it so? As I told you before, C is reliable, portable and fast.

7. Using C programming language we can directly access hardware. This is very powerful feature. We’ll discuss this in detail in coming video tutorials.

8. C program enables programmer to manipulate individual bits of memory. But “with power comes responsibility” – we need to handle memory carefully or else we may end up writing code which might behave abruptly. For this reason Java has its own builtin memory management feature called Garbage Collection.

9. C implementation has a large library of useful functions. Ex: scanf, printf, functions to write data to file etc.

10. C programming language is easy to learn and understand.

We can go on and keep writing advantages of learning C Program. But let me stop here and assure you that you’re in the right place and C is the best choice as your first programming language to learn.

Make sure to practice all the programs we post here and quickly you’ll know the advantage for yourself. And soon you’ll be an advanced user and if you keep learning you’ll be an expert.

There are many Job opportunities for people who are experts in C Programming Language. We’ll even post Job Board shortly and try to list job offers for C program experts. Stay tuned for all the good stuff we’ll post on this page: C Programming: Beginner To Advance To Expert

Request

Please let us know some advantages and disadvantages or anything informative about C programming language in the comment section below. This will be helpful for others joining you on later date to start learning ‘C Programming language’. Sharing is caring. Also please share this article with your friends and followers on Social Media.