There are currently 0 users and 1 guest online.
Basic C / C++
Basic C / C++
Submitted by dellagd on April 8, 2009 - 1:10pm.
In this tutorial I will go over some of the basics of programming in c++ (which can be easily modified into C)
First we will start out with some basic computer programming. And first of all you will need a compiler ( which is what you type your code into ). I use Borland, but you can get Dev C++ for free.
But before we get to programming, you need to know some terminology. The first term is “int” this means integer. So if you want “number” to be a integer, you type “int number”.
But “int” does have boundaries. And number more than (I think) 30000 will circulate all the way to -30000. so if you want a number bigger than 30000 stored, you can use “unsigned int” which makes “int”s boundaries 0 through 60000 instead of -30000 through 30000, or “long int” which is “int”, but with bigger boundaries. The same goes for “short int”, which is int, but smaller. “float”, which can go into decimals, also applies to these rules.
Now we get to the programming. For now, always include “#include <iostream>” at the top of your code. This lets you use std::cout and std::cin . Also, every program must have a main() function in it. This is where your program will start. Later, I wll describe what functions are, but for now, we will only use 1 function, main(). Here is the code:
Std::cout << “hello world” ;
Std::cin >> a;
Line 1: includes the functions std::cout and std::cin
Line 5: displays “hello world” on your screen
Line 6&7: makes sure that your program will stay open until you press a number and hit okay
Line 8: returns 0, really does nothing but it has to be there
see attachments for the .cpp (C++) file and open this in your compiler and run it
Check for updates as I go deeper into C++ with more specific tutorials
If people find flaws with any of my tutorials, please PM (message) me at dellagd in the robot forum.