knowledgediarybd.com

Your Virtual Knowledge Campus







C Programming Variable

c programming variables,c variableC Programming Variable or only Variables which  are essential components in programming. A variable that can hold a data when we want to execute a  c program. without variable we can not handle a lot of data in any programming.

Dear reader, here i will discuss details about  c programming variable  that will be helpful for your learning c  programming.

Variable:

To store data, different types of variable are used in C. A variable can store character, integer,

float or string type data. A variable must be declared before using it.

Syntax of declaring a variable in c:

<data type of variable> <variable name 1,variable name 2,….  ,variable name n>;

     Example:

                     int first_number, second_number;

                     char c;

                     float number;

Also a value can be initialized at the time of declaration of a variable.

          Example:

                     int payment=1000;

Rules of giving name of a variable

1. Variable name consists of letters (a-z and A-Z), digits (0-9) and underscore (_)

                Example: number, digit1, first_name

2. The first character of a variable must be a letter or underscore.

                Example: legal: payment, _details

                            illegal: 3due, 7fine

3. No other characters, spaces or special symbols are not allowed in C

                 Example: #name, first  name, +.temp are illegal.

4.  Anykeyword cannot be a variable.

                 Example:  int, float, main are illegal variable.

5.  Asis a case sensitive language so variable name is also case sensitive

                Example: x & X are not same, name and Name are not same variable.

6. Variables must be declared before use it.

Wrong variable declaration Example:

#include //for cout,cin etc.

int main()

{
printf( “Value of x is :%d”,a);//display prompt
int x=5; //variable name and type integer
return 0;

}

Correct variable declaration Example:

#include //for printf,scanf etc.

int main()

{

int x=5; //variable name and type integer
Printf(“Value of x is:%d “,x); //display value of int value x.

return 0;

}

if you want to run the above Two Program then you have to save as Like : “example.cpp” (cpp means c plus plusthen compile & run.

knowledgediarybd.com © 2017
shares