Showing posts with label Operators. Show all posts
Showing posts with label Operators. Show all posts

Tuesday, April 7, 2020

OPERATORS IN C

Vibhor Sharma
OPERATORS IN C

OPERATORS  IN  C

    Operator  are  symbols  that  act  upto  data. They represent a paticular operation to be performed on the data. Operators can be classified as arithmetical, relation, and assigning operators.

     Arithmetical Operators :  These types of operators denote mathematical operators like – Add, Subtract, Multiple, Divide and Exponentiation.

Operator                    Function
 +                           Addition 

 -                         Subtraction   

 /                           Division  

*                           Multiplication

^                           Exponentiation

%                          Mod (Remainder of                             a division)

      Special Arithmetical Operators :  The - - and + + are known as           decrement and increment operators.
       For example :
x = x + 1;
is equivalent to
++x; or x ++;
Also
x = x – 1;
is equivalent to
- - a; or a - -;
Relational OperatorThese operator are used to compare two values on the basis of a certain condition.
Operator                          Function
       <                                   Less than
 <=                                Less than or equal to
 >                                  Greater than
  >=                               Greater than or equal to
 !=                               Not equal to
   =                                Equal to      
     Logical OperatorsThe logical operators are :
     Operators                                      Function
            &&                                            AND
            ||                                              OR
             !                                                NOT
     Assigning OperatorThe assigning operators are :
     Operators                                      Function
             =                                            Assign a value
            + =                                          Add the values and
                                                           assign it to the left
            - =                                          Sudtract the values
                                                          and assign it to the left
           * =                                           Multiply the values
                                                           and assign it to the left 
           / =                                           Divide the values and
                                                           assign it to the left
         % =                                          Find the remainder                                                                                    and assign it to the left
    Bitwise Operators :  The  Bitwise  Operators are applicable to the char and int data types only .These operators are not useful with float, double, long double, void or other complex data types.

CONSTANTS OF C

Vibhor Sharma
CONSTANTS IN C

CONSTANTS  OF  C

A constant is a quantity that doesn’t change in a program. This quantity can be stored at a location in the memory of the computer. ‘C’ constant can be divided into two major categories :

PRIMARY  CONSTANT

        Important Points for defining integer Constant
·        An integer constant must have at least one digit.
·        An integer must not have a decimal point.
·        An integer should be either positive or negative.
·       An integer constant does not allow any commas or blanks.
·       An integer constant allows within range from -  32768  to + 32767.
Important point for defining Real Constants
·     A real constant must have at least one digit.
·     A real constant have a decimal point.
·     A real constant should be either positive or negative.
·     Default sign is positive.
·     A real constant does allow any commas and blanks.

Important point for defining Character Constants

·     The character constant is either a single alphabet, digit or a single inverted commas. For example ‘A’ is not.
·     The maximum length of a character constant can be 1 character.


                                                                          

Monday, April 6, 2020

VARIABLES IN C

Vibhor Sharma
C-VARIABLES

VARIABLES   IN   C

‘C’ programs are variables, constants, arithmetic operator etc. A       variable in a program is a name to which you can associate a   value.The variables can play different roles in a program :

     Inside the function – local variables
     In definition of the functions – formal parameter
    Outside all functions – global variable
    Actual parameter – defined during invocation of function.

For example, with the name A you can associate , say a number 20, so that whenever the number A is called /used, you get the value 20.   

Local variablesThose variable, which are declared within the function are called local variables because scope of these type of declaration of variables only exist ot the function in which these are defined.

For example :
int add(void)
{
int x;
int y;
int s;
x = 10;
y = 20 ;
s = x + y ;
return(s);
}
int diff(void)
{
int x;
int y;
int d;
x = 10;
y = 20;
d = y – x;
return(d);
} 

In above program, the variable x, y and s are local because scope of these variables are only within the function add(void). Same variables x and y are declared at the start of the function diff(void). The local variables are declared at the start of the function body. These variables can be declared within code block.  

Global Variables :The scope of global variables remain in the entire program and these type of variables can be used by any piece of code. These variables hold their values 

For example :

int func (int, int);
void result (void);
int i = 40;
int sum;
void main ()
{
    int sum = 500;
    clrscr( );
    result( );
}
void result(void )
{
int output;
printf(“%d”, func(i, i);
output = i * func(i, i);
printf(“%d”, output);
}
int func (int x, int y)
{
sum = x + y;
return (sum);
}

Previous :- Operators in C


FEATURES OF C

Vibhor Sharma
FEATURES OF C

FEATURES  OF  ‘C’
  • The ‘c’ language possesses the features of both, low level and of high level languages.
  • The ‘c’ provides the facilities to do programming at register level which lead to fast programming.
  • The ‘c’ is very much closer to English language .
  • There are many functions used to performed desired operation in ‘c’.It is very independence of machine.
  • The ‘c’ is very close to man and machine ; it is called middle level language .
  • The program written in ‘c’ language are 100 % efficient and are also machine independent and portable. That’s why ‘c’ is of very great importance.

Previous :- C - learning

Next :- Operators in C 

Sunday, April 5, 2020

ARITHMETIC OPERATORS

Vibhor Sharma
ARITHMETIC OPERATORS IN C

Arithmetic operators

The Arithmetic operators perform Arithmetic operations . The arithmetic operator can operate on any built in data types. A list of arithmetic operator and their meaning are given below.
Operator                                                           Meaning
+                                                                Addition or Unary plus
–                                                                Subtraction or Unary minus
*                                                                 Multiplication
/                                                                 Division
%                                                                Modulo Division
This table shows the symbols of arithmetic, together with their duties. These operators allow you to write expressions whose evaluation is precisely the treatment of information that made the computer. Arithmetic operators, along with a wide range of features resident in the library of the language used make it possible to perform calculations of all kinds.
Suppose that a and b are integer variables whose values are 100 and 4, respectively. Several arithmetic expressions involving these variables are shown below, together with their resulting values.
Expression Value
a + b 104
a – b 96
a * b 400
a / b 25
a % b 0

C-Expressions

Vibhor Sharma
EXPRESSIONS IN C

Expressions

  • Expressions is a sequence of operators and operands that specifies computation of a value. An expressions may consist of single entity or some combination of such entities interconnected by one or more operators.
  • All expression represents a logical connection that’s either true or false.
  • Thus logical type expression actually represents numerical quantities.
In C every expression evaluates to a value i.e., every expression results in some value of a certain type that can be assigned to a variable. Some examples of expression are shown in the table given below.
A+b
3.14*r*r
a*a+2*a*b+b*b
C – EXPRESSION EXAMPLE PROGRAM :
Output:
Value of a = 123
Value of b = 125