Tutorials Navigation
C Programming Tutorial 1, Variables part 1
Tutorial Name: C Programming Tutorial 1, Variables part 1
Category: PC Tutorials
Submitted By: Nissan
Date Added:
Comments: 4
Views: 2,232
Related Forum: PC Building Forum
Share:
C Programming Tutorial 1, Variables part 1.
The program we are going to be using to learn C programming language is "CodeBlocks" and here is a link to the download its a free program.
Link : [ Register or Signin to view external links. ]
All of these tutorials are going to be done in an console application.
So the first tutorial is going to be on Variables and there is going to be 3 parts 3 different ways on how to use Variables.
So lets get started :
The first thing i'm going to show you today is create a variable to store a number in.
The first thing you need to do then creating a variable is write out the type of data that you want to store inside of your variable and we want to store numbers inside of ours so i am going to write out an int and give that int a name and a value.
So after you have done that this is what your code should look like :
#include <studio.h>
#include <stdlib.h>
int main()
{
int myFistNumber = 5;
return 0;
}
The 5 is the value and the myNumber is the name. So now every time you want access to the value of in my case the number 5 all i would have to type out is "myNumber" instead of typing out the number 5.
Now lets create another int that stores another number in it.
So after you have done that this is what your code should look like :
#include <studio.h>
#include <stdlib.h>
int main()
{
int myFistNumber = 5;
int mySecondNumber = 9;
return 0;
}
Now lets create a 3rd variable that is equal to the sum of my first number and my second number.
So after you have done that this is what your code should look like :
#include <studio.h>
#include <stdlib.h>
int main()
{
int myFistNumber = 5;
int mySecondNumber = 9;
int myThirdNumber = myFistNumber + mySecondNumber;
return 0;
}
So now the value of my third number is the sum of myFistNumber and mySecondNumber so the value of my third number is going to be 14 since the sum of my fist number and second number is equal to 14.
So now i am going to show you how to print out the vaule of myThirdNumber onto the screen and to do that we are going to put :
#include <studio.h>
#include <stdlib.h>
int main()
{
int myFistNumber = 5;
int mySecondNumber = 9;
int myThirdNumber = myFistNumber + mySecondNumber;
printf("%i", myThirdNumber);
return 0;
}
We put the %i because we are printing out an integer.
We can put any amount of text before the %i so we could put : the value of my myThirdNumber is %i and where the %i is will be the sum of your first and second number so when we run it it will look like :
[ Register or Signin to view external links. ]
That is it for this tutorial hope you learned something from this.
Ratings
Comments
NissanPosted:
TTG_DIGITAL I love looking at your programming tuts. I always refer to it when I am doing small projects
Thanks for the feedback.
TTG_DIGITALPosted:
I love looking at your programming tuts. I always refer to it when I am doing small projects
Related Tutorials
- 01. Emulating Xbox 360 on PC for Running COD4 With Mods(3,656)
- 02. How to: Matrix Numbers | Batch File(1,954)
- 03. How to Password Protect Files on Windows(865)
- 04. How to play Socom 2/3/ and Combined Assault on PC(6,879)
- 05. Modern Warfare 2 Vac Ban Bypass Tutorial(6,243)
- 06. How to embed an image on TheTechGame(3,140)
- 07. [PC] NIOH 2 OTHER USER SAVE RESIGN(13,088)
- 08. Host bot lobbies! Full Tutorial!(11,611)
- 09. Unban yourself [Plutonium BO2](14,308)
- 10. Fall Guys - How to Change Your Name Color on Fall Guys(8,410)
- 11. Best Crosshair Settings for Valorant(6,550)
- 12. Othercide The Surgeon Boss Guide(2,568)
- 13. Othercide Remembrances Unlock Guide(4,517)
- 14. Othercide Beginners Tips and Tricks(2,734)
- 15. How to Fix Grounded Crashes, Loading Time, Low FPS and Other(4,881)
"C Programming Tutorial 1, Variables part 1" :: Login/Create an Account :: 4 comments