Types of C Variables

Variables are containers for storing data values.


We have different types of variables in C Programming language.

  • int- stores integers, such as 123 or -123
  • float- stores floating point numbers, such as 19.99 or -19.99
  • char- stores single characters, like as 'q' or 'd'. Char values are surrounded by single quotes

Code:


  #include

  int main()
  {
  int myInt = 15;
  float myfloat = 4.7;
  char myChar = 'a';
  printf("%d\n", myInt);
  printf("%f\n", myfloat);
  printf("%c\n", myChar);
  return 0;
}


Output

15

4.700000

a

Explanation:

In the main function,we declared int named myInt and assign value 15 to it (By using the syntax: type variableName = value;).

To print out variables in C, we use format specifiers
This is starts with a percentage sign %, followed by a character.
For example:
%d:for integers.
%f:for float.
%c for char.








© Copyright 2022 Advanced PLC. All rights reserved.