Learn Basics of c programming

What is the variables in c ?

C program practicals


Variable are the most important part of each programming language. variables are user defined. Here variable is the name of to the memory address. Where we store our data. Let's take example of Addition of two numbers : here we require two variables so suppose we taken variables name as 'num1' and 'Num2'. Also we require another variable to store result of Addition. That is 'result'.
Int num1; // first variable declared 

Int num2; // second variable declared

 int result; // third variable declared

 result = num1 + num2 ; // added two numbers and Stored Addition in result. 

When we print results using printf () function it shows result.
Basically we use variables for storing data and making process. Without variables programming is not possible. Because we require memory to store data. Because of that we use variables.
Hope you understood what is the variable and why it's require while programming.



How to print output on screen in c programming ?


C programming has standard libarary for I/o operations. That is " stdio.h" . This file give us access to use printf () function for displaying message on computer screen. Printf() is the function which is used for printing the message in screen. Using this function you can print output.



How to take input from user in c programming ?


C programming provides special function for input operation. That Function is ' scanf()". This function allows to take input or store input in variables.


For accessing Scanf () function we have to declared header file" stdio.h ". This file give us access to use Scanf () function.



What is the header file in c programming ?


Header files are most important for standard functions like input /output functions ex: printf (), scanf(), getchar(), gets(), puts() etc.


For accessing these functions we have to declare header file like 

" #include < stdio.h >".


There are so many header files like stdio.h, conio.h,math.h,graphic.h, stdlib.h etc.

What is the curly brackets in c programming ? 
Generallyy curly brackets used for organising code in neat way. The purpose of taking curly bracket is " to organise code in the small blocks and functions". In c programming curly brackets shows " block of code". Let's take an example : Addition program. Generally for writing the code we should structure of program. Structure is like below, 
  1.  header files declaration 
  2.  main function declaration. 
  3.  Start with opening & closing curly brackets. 
  4.  In between the opening and closing curly bracket add remaining body of code.

 That's simple and easy structure of c program. Here is example :

 #include < stdio.h > //header file declared
  int main() // main function declared 
 { // Opening curly bracket 
int a=2,b=3 ; // variables declared
int c=0 ;
c=c+a+b ; 
Printf("Addition=%d",c) ; //Code body
return 0 ; // end of program
   } // Closing Curly bracket. 

The above program shows us structure of c programming. Here the code in between curly bracket is called block of code. Hence each programs body starts with opening Curly bracket and ends with closing Curly bracket.


How to assign value to variable in c programming ?


When you declare variables or after declaration of variables you can assign value to the variable using assignment variables.


Here is example :
int number1;

number1=20;

Or 

int number1=20;

It's works and easy.

    


How to declare main function ,variables , printf function , scanf function and return statement in c program:

1) Main function declaration

int main () { //Code body }

2) variables declaration

int main() { // Data_type variableName ; int number1; }

3) printf & scanf declaration

int main() {
 // function_name(" message"); printf("Enter a number "); //function_name ("data specifier", & variableName); Scanf("%d",&number1); 
 }

4) return statement declaration

int main() {
return 0; /* return statement shows end of the program. */ 
 }


what is the main() function ?

Each program in c start with main() function.


Main function is the starting point of execution of code. Without main() function we can't able to run c program. Because of this reason main() function is compulsory for each program.

see c program examples

Comments