Thursday, 19 April 2012

Starting to code

Hello world!

In this post I will show you how to setup everything you need for programming and start coding.Programming language I will show you will be C.
So first thing you will want to do is setup your programming environment.By that i mean tidy you're room and everything around your laptop.Ok bad jokes aside,programming  environment is a program itself in which you will program.Sounds a bit complicated?Well it really isn't and you'll see that as soon as you start.I think most popular newbie programming enviornment for C would be Bloodshed Dev C++.If you dont want to install anything you can use online compilers that are just as good for beginners.Online compiler I use is Ideone.com and I would recomment it to everyone(given that you don't want to install Bloodshed Dev C++ for some reason).Once you have downloaded you're environment you have to install it and you're ready to start coding!

What you will want to do is open Dev,click "File" in the top left corner,"New","Project..." and then Console Application.Now you're ready to go!

Lets get started now!

Code should look like this:


#include <cstdlib>
#include <iostream>


using namespace std;


int main(int argc, char *argv[])
{
    
    
    system("PAUSE");
    return EXIT_SUCCESS;
}


What you will write is following:
#include <cstdlib>
#include <iostream>
#include <stdio.h>


using namespace std;


int main(int argc, char *argv[])
{
    
    printf("Hello World!");
    system("PAUSE");
    return EXIT_SUCCESS;
}


Ill explain what does each line do now.

#include<stdio.h> - What this does is includes a package of functions in your program.For example if you want to do exponential function you will have to include <math.h> and for printf() we just used we need <stdio.h>.If we haven't used the include function, compiler would not recognize it as a function and will think of it as a gibberish text.It's not really important to understand it since it's not part of an actual code.




printf("Hello World!"); - Finally this is the real part of code! printf() is a function that writes anything you say to output.At end of any command in C you have to put ' ; ' as this concludes a command.Program woldn't work without it.

Rest of the program(the things you get written in beginning) aren't really neccesary to explain but I'll do it briefly for those that already know a bit about programming.#include i explained already.Other 2 includes are neccesary to run the rest of the program.
using namespace std -Explained as simply as possible,namespaces allows us to group a set of global classes,objects and/or functions under a name.




int main(int argc, char *argv[])
{
    
    XYZ


    system("PAUSE");
    return EXIT_SUCCESS;
}
int main is the main function of every program.What the program does you write in replacement of XYZ.
system("PAUSE");leave the program open after running it.
return - it concludes the main() function.





Ok so you have written everything you need to now its time to run a program!
Under "Execute" tab press "Compile".Save it anyway you want but chose to save it as C file.After that under "Execute" tab press "Run".

And there you go! You have a program that writes Hello World!

That's it for today.I'll tutor you guys further tomorrow!



No comments:

Post a Comment