Variables and Keywords in C

ProgrammingServer Side ProgrammingC

Variables

In C language, variables are the storage place where some form of data is stored. Different variables require different amount of memory on which a set of operations is applied.

A variable name cannot start with a number. It can consist of alphabets, number, underscore “_”.

Here is the syntax of declaring variables in C language,

type variable_name;

Here is the syntax of multiple variables declaration in C language,

type variable_name1, variable_name2,variable_name3;

The following is an example of variables in C language,

Example

 Live Demo

#include <stdio.h>
int main() {
   char a1 = 'H';
   int b = 90, c = 150;
   float _d = 3.4;
   printf("Character value : %c\n",a1);
   printf("Integer value : %d\t%d\n",b,c);
   printf("Float value : %f",_d);
   return 0;
}

Output

Character value : H
Integer value : 90150
Float value : 3.400000

Keywords

Keywords are predefined, reserved words in C language and each of which is associated with specific features. These words help us to use the functionality of C language. They have special meaning to the compilers.

There are total 32 keywords in C.

autodoubleintstruct
breakelselongswitch
caseenumregistertypedef
charexternreturnunion
continueforsignedvoid
doifstaticwhile
defaultgotosizeofvolatile
constfloatshortunsigned

Here is an example of keywords in C language,

Example

#include <stdio.h>
int main() {
   // char, int and float are keywords and used as datatypes
   char c = 'H';
   int b = 6, c;
   float _d = 7.6;
   // if and else is a keyword checking the value of b
   if(b<5)
   printf("Character Value : %c",a1);
   else
   printf("Float value : %f",_d);
   return 0;
}

Output

Float value : 7.600000
raja
Updated on 24-Jun-2020 10:52:39

Advertisements