• USA : +1 973 910 5725
  • INDIA: +91 905 291 3388
  • info@tekslate.com
  • Login

Declare variables in C

Variable declarations : –

Name of the memory location is called variable

Generally when we required to change the data of the time of execution then we need to go for variable,

  • Before using any variable in the program, it must be declared first
  • Declaration of variable means require to specify data type, name of the variable followed by semicolon(;)
  • In ‘c’ programming language, variable declaration must be exist top of the program after opening the curly brace before writing first statement.
  • In variable declarations, name of the variable must be starts with alphabet or ‘_’(underscore) only.
  • Maximum length of the variable name is “32” characters, After 32 characters, compilers doesn’t consider remaining characters.
  • In variable declarations, existing keywords, operators separators and constant values are not allowed.
  • In variable declarations, at least single space should be required b/w data type & name of the variable.
  • When we are declaring multiple variable of same datatype, we use “’” as separator.

 

Syntax:-

Datatype variable;

Datatype var1,var2,var3;

  1. Inta; error
  2. Int a_ Error
  3. Int a;
  4. Int a b c; Error
  5. Int a,b,c;
  6. Int 1a,1b,c1; Error
  7. Int a1,b1,c1;
  8. Int abc,d;
  9. Int if; error10.
  10. Int If; yes
  11. Int If; yes case sensitive
  12. Int if., yes
  13. Int if; yes
  14. Int total-sal; error
  15. Int 1,2,3; error
  16. Int -1,-2,-3,yes
  17. Int -.,yes

 

Void main()

{

Int I;

Float f;

I=5/2;

F=5/2;

Printf(“%d  %f”,I,f);

 

}

o/p:  2   2.000000

 

Value Int Float
Gr Gr
5/2 2 2.000000
5.0/2 2 2.5
5/2.0 2 2.5
5.0/2.0 2 2.5
2/5 0 0.0
2.0/5 0 0.4

 

 

 

Operator behaviour is always variable independent i.e Acc to the variable type, the behaviour of the operator will not be changed.

  • Always the operator behaviour is operand dependant only
  • e depends on the i/p data, the behaviour of the operator will change
  • Always return value behaviour is variable dependant only. i.e depends on the variable type automatically return value will converted.
  • In implementation, when operator is returning an integer value, we require to assign the data to float variable, then automatically data will be converted into float format by adding “.0”
  • Whenever the operator i.e returning float value and we require to assign an integer variable then decimal point only require to assign.

 

By default, whenever we are declaring any variable, it bolds garbage value initially

Summary
Review Date
Reviewed Item
Declare variables in C
Author Rating
5

“At TekSlate, we are trying to create high quality tutorials and articles, if you think any information is incorrect or want to add anything to the article, please feel free to get in touch with us at info@tekslate.com, we will update the article in 24 hours.”

0 Responses on Declare variables in C"

Leave a Message

Your email address will not be published. Required fields are marked *

Site Disclaimer, Copyright © 2016 - All Rights Reserved.