Variables in C Language

Variables in C Language:

(1) In C language when we develop or built logic, we need variables that store information like amount, string or character. For storing this type of information, the C language provides variables like int, float, and char. 

(2) Sample C language code using all variables and their output, as shown:

Sample C language code using all variables
#include <stdio.h>
#include <conio.h>
 
int main()
{
  int x;      // Declare integer variable
  float y;    // Declare float or decimal variable
  char z;     // Declare char variable
  char w[20];  // Declare string variable
  z = ‘F’;    //Assign the value to char variable
 
  printf(“Enter the value of x: “); //Asking for entering the value in output screen
  scanf(“%d”,&x);                   //Assign value in output screen
 
  printf(“Enter the value of y: “);//Asking for entering the value in output screen
  scanf(“%f”,&y);                  //Assign value in output screen
 
  printf(“Enter the value of w: “);//Asking for entering the vaue in output screen
  scanf(“%s”,w);                  //Assign value in output scree
 
  printf(“\n”);
  printf(“Value of x is: %d\n”, x); //Show Output of A
  printf(“Value of y is: %f\n”, y); //Show Output of B
  printf(“Value of z is: %c\n”, z); //Show Output of C
  printf(“Value of w is: %s\n”, w); //Show Output of D
 
  getch();
  return 0;
}

(3) After that go to the “Build” menu and select the “Build” option for publishing the code as shown.

click on build menu in codeblocks

(4) After building the code, press the “Run” button, as shown.

click on run menu in codeblocks

(5) After pressing the “run” button, the output screen is opened, then enter the values and then press the “Enter” button as shown.

enter values for varibale query in c language

(6) After entering the value, the system gives the output value, as shown.

output values of varibale obtained in c language

Note:

  • “Int” : It stores integer values without decimal. For storing or printing integer value, you must specify “Format Specifiers”. For “int” – “%d”.
  • “float” : It store decimals values.For storing or printing decimals value, you must specify “Format Specifiers”. For “float” – “%f”.
  • “char” : It store single character. For storing or printing values, you must specify “Format Specifiers”. For “char” – “%c” and for long string more than one character then use “%s”.
Data TypesSpecifiers
int%d
float%f
char%c
char (long string)%s

How to Create New Database in Microsoft SQL Server
How to Attach MDF file Without LDF File by using SSMS
How to Install SQL Management Studio
Use of SUBSTRING Function in SQL
SUBSTRING (Transact-SQL)– Microsoft Docs

Leave a Reply