Learning C language part 2 Basics of C

c logo

Welcome to the second part of this Series of C language. In this series, we will start with the basic of C language.

Previous post

Environment Setup

Text Editor

Install any of the text editor available in the market, suggestion consist of the Sublime Text Editor, notepad++ etc.

I have been using Sublime Text Editor.

Compiler

Install the compiler if you have not previously then check out this post.

Basics of C

Before starting anything lets take a look at the minimum code required to run a C program.
Now we are going to do the Most famous ritual of the programming, Program of Hello World.


#include <stdio.h>

int main(int argc, char const *argv[])
{
printf("Hello World!\n");
return 0;
}

save this program as the hello.c
this will give output as like



Comments in C

comment is of two types in C.
first

// this is single line comment in c 

Second,

/* this is multiline comment in
c language */

Semicolons in C

A semicolon terminates the statement. you can see the example program from the hello world.

Keywords in C 

  1. auto
  2. else
  3. long
  4. switch
  5. break
  6. enum
  7. register
  8. typedef
  9. case
  10. extern
  11. return
  12. union
  13. char
  14. float
  15. short
  16. unsigned
  17. const
  18. for
  19. signed
  20. void
  21. continue
  22. goto
  23. sizeof
  24. volatile
  25. default
  26. if
  27. static
  28. while
  29. do
  30. int
  31. struct
  32. _Packed
  33. 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.

WhiteSpace in C

a line is only with the whitespace is considered as the blank line and compiler totally ignores this line.

int money;

there must be at least one whitespace character (usually space) between int and variable name (money) for the compiler to be able to distinguish them. On the other hand, in the following statement.

money = original + interest; // this gets the total money

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.
Subscribe my blog to get the continuous update of posts.
Next Part (part 3)

Comments

Popular posts from this blog

Third Equation of motion, How to implement using C language

Second Equation of motion, How to implement using C language

First Equation of motion, How to implement using C language