Start your Journey with C | Part 2

3.Elements :

Elements helps to create C Program. These are as follows :

Alphabets :

A to Z
a to z

Digits :

0 to 9

Special Characters :

Character  |     Meaning______
   +           plus sign 
   
   -           minus sign

   *           asterisk  

   %           percent sign

   \           Backward slash

   /           forward slash

   <           less than sign

   >           greater than sign 

   =           equal to sign

   _           underscore

   (           left parenthesis

   )           right parenthesis

   {           left braces

   }           right braces

   [           left bracket

   ]           right bracket   

   ,           comma

   .           period

   '           single quotes     

   "           double quotes  

   :           colon  

   ;           Semicolon    

   ?           Question mark 

   !           Exclamation sign    

   &           ampersand 

   |           vertical bar
 
   @           at the rate

   ^           caret sign 

   $           dollar sign

   #           hash sign      

   ~           tilde sign

   `           back quotation mark 

Escape Sequence  : 

\b - Backspace - Moves the cursor one step back.

\a - bell - It produces a beep alert sound.

\r - carriage return - Moves the cursor at the beginning of the line.

\n - newline - Moves the cursor to the next line.

\f - form feed - Moves the cursor to the initial position of the next line

\0 - null - Null

\v - vertical tab - moves the cursor to the next vertical tab position.

\t - horizontal tab - moves the cursor to the next horizontal tab position.

\\ - backslash - Presents a character with backslash

 

         Code of all escape sequence :

#include<stdio.h> 

int main()
{   
    // \b escape sequence

    printf("I live in    don.\b\b\b\b\b\b\blon");
    
    //  \a escape sequence 
    
    printf("This is an alert!!! \a");
    
    // \r sequence 
    
    printf("    bye\rgood");
    
    // \n sequence
    
    printf("mary. \nJohn. \nHarry. \nDev.");
    
    // \f sequence
    
    printf("a\fb");
    
    // \0 sequence
    // Here, each zero is octal digits.
    
    char* s = "A\0725"; 
    printf("%s", s); 
    
    // \f sequence

    printf("I\v am\v very\v happy.");
    
    // \\ sequence
    
    printf("dd\\mm\\yyyy");
    
    return 0;
}

Delimiters :

Delimiter are used in C Language such as :

; - semicolon - end of a statement

 printf(".....");
{} - curly braces - block of a statement

void main
{
.......
.......
}
[] - square bracket - use to create array

int a[20];
() - parenthesis  - expression type of statement 

printf(".....");
# - hash - it is used in preprocessor command.

#include<stdio.h>
 ,- comma - declaring variables

 int x,y,z;
: - colon - labeling purpose 

 printf(c=a>b?a:b);  //conditional operator   

Reserve Words / Keywords :

Keywords are the predefined reserved words in programming which indicates or give a different or spacial message to the compiler when you run a program. It is reserved and cannot be used as identifier or variables. For example :
int sum;
float length;
char name;
Here, int, float and char are the keywords and sum, length and name are the integer variable.
C language is case sensitive, all keywords are written in lower case.

here is the table of all keywords present in c language :-

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

Identifiers : 

Identifiers are the names other than any keywords which identifies or indicates to something such as structure, variable, functions, etc.

Names of the identifiers must be unique because one identifier can identify one thing at entire time. For example :
int marks;
float money;
char name;
int multiply();
 Here, marks, money, name and multiply are the identifiers of different data type and  function.

Data Types :

Data types are type of data entry or type of data perform while execution .For example
integer value , character value , etc. 
Data types are two types:
  1. Primitive:  

        Primitive Data Type are the essential and basic data type which are use to build program. These are :                                                                                                                             
     Primitive Data Type  Format     Specifier
     integer   int   %d
     character   char   %c
     float   float   %f
     double   double   %lf

                                                        
  2. Non primitive: 

     Non primitive Data are use after primitive data type. These are 

    • Arrays
    • Structure
    • Union
    • linked list
    • Stacks
    • Queue 
    • etc

                              Some Qualifiers of primitive Data Type: 

  Type                        Size                          Limit                   Format Specifier

short int 2 -32,768 to 32,767 %hd
unsigned short int 2 0 to 65,535 %hu
unsigned int 4 0 to 4,294,967,295 %u
int 4 -2,147,483,648 to 2,147,483,647 %d
long int 4 -2,147,483,648 to 2,147,483,647 %ld
unsigned long int 4 0 to 4,294,967,295 %lu
long long int 8 -(2^63) to (2^63)-1 %lld
unsigned long long int 8 0 to 18,446,744,073,709,551,615 %llu
signed char 1 -128 to 127 %c
unsigned char 1 0 to 255 %c
float 4 %f
double 8 %lf
long double 12 %Lf

Variable :

 Variable is a name that can be -used to store values.

     Declaration of variable:

          Declare a variable before it is used in the program. Declaration of a variable      specifies it name and datatype. Ex- int x;

     Initialization of variables:

          Assign some initial value to the variable during the declaration itself.Ex- int x=7;

Statements:

  • Expression statements( int 1=4, b=2, h=3; )
  • Compound statements( fun( a , b ); )
  • Selection statements (if, if. .. else, switch)
  • Iterative statements (for, while, do, ..while)
  • Jump statements ( goto, continue, break, return)
  • Label statements ( case, default, label statement used in goto )

Comments :

In programming, a comments is an annotation or explanation for programmer to understand what is a program all about. 

It comes handy while writing a long program, you can make a short elaboration of a piece of a program. Later you can read the comment and quickly understand what this part of the program does.

In C language, there are two types of comments :
  1.  Single line comment.
  2.  multi-line comment.

// single line comment :

 With this double forward slash ( // ), you write a single line comment in your program.

/* multi-line comment  */

With this multi-line comment, you can write comment which needs multiple line. you can start it by writing " /* " and all the line after this will be counted as comment until you end it with " */ " .
-----------------------------------
 Start your Journey with C | part-1

Comments

Popular posts from this blog

Print name in a pattern | name as abbreviation | C-Program

Print Fibonacci Series using Recursion | C program :