Tutorial 2: Variables and Data Types

Variable is a memory location that can store a value. The stored value can be retrieved or modified when necessary. Initialization of a variable means a value is given to the variable during its declaration. When a variable is declared, its name and data type are specified.A variable name can contain letters, digit and underscore (_). It cannot begins with a digit. C is case sensitive, therefore v and V are considered two different variable names. Its data type is given to specify what type of data can be stored in the variable. There are four basic data types in C programming language: int, float, double and char. Each data type has its own size. The size of a variable is the memory space allocated in the memory required to store its value. The following example demonstrates on how to declare a variable for each data type.
#include <stdio.h>

int main()
{
 int num1;
 float num2;
 double num3;
 char letter;
 
 return 0;
}
The statements declare four variables of types int, float, double and char with the name of num1, num2, num3 and letter. Now that we have declared the variables, lets look at how to initialize them.
#include <stdio.h>

int main()
{
 int num1;
 num1 = 5;
 
 float num2;
 num2 = 2.5;
 
 double num3;
 num3 = 125.24683579;
 
 char letter;
 letter = 'a';
 
 return 0;
}
We use '=' (assignment operator) to initialize the variables such as the value of 5 into variable num1. We could also perform the declaration and initialization on a single statement. This is demonstrated in the following program.
#include <stdio.h>

int main()
{
 int num1 = 5;
 
 float num2 = 2.5;
 
 double num3 = 125.24683579;
 
 char letter = 'a';
 
 return 0;
}

7 comments:

Anonymous said...

gud

Techbee web Solution said...

am a beginner to C Programming Language, Good Post
C Tutorial For Beginners

Unknown said...

Hey admin,
of course this blog is doing a very good job of serving useful information. I'm proud to be a part of its Readers community.
for more programing visit my web
http://www.hhhprogram.com/

kishan said...

hi dude i am visit you site and its relay very very nice.
I have one site but i am in some trouble not more visitor in my site, so please tell me what am i do for more visitor.
http://www.freesoftwaredownloader.com

Unknown said...

Hey dude Thank you for this awesome article on C.
please post an article on Simple Calculator in C

M@k said...

Nice article man. I hope I will get a Good Results 2014 out of this piost

Unknown said...

i feel proud to be a meber of this site.

Post a Comment