Latest News
Thursday, 8 January 2015

C tutorial Day 1

This tutorial teach you how to print a simple text in C language.

For this open your dev-c++ and press ctrl+n to open a new "Source File"

First, Write the below code in dev-c++ which helps you to print a simple text in your C language.

#include <stdio.h>
int main(void)
{
printf("Hello World");
getch();
}


 Run(F11) the program.
After running you will see your program as same as shown in below image:-



Remain it open and read Below terms to know what is actually everything means and what they do.

1.  #include <stdio.h>  - This will help you to include standard input and output header.

include - include
std - standard
i - input
o - output
h - header

Header contains the list of functions which C understands.If you doesn't write this then your program doesn't understand the functions which are include in this.
printf is one of the function which is include in this header.If you doesn't write this header then your computer doesn't include printf function into your program.

Now,Lets talk What is a function?
A function is a set of instructions that you tell your computer what to do.All of the instructions goes between { } (Courly braces).{ This is called open courly brace and } is called close courly brace.
Anything you write in between { } is the instructions.

2. int main(void) -This is a fuction called 'main' in C language.C gonna look for function 'main' first and also run it first from all other functions.
In other Words,It is a first function that C looks for.
here
'int' stands for 'integer'

'Void' means 'argument'

3. printf() -It is a function which help user to print text into the program.

Example- If you want to add a text "Hello World" in your program.
If you write it simply Hello World, C would not understand it and nothing is going to show in your program.
For this C has a function printf.You have to use printf function like below.All of your text goes in between "" 
printf("Hello World");

Q- What " " do in above function?
A- This tells C it is a string of text.

Q- What ; Do?
A- ; (smi colen) tells C that this is the end of the instrunction or line, you can go to the next instruction or next line.

4. getch()  - It means get character.
Here, 
get - get
ch - character

This will help us to see what he/she actually did in his/her program.You see a small _ blinking  line  after 'Hello world', that is the getch() function.That blinking line is waiting for a user to type a  character.
If you press any key the program will go to the rest of the code.In our case, their is no other code than printf so Program gona close after pressing any key.
If we doesn't add this in our program then our computer just run and exit the program and we will not come to know what we actually did.
Let take a Example- 
Below code doesn't have getch(); function.

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


Paste the above code in your Dev-C++.Compile and run(F11) this.A pop up will flash on your screen.
Now try it after adding getch() function in your program.

#include <stdio.h>
int main(void)
{
printf("Hello World");
getch();
}


Now,If you compile and run(F11) your program it will now exit automatically.You will come to know weather you did right or wrong.

Note:-
After every instruction or line you have to add ; (smi colen)  in the end because ; (smi colen) tells C that this is the end of the instrunction or line, you can go to the next instruction or next line.

Download this post into your hard drive from here.

Hope you understand.If you have any questions please ask it. we will try our best to answer your questions.

Follow us on Social media's 

This tutorial made by UnArm3D
  • Blogger Comments
  • Facebook Comments

0 comments:

Post a Comment

Don't spam :)

Item Reviewed: C tutorial Day 1 Rating: 5 Reviewed By: Unknown