mobileNavlogo
headerlogo

Declare variables in C

Blog Author

Tekslate

Published Date

21st September, 2018

Ratings

Views

262

  • Share this blog :

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

About Author
Authorlogo
Name

TekSlate

Author Bio

TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills .

Related Blogs

Write For Us