Hello There, Guest! Login Register
Dismiss this notice
MaDLeeTs is not responsible for any attacks that are carried out on networks, websites or servers.
MaDLeeTs staff members cannot be held responsible.
All information on this forum is for educational purposes only.

C language Training From Beginner To Advance

  • 0 Vote(s) - 0 Average

06-25-2012, 10:24 PM #1
////////////********Start With The NAME Of ALLAH*********\\\\\\\\\\


it's just a quik tutorial for every beginner who want to learn c,

dont waste time anymore 'my tea cup is finished now let's get started'

////////////////***C language for beginners by [email protected] MinD***\\\\\\\\\\\\\\\\\\\\\\\\\\

first of all you have to know about c standard libraries or header files..!! without including that, you can't even coding a bit in c or c++.

Let's take a look at some important one.

*<iostream> : this one is stand for (input/output stream) and use to get input from user and give output message to users screen(it's use for c++)

<stdio.h> : stdio stand for (standard input/output) also use to get input and shows output message on screen. but it has some other more functions(see latter)

<cmath.h> : if you are gonna use math's function in your program then it's recomended to inlude cmath

<conio.h> : stand for (console input/output), also use to get input and shows output on screen ,but it has some built it functions(see latter)

<string.h> : use for string functions (very usefull)

<windows.h> : use for windows apps

There are alot more (google it), but am not gonna cover everyone as beginner you will just face these one's (sorry for bad english Sadsmiley ).

*The syntax for including header files are

#include <header_file_name>

ok now let's take a look at <conio.h> and <stdio.h>.

#inlcude <conio.h> : it's use for geting input and showing input message on screen but it has some other built in functions like :

*clrscr() : stand for clear screen use to clear the contents of screen.

*getch() : stand for Get Character. The function use to get single character from user, your console will be paused untill you give any sngle character. The character user entered can also stored in variable. e.g

ch = getch;

the console window will be paused untill you give any character suppose you give (*) . the (*) character will saved in (ch) variable.

i dont want to give you more ass pain Biggrinsmiley (google it for more)

now come at stdio.h (standard input/output)

#iclude <sdtio.h> : it also contains different function that use in tha task of input and output

common functions:

*getchar(): This works similar as getch() works in conio.h header.

*putchar() : stand for Put Character use to dispaly single character using stdio.h header.

*gets() :Stand for Get String use to get input from user.

Enough for header files or C standard libraries for more again google it wink

without wasting time let's make a simple hello world program, In addition i will put comments for every line. for your better understand..!!

let's get started :

#include <stdio.h>    //header file for input output

main(){         //main fucntion starts
//within these brackets {} << we can wirte our execution code

printf("Hello world"); //printf function use to get output message show on screen

getchar(); //this will puase your console window untill you press any character

//without getchar() function your program will run so fast try running your program without getchar()

//semi colon(;) are recomended in c language after any command

}// main fucntion ends

Variables are important part of any program in any language without this you can't make any good program.

int : stand for integers use for decimal numbers from 0 to 9

char : stand for characters use for any single character

float : use for real values such as 1.2, 2.3 , 4.5 etc

double : use for big real values.

Sytntax for declaring variables in c:

#include <Header_file_name>
<data type> <variable name>;

int a; //using this you have declared an integer data type variable named a

// gives value to variable a

a = <value>;

a= 10; //now (a) variable has a decimal value (10)

//print out the value of (a)

printf("%d",a); // now here new thing is (%d) what is this ? //it's actually string format use for function printf()

some common string formats and symbols:

%d : for decimal values
%s : string values
%c : character values
%x : hex values

//if you want to print decimal value using printf function the syntax will be:


// have you got somthing hah ? let's go ahead


* come at operators :

*here is list:

* (+) = for adding two values e.g(a + b)
* (-) = for sybtracting two values
* (*) = Multiply two values
* (/) = use for division
* (%) = itr's modulus operator use to get remainder of two values.
* (=) = for assigning value to variable
* (==) = for comparing two values for example (a==10) here we are not giving value to (a) but we are comparing and checking is a equal to 10.

* (!=) = not equal, also use for comparing (a!=10) we are cheking is (a) not equal to 10

* (<) : less then operator, (a < 10) this command will chek is the value of (a) is less than 10.

* (>) : Greater then operator. (a > 10) is the value of (a) greater then 10.

* (<=) : Less then or equal to. use to chek if the value of left side is less then or equal to the value of right side for example (a <=10) here if the value of (a) is 0 to 10 then the condtion is true.

* (>=) : Greater then or eqaul to. (a >= 10) if the value of (a) is 10 or above then the condtion is true.

* ( || ) : or operator. it will work like this (a=10 or b = 10) but you will get eror using this now instead of "or" we will use operator "||" (a=10 || b=10) this statatement is true.

* (&&) : And operator . wok like this (a = 10 and b = 10) again it's false then use and operator here, (a=10 && b=10) this is true statement.

you also can use as more values as you want like this
(a =10 || b = 9 || c = 8 || d = 7)
(a = 10 && b = 9 && c=8)

you will need these all operators with if statement. and then it will clear up your mind how to use these operators. take a look at if/else statement.

* if/else statemnts

They are conditional statements use use to chek if condition is true, if yes then execute the code

here are example :

#include <Header_file_name>
int a = 10; // (a) variable with value 10
int b = 9; //(b) variable with value 9

//syntax for using if statemnt is
// if(condition){code here to execute if condition is true} //within these two curely brackets write your code to execute.

// the conditional operators are use with if statement (==,!=,<,>,<=,>=)

if(a=>b){ //here we are cheking is the value of (a) is equal to or greater then (b)

// yes condition is true becuase the value of (a) is 10 is not equal to (b=9) but the the 10 is greater then 9, and thats why the condition is true

The code you will write here will execute.


* let's make a simple program using if statement.

#include <stdio.h>


int a,b; //declaring two integer values a and b

a = 10;
b = 9;

if(a >= b){
printf("%s","yes the condition is true");


Try the above code and you will get console message "yes the condition is true"

But now the question is if the condition is False then what will happen ?

Answer : "Else statement"

for making better programm you will need to use else statement with if statement. because if the condition of "if" is false, then the the code of "else" statement will execute automatilcaly.
The syntax of using else statemnt is:

else{code here to execute};

it will work like this

if (condition ){

execute this code

else {
execute this code

* Ahh confuse hah ? let's do it practically
make another simple programm using if/else statement.

#include <stdio.h>

int a,b;
a = 8;
b = 9;

if(a >= b){

printf("%s","runing if statement");
else {
printf("%s","Runing else statement");

Run the above program it will show you "Running else statement"
how ?

Because the the condition of "if statemnt" is false because 8 is niether equal to 9 nor greater then 9. thats why the control skip the if statement and run the else statement code.

* Multi if/else statement and switch statement

Ok go ahead and take a look at multi if/else and switch statement.
why i said multi/else and switch together ?

Because both statements works same. you will need these statements if you have multi conditions. still confused ?

here are example :

Suppose if a student get 40% marks in exams then he is simply pass. if he takes above then 50% then he has grade c. if above 70% then grade b.

And principle asked you to make a program for student then what will you do ?
ofcourse this program needs "if statemnt"
but there are multi if . then you will do it like this:

if (marks ==40){you are pass}
if(marks = 50){you have c grade}

like this hah?

if you are doing like this then you are going wrong . here are multi if/else.

Take a look here:


code here

else if(2nd condition){
code here

else if (3rd conditon){
code here

else {

if not matched above then execute this
oooohhhhh confused ???

Let's get a real life example with simple porgram :

#include <stdio.h>

int a,b;  // declared two integer values

printf("Enter value of a : "); //simply out put

//message using printf

scanf("%d",&a);  //here is new function "scanf"
//what is this ?  // it's used for getting input

//from user in stdio.h header file

//syntax for using this is scanf("string format",Null variable) //got it hah ?

printf("Enter value of b : ");


if (a==10 && b==20){
          printf("%s","A = 10 and b = 20");

else if(a==30 && b==40){
      printf("%s"," a = 30 and b = 40");
else if(a==50 && b==60){
           printf("%s","Above then 50");

else {
                 printf("%s","Not matched..!!!!");




Note always use (&) operator in function scanf(); like this scanf("%d",&a); else the program will be crashed as it will not allocate the value on right adress. (&) sign use to get the memory adress of variables.

how the above prgram works ? still confused ?

yeah it's a bit complicated instead of this you can use "switch statement"

Let's go ahead take a look at switch statement:

it's easy to understand and easy to use for multi conditions

syntax for using this is:



Example for switch statement :

switch(variable here){

case 1: //same as if a == 1

printf("%s","If case one print this");

break; //this will separate two statements

case 2: //same as if a==2

code here


printf("%S","This default will work same as else");

Lets's get real life example :

#include <stdio.h>

int a;

printf("Enter value of a : "); //simply out put

//message using printf

scanf("%d",&a);  //get user input

switch (a){ //switch start code within these curely brackets
       case 20: //same as if(a==20)
            printf("%s","A = 20"); //then print this
            break; //it will separate two statements
            case 30: //if(a==30)
                 printf("%s","A = 30"); //print this
            case 40: //if(a==40)
                printf("%s","a is equal to 40");
                default: //same as else{print this}
                        printf("%s","Not matched") ;            
       }//switch end here



how easy is c ?? =))

go ahead take a look on looping:

looping mean run the commands again and again untill the condition get false ..got it ?

ofcourse not..!!!

Ok here we start:

There are three main loops

*for loop

*while loop

*do while loop

first we will talk on "while loop".

th syntax of using while loop is:



statement 2
incerement/decerement operator
how loop This loop works ?

suppose you give while (a<=10) and the value of a is lessthen ten the loop will chek condition oh yes the condition is true then it will execute the code again but using incerement or decrement operator is changed and after all the time will come the value of a will not less then or equal to 10

the condition will false and the loop stops..wtf? pretty confused ?

i know

let's take a real life example:

#include <iostream>
#include <stdio.h>

       int a= 0; //the value of (a) is 0
       while(a <=10){ /*while loop starts, the condition wll remain true untill the value of (a) is less then or equl to 10*/
       printf("%d",a); //show the value of (a)
               a++; //this is incerement operator this mean a = a+1;
               printf("\n"); //\n using this cursor will go to the next line \n = start new line
               }//loop ended
how the above program works ?

see the value of a = 0 while(a <=10) this condition is true the control enter in code area and executes the code. by using
a++ = a = a+1
now the value of a = 1+1=2
the loop will chek again the condition, condition was (a<=10), now the value of a=2 here 2 is also less then 10, the control will enter again in execution area and will execute the program

again here a++, now the value of a =2

and a++ means a=a+1 = a= 2+1=3

now the vlaue of a is three which is still less then 10.
Atlast the time will come the value of a will become 11 and the condition (a<=10) will become false and loop will be stoped.

pretty cool hah ?

*do while loop

This loop will work atleast once either the condition is true or false.

syntax for this is:


statement here

Let's take a real life example :


#include <stdio.h>

int a = 10; //integer a = 10
printf("\n%d",a); // print the value of (a) which is 10

a = a-1;   //now decrease the value of a by 1 , so value becomes 9
}while(a>=0); //chek condition now still the value of a is greater then 0, run again
* for loop

it is a wide loop used by programmers it executes the statement for specific number of times.

syntax of for loop is:

for(initialize value, condition, incerement/decerement){

statement here


real life example :

#include <stdio.h>

for(int a=1;a<=10;a++) /* initialize variable a with value 0, set condition of loop it will run till the value of a is less then or equal to 10,3rd increase the value of a by 1*/


enough now for this tutorial ?

Classes, user define function, file handling, arrays wii be covered in my next tutorial thanx

Remember me in your prayers

06-25-2012, 10:29 PM #2
Tor Demon Offline MadLeets Vip ******
Posts:172 Threads:5 Joined:Jun 2012 Reputation: 0
Mood: None
that was too quick Tonguesmiley

06-25-2012, 10:31 PM #3
any question about c and c++ feel free to ask....[/align]

(06-25-2012, 10:29 PM)Tor Demon Wrote:  that was too quick Tonguesmiley

Yup i got ass pain sitting on chair for 5 hours xD

Imperfection is beauty, madness is genius and it's better to be absolutely ridiculous than absolutely boring

06-26-2012, 01:50 AM #4
H4x0rl1f3 Offline Commander In Cheif *******
Posts:1,121 Threads:25 Joined:Jun 2012 Reputation: 15
Mood: Stoned
Nice thread, best of luck...

Always Aspect Reward from the Creator and not anyone or anything Created.
For Complaints & Help Contact:- [email protected]
I am the orphan of Gaza & Kashmir. Ruins of Iraq,Syria & Palestine Bombarded of Pakistan,Afghanistan, Mali & Yemen Change of Libya and Egypt Discriminated of Bahrain & Turkey Freedom of Earth's paradise and Al-AQSA. I am the hunger stricken child of Somalia, Ethopia, & rest of Africa I am the suffering of each and every single corner of the world. But Listen!!! Hope is what I am!!

06-26-2012, 03:40 AM #5
Guest Unregistered
Mood: None
Lool broter I learned all this quickly bue nice hababy and tankx Smiley1 (Y)

08-08-2012, 11:05 AM #6
codex Offline Junior Member **
Posts:12 Threads:6 Joined:Aug 2012 Reputation: 0
Mood: None
nice tutorial bro.. I have studied C in 2nd year Biggrinsmiley and i liked the way u explained.. thanks

09-26-2012, 04:45 AM #7
john connor Offline Junior Member **
Posts:17 Threads:1 Joined:Jun 2012 Reputation: 0
Mood: None
whole Year C notes is here Smiley1 good brother Purani yaade tazza ho gaiii Smiley1

09-26-2012, 08:03 AM #8
Mast3r M!nd Offline Member ***
Posts:55 Threads:3 Joined:Jul 2012 Reputation: 0
Mood: None
Nice thread bro but i already know C++ Smiley1

09-26-2012, 02:12 PM #9
Bralo Offline Respected *****
Posts:165 Threads:35 Joined:Sep 2012 Reputation: 1
Mood: None
Very nice tutorial bro !
You making more C/C++ tutorials ?

01-24-2013, 04:56 AM #10
well not bro , you will find alot here or google wink

Imperfection is beauty, madness is genius and it's better to be absolutely ridiculous than absolutely boring

Forum Jump:

Users browsing this thread:1 Guest(s)