C103: Data types

variable is a memory location where program store values and later take that data to do process. To use a variable it must be declared, during declaration a variable or function we tell the compiler what is the name of the variable or function and also the type of data the variable can store or return.

Different data type has different size and type of data it can hold. there are numerical and textual data. Numerical data are integer and floating point values, textual is character

Keywords such as int, float, double, char and only for function void are used. The first keyword, int is whole number without decimal point. Float is for numbers with decimal point, double also for number with decimal point but  for more precision. Char for alphabet such as a to z, A to Z and symbols.

These are some examples of variable declaration.

int intNum;
float floatNum;
double doubleNum;
char charValue;

assignment statement is a statement containing equal sign. Its purpose is to assign value to a variable. A declared variable only has default value such is 0 for integer, 0.0 for floating point. Lets assign a value to the variable:

intNum = 5;
floatNUm = 5.3;
doubleNum = 12.43212;
charValue = 'A';

variable makes it easy to wrote program. rather than remembering memory address, it allows us to use the variable name when accessing this memory location. for example when display value of a variable on console

printf("%d", intNum);
printf("%f", floatNum);

also easy to use variables in arithmetic operations (add, minus, multiply, divide)

varA + varB
(varA - varB)/2

variable is what makes a program dynamic. in order to use the variable understanding type of data C program can handle is very important.

Comments

Popular posts from this blog

Drawing Simple Pie Chart

VB.net connecting to SQL Server

VB.net