Hey Guys,

In this article, I am going to talk about variables in C programming. Variables are basically placeholders for something else such as numbers, words or something else. Lets look at a sample which is not a code. For example, if you say
x= apple
I love 'x'
here you can see the logic of placeholders.
You can't start a variable with numbers. Moreover, you can't have space or any other weird sign such as dollar sign in variables. Don't name the variable like a function such as main or printf. First, you have to define a variable. For example integer.
Int main() {
int age;
age=25;
printf("Thileban is %d years old", age);
}

In this article, I am going to talk about variables in C programming. Variables are basically placeholders for something else such as numbers, words or something else. Lets look at a sample which is not a code. For example, if you say
x= apple
I love 'x'
here you can see the logic of placeholders.
You can't start a variable with numbers. Moreover, you can't have space or any other weird sign such as dollar sign in variables. Don't name the variable like a function such as main or printf. First, you have to define a variable. For example integer.
Int main() {
int age;
age=25;
printf("Thileban is %d years old", age);
}
Here we have included a variable for integers. The following is the output of this code.
Thileban is 25 years old
Here you can see that %d is replaced with 25. It is because we used integer as a variable in the input code.
There many different ways to use variables for example instead of saying age = 25. You can input the following.
#include<stdio.h>
int main() {
int age;
age=2018-1993;
printf("Thileban is %d years old", age);
}
Here I have input age=2018-1993 instead of age = 25 but the output didn't change. We will still get the same output as above which is
Thileban is 25 years old
Moreover, we can do the same thing in another way too by inputing this code with three variables.
#include<stdio.h>
int main() {
int age;
int currentYear;
int birthYear;
currentYear = 2018;
birthYear = 1993;
age = currentYear - birthYear;
printf("Thileban is %d years old", age);
}
For this one also the output is
Thileban is 25 years old
#include<stdio.h>
int main() {
int age;
int currentYear;
int birthYear;
currentYear = 2018;
birthYear = 1993;
age = currentYear - birthYear;
printf("Thileban is %d years old", age);
}
For this one also the output is
Thileban is 25 years old
Comments
Post a Comment