Friday, 24 June 2016

VARIABLE AND CONSTANTS


VARIABLE AND CONSTANTS





Variable:-                                                            

                    Variable is data name that are stored in the memory. A variable have two values that is rvalue and lvalue. The Meaning of rvalue is the real value of the variable and the lvalue is the location value of the variable where the variable is saved.

Example:- a=30,b=54,x,y,z;

          100                    102                      104                               106                     108
       30

             54


          a                         x                        b                                 y                             z
here ‘a’ is a variable
 rvalue of a = 30
 lvalue of a =100   
       same as
 rvalue of b = 54
 lvalue of b = 104.




Declaration:-

                     If you use a variable in C , we must first declare it specifying which data type we want it to be. The syntax to declare a new variable is to write the specifies of the desired data type- followed by a valid variable identifier.

For example:          Data type variable_name;

                               int x;

                               float myid;

These are two valid declarations of variables. In first example declares a variable of type int with the identifier x and the second one declares a variable of type float with the identifier myid. Once declared, the variable x and myid can be used within the rest of their scope in the program.

If you are want to declare more than one variable of the same type, you can declare all of them in a single statement by separating with commas.

For Example:-                    int x,y,z;



Initialization:-

                           When declaring a regular local variable, its value is undetermined by default. But if you want a variable to store a concrete value at the same moment that it is declared. In order to do that, you can initialize the variable.

Syntax-    type identifier= initial_value;



Example int x=0;







Constants:-

               Constants are the expression with the fixed value which does not changes during the execution of the program.

  1. Integer Numerals- Numerical constants that identify integer constant.
    int a=2;
  2. Floating point numbers- decimals
    Float e=28.3;
  3. Character and string literals- non-numerical constants,
    ‘d’
    ‘g’
    “Hello world”
    “How you feel know?”


Note:-

   The first two expressions in ‘ ’ represent the single character and other two expressions in “ “ represent the string literals bundle  of several character.

             If you want to represent a single character than we us single quote (‘) and when we express a string than we use double quote (“).





Declared constants (const) :-

    With the ‘const’ prefix you can declare constants same as the variable.

Syntax- const type identifier= initial_value;



Example- const int p=5;

                const char ch=’y’;

 Here the value of p=5 is fixed for whole program, it doesn’t modified while execution. Same as ch.



                                        Thank you




Friday, 17 June 2016

Keywords and Identifiers

Keywords and Identifiers



 



In this tutorial, you will learn about Tokens (keywords, identifiers,
Strings, Operators), Character set, etc.

Character Set:-
C has the rich set of character that are Litters (A-Z), Digits (0-9), special character ({}, [], , .,etc).

Letters

Uppercase: A  B  C-------------------X  Y  Z
Lowercase: a  b  c--------------------x  y  z

Digits
1  2  3  4  5  6  7  8  9  0

Special Characters

        +

       <

         >

       .

       -

     )

         (

       ;
       

       &

       :

       %

       }

       {

       #

       ?

      

      $

     [

       ]

      

       ^

         !

       *

      \

       |

       _

        /

         ~

        ,


White space Characters
New line, Horizontal tab, Carriage returns and black space.


Tokens:-
As we know the smallest individual units in a program are known as tokens.
C has the following tokens:-
  • Keywords
  • Identifiers
  • Constants
  • Strings
  • Operators

A C program writing using these tokens, white spaces and the syntax of the language .

KeyWord:
                      They are reserved identifier and cannot be used as variable names. The keywords in C are:-
                                       Keywords of C
auto
double
int
struct
Do
if
static
while
Default
goto
sizeof
volatile
Continue
for
signed
void
Const
float
short
unsigned
Char
extern
return
union
Case
enum
register
typedef
Break
else
long
switch

There are several numerous keywords depending upon the compiler.

Example:-
int ashu;
Here, int is a keyword that indicates ‘ashu’ is a variable of type integer.




Identifiers:-
                         Identifiers refer to the name of variables, function, array, and structures etc, created by the user. They are fundamental requirement of any language. Each language has its own rule to identifiers. Some rules in C are given below:-
  1.              A valid identifier is a series of one or more letters, digits or underscores characters.
  2. Neither spaces nor punctuation marks or symbols can be part of an identifier.
  3. Only letters, digits and single underscore characters are valid.
  4. Variable identifiers always have to begin with a letter.
  5. They can also begin with an underline with letter.


Important:
              The C language is a case sensitive language. It means let we have two identifiers which have same name but one is written in capital letters and another in small is not equivalent. Thus, for example, the HAPPY variable is not the same as the happy variable or the Result variable.


 

Saturday, 11 June 2016

C Introduction


 C Introduction


 Hello friends, today we studied about the C language and their features. C is a high level language that was developed by Dennis M. Ritchie for developing the Unix os(operating system) in 1972.
Due to several reasons listed below, C; now become one of the professional language and most of the UNIX application programs have been written in it.
  • learn easily
  • Structured language
  • efficient programs
  • handle low-level activities
  • complied on a variety of computer platforms
    Facts:
  • C is used to write the code of an operating system called UNIX.
  • C is an Advance of B language.
  • Use ASCII character codes.
  • Most of software is formed in C.
  • Linux os and RDBMS mySQL have been written in C.

    Adopted as a system development language because it runs code fast.
    Some example of the use of C might be-
  • Database
  • print Spoolers
  • Network Drivers
  • Advanced  programs
  • Language Interpreters
  • Text Editors
  • Language compilers
  • ‎Assembler

This introduction of c is useful for beginners who do not have any ideas or little knowledge about computer programming.


C Programs
A C program can be written into one or more text files with extension ”.c” (for example hello.c). you need “vi”,”vim” or any other text editor to write your c Program.
Getting started with C....
To run a C program, you need a compiler .That check the error of your program.
Compiler changes the code that written by programmer (source code) to the code that understands by computer (object code) and creates executable file.   

There are many compilers are available in free of cost .for the sake of course, Turbo C++(Click on it to download the compiler/software) compiler is used.
                                               
                                             Happy coding
                             (If you have any questions regarding this post please comment us)