Basic C Programming Concept and Programs: hello world, Adding two integers, Area of Square and Circle using VS Code

Basic C Programming Concept and Programs

C Programming

C is a general-purpose programming language. It was initially developed by Dennis Ritchie in the year 1972. It was mainly developed as a system programming language to write an operating system. The main features of the C language include low-level memory access, a simple set of keywords, and a clean style, these features make C language suitable for system programming like an operating system or compiler development.

C Basic Commands

  • #Include<Stdio.h> :- This command includes standard input output header file(stdio.h) from the C library before compiling a C program.
  • int main() :- It is the main function from where C program execution begins.
  • { :-Indicates the beginning of the main function.
  • /*_Comments_*/ :- Whatever written inside this command “/* */” inside a C program, it will not be considered for compilation and execution.
  • printf(“Hello_World! “); :-This command prints the output on the screen.
  • getch(); :- This command is used for any character input from keyboard.
  • return 0; :- This command is used to terminate a C program (main function) and it returns 0.
  • } :- It is used to indicate the end of the main function.

Symbols Meaning

  • Brackets[] – It is use for opening and closing for brackets.
  • Parentheses() – These special symbols are used for function calls and function parameters.
  • Braces{} – Opening and closing of curly braces indicates the start and end of a block of code which contains more than one executable statement.
  • Comma (, ) − It is used to separate more than one statements like separating parameters in function calls.
  • Colon(:) − It is an operator which essentially invokes something called as an initialization list.
  • Semicolon(;) − It is called as a statement terminator that indicates the end of one logical entity. That is the reason each individual statement must be ended with a semicolon.
  • Asterisk (*) − It is used to create a pointer variable.
  • Assignment operator(=) − It is used for assigning values.
  • Pre-processor (#) − The pre-processor called as a macro processor is used by the compiler to transform your program before the actual compilation starts.

Variables: Variables is the name of the memory location which stores some data.

variables rules:

  1. variables are case sensitives.
  2. 1st character is alphabet or ‘_’.
  3. No comma/blank space.
  4. No other symbols other than ‘_’

Data types:

Data types Size in bytes
Char or signed char 1
Unsigned char 1
int or signed int 2
Unsigned int 2
Short int or Unsigned short int 2
Signed short int 2
Long int or Signed long int 4
Unsigned long int 4
Float 4
double 8
Long double 10

 

Constant:

Constant is an entity that refers to a fixed value of data and which cannot be modified. During execution/computation of programming, the value of a constant cannot be altered, it remains constant.

Constant types:

  1. Integer Constants
  2. Real Constants
  3. Character Constants

Keywords:

Keywords are predefined, reserved words used in programming that have special meanings to the compiler. Keywords are part of the syntax and they cannot be used as an identifier.

Keywords
auto double int struct
break else long switch
case enum register typedef
char extern return union
continue for signed void
do if static while
default goto sizeof volatile
const float short unsigned

 

Hello world C program:

#include<stdio.h>
//print hello world!
int main(){
printf("Hello world!");
return 0;
}

Sum of two numbers:

#include<stdio.h>
//sum of two numbers
int main(){
int a,b;
printf("enter a\n");
scanf("%d", &a);

printf("enter b\n");
scanf("%d", &b);

 printf("sum of a & b is: %d\n", a+b);
return 0;
}

Area of Square:

#include<stdio.h>
//area of square
int main(){
int side;
printf("Enter Side");
scanf("%d", &side);

printf("Area of Square: %d", side*side);
return 0;
}

 

Area of Circle:

#include<stdio.h>
//area of circle
int main(){
float radius;
printf("Enter radius");
scanf("%f", &radius);

printf("Area of square is: %f", 3.14*radius*radius);
return 0;
}

Learn More:

HOW TO FIX INDEXED PROBLEM IN GOOGLE SEARCH CONSOLE: COVERAGE ISSUE, SITEMAP PROBLEM

 

LEAP YEAR PROGRAM IN C USING IF ELSE

What is Graphics Software and Examples