Variable Constants & Keywords in C

Variable Constants & Keywords in C


Variables :

A variable is a Container which stores a 'Value'.  like In Kitchen, we have containers storing Rice, Wheat, Sugar etc.  Similar to that Variables in C Stores value of a Constant
e.g.
      int a=3;          // a is integer and assigned as '3'
      float b=3.5      // b is Real No. which is assigned as '3.5'
      char x='A'       // x is a Characters which is assigned to 'A'


Rules for naming variables in C :

➔ First Character must be an alphabet or underscore(_)
➔ No Commas, blanks allowed
➔ No Special Symbol other than (_) allowed.
➔ Variable names are case sensitive
➔ We must create meaningful variable names in our programs. This enhances readability
     of our program

Constants

➔ An entity whose value doesn't change is called as a constant.
➔ A Variable is an entity whose value can be changed.

Types of Constant : 
➔ Integer Constant ➟  12, -2, 5, 8
➔ Real Constant     ➟  23.5, -423.32, 7.0
➔ Character constant ➟ 'a',  '$'  (Must be enclose within single quotes)


Keywords : 

These are reserved words, whose meaning is already known to the Compiler. 

There are 32 keywords available in C :
auto double         int               struct
break         long            else              switch
case          return         enum          typedef
char         register      extern         union
const         short      float          unsigned
continue    signed          for              void
default     sizeof         goto           volatile
do              static         if                 while


Basic Structure of a C Program ➟
➔ All C programs have to follow a basic structure.
➔ A C program starts with a main function and executes instructions present inside it
➔ Each instruction is terminated with a semicolon(;)


Some rules which are applicable to all the C programs 
➔ Every program execution starts from main() function
➔ All the statements are terminated with a semicolon 
➔ Instruction are Case-Sensitive
➔ Instruction are executed in the same order in which they are written

Comments ➟
➔ Comments are used to clarify something about the program in plain language.
      It is a way for us to add notes to our program.
➔ Comments in a program are not executed and are ignored.

There are two types of comment :
➔ Single line comment : 
// This is Single Line Comment

➔ Multi-line Comments : 
/* This is Multi-Line
     Comment        */

Compilation and Execution

A complier is a computer program which converts a C program into machine language so that it can be easily understood by the Computer.

A C program is written in plain text.
This plain text is combination of Instruction in a particular sequence. The compiler performs some basics checks and converts the program into an executable.

   first.c                                C Compiler                                       first.exe    
program in VS Code      (with gcc it compile the program)                 (gives output ) 


Library Functions : 
C language has a lot of valuable library functions which is used to carry out certain
tasks for instance printf function is used to print value on the screen

syntax : printf("This is %d", i);

➔  %d for integers
➔  %f for real numbers
➔  %c for character

Types of variable :
➔ Integer variables      int a = 3 ;
➔ Real variables          float a = 5.3 ;
➔ Character variable ➟   char a = 'A' ;

Syntax :
# include<stdio.h>
// Lets learn about Variables in C Programming Language
int main(){
    int age = 22 ; // integer variable
    int class = 12 ;
    printf("Hey Dude! I'm %d Years old \n"age);
    printf("and I'm in class : %d"class);
    return 0; }





Instagram : @akashmacskill


Disqus Comments