C programming introduction



C programming introduction

Before article we learned a few things about the history of the C programming language. This article about C programming Introduction.

  1. Find a code editor
  2. Default
  3. Hello world!
  4. Comments
  5. Variables
  6. Constants

Find a code editor

First we select the code editor to write the program.

  • Code:: Blocks
  • Eclipse
  • CLion
  • Visual Studio Code
  • NetBeans
  • Codelite
  • Atom

In this lesson, we select to write a program Code::Blocks and you can download go below the link :

http://www.codeblocks.org/downloads/binaries/

After the code::blocks install, follow this step for create a project.
Create new project &#8594 Select Console Application and Click Next &#8594 Click Next &#8594 Select C and Click Next &#8594 Select the Path &#8594 Finish

Default

Our main program write in the main () function, if you are create a other function you can write it above the main() function.



Hello World!

In C use printf() function for output a any strings.
eg: printf(“Hello World!”);



If you want go to new line or blank line use a “\n” in printf() function.



Commects

In C, if commented one line use “//Comment” and commented more lines “/*Comment*/”.



Variables

Few variable types in C language.

  • int - Store whole numbers without decimal (1, 25, 351)
  • double and float - Store decimal number (1.2 , 2.3568)
  • char - Store single character ( a , A , z) {using single quoted}
  • If you need store a words, use chat array
    char name[] = "Name";

Such of variables have a different output ways.

  • int - printf(“%d”, x);
  • double - printf(“%lf”, y);
  • float - printf(“%f”, z);
  • char - printf(“%c”, a);
  • char[] - printf(“%s”, name);



Constants

Constants are use for store not changing values, like a hours of day.
eg: const int hours = 24;
Variable will can change it value later, but constant’s value can’t change.

Read More (Ref.)

W3schools