Showing posts with label C Programming beginners - Introduction. Show all posts
Showing posts with label C Programming beginners - Introduction. Show all posts

Thursday, 22 August 2013

C Programming beginners - Introduction, Variable declaration and simple iteration

/*
 Global variables can be accesses any where in the program;
Local variables accessed within the scope defined by curly braces.
*/
#include<stdio.h>
#include<conio.h>
//As user defined function declared after main(), its prototype must be declared before main
void DoSum(int,int);
int Total;
void main()
{
int ValA,ValB;
clrscr();
ValA=23;
ValB=15;
printf("ValA:%d\nValB;%d\n",ValA,ValB);
Total=ValA-ValB;
printf("Before DoSum(), Value of Total=ValA-ValB=%d\n",Total);
//Calling of Function, function will add value of ValA,ValB
// and stores it in Total
DoSum(ValA,ValB);
printf("After DoSum(), Value of Total:ValA+ValB=%d",Total);
getch();
}
//DoSum() is user defined function
void DoSum(int A,int B)
{
//As Sum is Global Variable it is accesible here
//And it will holds addition of value
Total = A+B;
}

/**************************************************************/
#include<stdio.h>
#include<conio.h>

//Global Variable declaration
int Total;

//DoSum() is user defined function
//As function definition written before main(), no need to declare function prototype before main
void DoSum(int A,int B)
{
//As Sum is Global Variable it is accesible here
//And it will holds addition of value
Total = A+B;
}
void main()
{
int ValA,ValB;
clrscr();
ValA=23;
ValB=15;
printf("ValA:%d\nValB;%d\n",ValA,ValB);
Total=ValA-ValB;
printf("Before DoSum(), Value of Total=ValA-ValB=%d\n",Total);
//Calling of Function, function will add value of ValA,ValB
// and stores it in Total
DoSum(ValA,ValB);
printf("After DoSum(), Value of Total:ValA+ValB=%d",Total);
getch();
}

Monday, 12 August 2013

Little Introduction for Beginners of C Programing

And E-Book is available on below link.

E-Book of Ansci C Balaguruswamy : Download E-Book (External Source)

In C Program, we include header files in which external/predefined functions declared.
These functions will be used in our programs, so related header file will be included.

->In C Program, double slash "//" is used to comment a single line.
   And /*..*/ is used to comment multiple lines.
->Commented line will not be compiled during compilation.
    It is good practice to write comments in program. Comments will help to understand the program.

->Every line must end with semi-colon ";"

->main() is the function denotes to compiler starting of program for compilation.


General format of C Program

//Header or Title or Definition of program

#include<...h> //Header File(s)

globle varible declaration

main()
{ //Program Starts
     Loca Variable declaration;
//     Executable part of program
     Input/Output Operation

}//end of program

user defined functions()
{
}

Important shortcuts for Turbo C Compiler
To Compile Program : ALT+F9
To Run Program : CTRL+F9
To View output/previous screen : ALT+F5

Open Turbo C and write following program.

First C Program
//Simple program to display "Hello World"

#include<stdio.h>
void main()
{
     printf("Hellow World...!!!");
}

check for errors by ALT+F9
if no errors hit CTRL+F9 to run program
and to check output hit ALT+F5


Now you can write C programs.....

Contact Form

Name

Email *

Message *