About this Series
Welcome everybody, you must be interested in learning about the programming. Guess what, you’re at the correct place. In this series we will learn about how to in and out of C language from very basics of programming to a pretty intermediate level. This post mainly contains the keywords, comments and variables in C.
If you wanted to take a look at history of C then checkout my previous post in this series.
Setup
Text Editor
I have already asked you guys to set up a visual code editor. I recommend Visual Studio Code
Compiler
Another thing which is required is Compiler, I have created another post for installing a compiler.
Installing C/C++ (GCC) compiler On Windows
Basics of C
To successfully execute a program in C, first we need to save it in a file, then we have to compile it (in our case using GCC). Next step is we need to run this compiled program. If no name given while compiling then, it will be saved in same directory with name “a.exe”(in windows).
Ritual
First, let’s perform a well known ritual in programming field, which is writing/printing “Hello World!” code in beginning of learning in any programming language.
#include <stdio.h>
int main(int argc, char const \*argv\[\])
{
printf("Hello World!\n");
return 0;
}
Save this program as the hello.c, then compile it using
gcc hello.c
Next step is execute this program.
a.exe
You can see all the steps from GIF.
Semicolons
A semicolon terminates the statement. You can see Ritual program as example.
Comments in C
Almost every programming contains comments. C has two types of them.
- // (single line comments)
- /* …….. */ (multiline comments)
first
// this is single line comment in c
Second,
/* this is multiline comment in
c language */
Keywords
Each programming language contains some reserved keywords for some specific purpose. C has a lot of them, let’s look at them.
- auto
- else
- long
- switch
- break
- enum
- register
- typedef
- case
- extern
- return
- union
- char
- float
- short
- unsigned
- const
- for
- signed
- void
- continue
- goto
- sizeof
- volatile
- default
- if
- static
- while
- do
- int
- struct
- _Packed
- double
Identifiers in C
A C identifier is a name used to identify variables, functions or any other user-defined item. A variable name cannot be started from a number. An identifier starts from A to Z, a, z, or an underscore ‘_’ followed by zero or more letters, underscores, and digits (0 to 9).
C language is case-sensitive programming and does not allow the special character like the @,$,%,# etc.
Example names.
vari, _test, test, test123_ => all these keywords are astill supported in few parts of india.
23var => this implementation is wrong.
WhiteSpace in C
If a line is blank line, while compiling compiler completely ignores it.
int money;
There must be at least one whitespace character (usually space) between int and variable name (money) for compiler distinctly find them and storing them into memory for later resolution.
money = original + interest; // this gets the total money
While in this example, no whitespace characters are necessary between money and =, or between = and original, although you are free to include some if you wish to increase readability.
That’s it for this tutorial.
Thanks for being here. If you have any issue please drop them in comments.
Next Part (part 3)