Skip to content
Home » Blog » C Programming Basics

C Programming Basics

C Programming Basics

In this tutorial, you’ll learn All the important C Programming Basics, used for Programming in C Language.

This C programming basics section explains a simple “Hello World” C program.

Also, it covers basic topics as well, which is to be known by any C programmer before writing a C program

If you are looking for C programs, please click here C programs” for C Programming Basics continue below.

  1. C programming basic commands to write a C program.
  2. A simple C program with output and explanation.
  3. Steps to write C programs and get the output.
  4. Creation, Compilation, and Execution of a C program
    * How to install C compiler and IDE tool to run C programming codes.
  5. The basic structure of a C program
    * Example C program to compare all the sections
    * Description of each section of the C program
  6. C programs ( Click here for more C programs ) with definition and output – C program for a Prime number, Factorial, Fibonacci series, Palindrome, Swapping 2 numbers with and without temp variable, sample calculator program and sample bank application program etc.

Programming Basics to write a C Program

Below are few commands and syntax used in C programming to write a simple C program. Let’s see all the sections of a simple C program line by line.

C Programming Basics

Program to Print Hello World!

Below C program is a very simple and basic program in the C programming language. This C program displays “Hello World!” in the output window. And, all syntax and commands in C programming are case sensitive. Also, each statement should be ended with semicolon (;) which is a statement terminator.

#include
int main()
{
/* Our first simple C basic program */
printf("Hello World! ");
getch();
return 0;
}

Output

Hello World!

Steps to write C Programs and get the Output

Below are the steps to be followed for any C program to create and get the output. This is common to all C program and there is no exception whether its a very small C program or very large C program.

  1. Create
  2. Compile
  3. Execute or Run
  4. Get the Output

Prerequisite

  • If you want to create, compile and execute C programs on your own, you have to install C compiler on your machine. Then, you can start to execute your own C programs on your machine.
  • You can refer below link for how to install C compiler and compile and execute C programs on your machine.
  • Once C compiler is installed on your machine, you can create, compile and execute C programs as shown in below link.
  • If you don’t want to install C/C++ compilers on your machine, you can refer online compilers which will compile and execute C/C++ and many other programming languages online and display outputs on the screen. Please search for online C/C++ compilers in Google for more details.

Basic Structure of a C Program

Structure of C program is defined by the set of rules called protocol, to be followed by a programmer while writing C program. All C programs are having sections/parts which are mentioned below.

  1. Documentation section
  2. Link Section
  3. Definition Section
  4. Global declaration section
  5. Function prototype declaration section
  6. Main function
  7. User-defined function definition section

Program to Compare all the Sections

You can compare all the sections of a C program with the below C program.

#include <stdio.h>   /* Link section */
int total = 0;       /* Global declaration, definition section */
int sum (int, int);  /* Function declaration section */
int main ()          /* Main function */
{
    printf (&quot;This is a C basic program \n&quot;);
    total = sum (1, 1);
    printf (&quot;Sum of two numbers : %d \n&quot;, total);
    return 0;
}
 
int sum (int a, int b) /* User defined function */
{   
    return a + b;      /* definition section */
}

Output:

This is a C basic program
Sum of two numbers: 2

Description for each Section of the C Program

  • Let us see each section of a C basic program in detail below.
  • Please note that a C program may have all below-mentioned sections except main function and link sections.
  • Also, a C program structure may be in below-mentioned order.
C Programming Basics

C Programs with Definition, Example Program, and Output:

If you have enough basic knowledge of C programming language and all concepts, you can refer following C programs.

Please click here “C programs” for referring below programs.

  • C program for the Prime number
  • C program for Factorial
  • C program for Fibonacci series
  • C program for Palindrome
  • C program for Swapping 2 numbers with and without the temp variable
  • Sample calculator program and bank application program etc.

Important Basics Points to Remember in C Programming

  1. C programming is a case-sensitive programming language.
  2. Each C programming statement is ended with a semicolon (;) which are referred to as a statement terminator.
  3. printf( ) command is used to print the output onto the screen.
  4. C programs are compiled using C compilers and displays output when executed.

Ask your questions and clarify your/others doubts on C Programming Basics by commenting. Documentation

NEXT
Keywords & Identifier