Hello everyone, as you would have guessed, my name is Vlad and this is a tutorial for people who want to learn C and C++. These two programming languages are almost the same, but they are different in some ways... you'll see what I mean in a second.
First, let me present these languages. They are two of the most used languages of programming, and I must say, the simplest for me to learn. I don't want to lie, though, learning it won't be a piece of cake, but it is very useful once you get the hang of it!
I assume a lot of people would have wanted me to make a flash about it, but I just formatted my computer and now I doesn't quite work. If it doesn't abide the rules to post a tutorial here, I'm sorry, I'll delete this and I will go on with living. By the way, if the 8000 characters are not enough, I will have to double post.
So, let get to the thing.
Chapter 1 : Preparation
I guess you're eager to start, but first you need to prepare! To make a program, you need a compiler. There are a lot of compilers out there, but my favorite is MinGW.
Google it, it's that simple to get it.
Before we begin this tutorial, I suggest turning off any surge of distraction.
Chapter 2 : Basic programs
Now you've got you compiler and you're ready to start. To begin making a program, click Project>New Project. Click the command prompt icon and then name the project.
Now click on Source Files from the left panel and click Project>Files>New and select source file and select a name.
You're ready to start! Copy this code and I will explain it after :
#include<stdio.h>
int main()
{
printf("Hello World!");
return 0;
}
So, let's explain!
#include<stdio.h>
This part is where the library named stdio (standard input/output) is called. It has a lot of things within it, but we're not gonna talk about it now. For now all you need to know is that it helps your program run.
int main()
This is the main function, which does all the work. Later, we will also make our own functions which will aid the main.
printf("Hello World!");
This function puts on the screen the message "Hello World!". You can replace the message with whatever you want.
return 0;
This thing will tell Windows that the programmed finished corectly. If the program didn't finish corectly it will say "Abnormal program termination".
Now that you've got the code save the source file and click Compile and Run. A command prompt window will apear where it will say "Hello World!".
Chapter 3 : Variables
What are variables in the first place? They are memory places where numbers are stocked. They occupy from 1 byte to 64 bytes. We will go over these types right now.
int
Bytes : 2
Max value : 32676
Min value : -32677
Cannot hold zecimals
Read with %d
long
Bytes : 4
Max value : around 2000000000
Min value : around -2000000000
Cannot hold zecimals
Read with %ld
float
Bytes : 8
Can hold zecimals
Read with %f
double
Bytes : 16
Can hold zecimals
Read with %lf
long long
Bytes : 64
Can hold zecimals
The most high Max value
Read with %lld
char
Bytes : 1
Can hold letters
Read with %c
Now that I have exposed the data types, let's get to our sheep and see how to read them!
Here's a code :
#include<stdio.h>
int main()
{
int x;
scanf("%d",&x);
return 0;
}
As you can see, scanf is the function that reads them, and this is the syntax :
scanf("%d or %ld or %c or...", &name of var);
And the same applies to printf, but without the &!
printf("%d or...",name of var);
Now that we know how to read/show variables, let's learn how to modify them! The following program gets a number, adds one to it and shows it back. I wont put #include<stdio.h> or int main, cause you already know it!
long x;
scanf("%ld",&x);
x=x+1;
printf("%ld",&x);
return 0;
So, let's put it like this :
Add : x=x+y;
Substract : x=x-y;
Multiply : x=x*y;
Divide : x=x/y;
Now, I'll let you think about a program. Make a program which reads x and y and shows x*y.
...
...
...
Managed? Yes? Go on with the tutorial! No? Read the chapter again and understand it more!
Also, you can also put in a variable other variable and assign values to variables this way :
x=y; to make x the same value as y
x=42; to make x the value 42;
s=x+y; to make s the value of x plus y
Well, it's the end of this chapter. I will continue with part 2, though! Stay tuned for more details!
seel
<a href="http://www.youtube.com/watch?v=WrjwaqZfjIY">http://www.youtube.com/watch?v=Wrjwaq ZfjIY</a> pretty much sums up my thoughts about your entire post. Poster above me obviously does not know C or C++ if he read through this. Also zecimal in English is decimal, might want to work on your English skills as well.