Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Expression

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 527
    Comment on it

    An Expression is a combination of operators, constants and variables arranged as per rules of language. It may also include function calls which return values. An expression may consist of one or more operators and zero or more operator to produce value.

    Types of expressions

    Expression may be of following four types:

    1.Constant expression.

    It produces an integral result after implementing all the automatic and explicit types conversions.

    e.g.

     m
       m*n-5
    
       m-'x'
    
       5+ int(2.0)

          where m and n are integral variables.

    2. Integral expression.

    3. Floating expression.

     After all conversion, these produce floating point results.

    e.g.   

    x+y
       x*y/10
    
      5+float(10)
    
      10.75

    4. Pointer expression.

    It produces address value.

       &m

      ptr  where m is variable and ptr is a pointer

     ptrH ptr is a pointer 

     "xyz"

    Conversion

    We can mix data types in expression 

                                                 m=572.75;

    is a valid statement.

    Whenever data type are mixed in an expression, C++ performs the conversions automatically.This process is called implicit or automatic conversion.

    Rule:"smaller" type is converted to the "wider" type.

    e.g. waterfall model. If one operator is an int and other is float, then int is converted into float because a float is wider than an int.

    Whenever a char and short int appear in an expression, it is converted into an int. This as called integral widening conversion.

    The implicit conversion is applied only after completing all integral widening conversions.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: