Operator and Expression chapter- 3

Introduction of c

C language and its features:

The c programming language is developed at bell laboratories of USA in 1972. It was written and designed by the dennis Ritchie. The features of c programming is given below:

  1. It is more fast and efficient.
  2. It is highly portable.
  3. It is ability to extend itself.
  4. It is robust language and high strength to built a function.

Character set

It is a collection of different symbol(digit, letter, special character) are used to building or developing a c program is called character set. All the element of program are made by using a character set. The character available in a c program are given below:

  1. Letter: uppercase A to Z, lowercase a to z.
  2. Digit: all decimals digit 0 to 9.
  3. White spaces: enter, tab, space etc are white spaces.
  4. Special characters: some special character is given below:
  • % percent sign
  • *Asterisk
  • $ dollar sign
  • & ampersand
  • , comma
  • ( Left parenthesis
  • ~ Tilde
  • ) Right parenthesis

Identifiers

it is a element of c programming which is used to naming purpose. It is used to give a names of various program element, variables, function, and arrays.
Rules of writing a name of identifiers:

  1. Naming always starts from alphabet. Such that Anil, ram etc.
  2. Digit can be use after alphabet. Eg.: anil123 , ram01 etc.
  3. Naming is case sensitive.
  4. Special character is not using except underscore.
  5. Naming is not exceed 32 characters.

Keyword

it is a collection of word in c program which meaning is not deviated or which meaning is fixed. Eg: while, if, if else, do while etc.

VARIABLES


variables are simply a named area of storage that can hold a single value. In C programming variables are needed to be declared before making any use of it.
int num; – declaration of an integer variable, with name num and data type int.
char ch; – declaration of a character variable, with name ch and data type char.

Symbolic constants


symbolic constants, conventionally written in uppercase, are the names which substitute a sequence of character that cannot be changed. The character may be a numeric constant, a character constant, or a string constant.
General Form : #define NAME VALUE
Example : #define PI 3.1416

DATA TYPE


Data type is an extensive system for declaring variables, and represents the type of data the declared variable will hold. The difference type of data type are given below:


• Fundamental data type:


• Integer Data Type:


Keyword int is used to represent integer data type which in general requires 2 bytes of memory (may vary from one compiler to another).
The range of an integer is limited from -32768 to +32767.
In general the range is given by -2n-1 to 2n-1-1, where n represents the no. of bits.
Different qualifiers can be applied to int varying the size and range of it.
If short int and int have same memory requirements (2 bytes) then long int will have double the requirements (4 bytes).
If int and long int have the same memory requirements (4 bytes) then short int will have half the requirements (2 bytes).
Signed int and int is similar with 2 bytes requirements and range is -32768 to 32767.
Unsigned int also require 2 bytes but range varies from 0 to 65535.
Unsigned qualifier can be applied to int as unsigned short int and unsigned long int.


• Single Precision Real Data type (float):


Keyword float is used to represent float data type which require 4 bytes of memory and the range is limited from -3.4e-38 to +3.4e38.
Floating point numbers are stored in 32 bits with 6 digits of precisions.
The precision describes the number of significant decimal places that a real value carries.
Qualifiers are not required to apply since long float is equivalent to double.


• Double Precision Real Data type (double):


A double precision number is required when very high precision is required i.e. accuracy of float is not sufficient.
Keyword double is used to represent double precision real data type.
A double data type requires 8 bytes of memory giving a precision of 14 digits and the range of -1.7e-308 to 1.7e+308.
Qualifier long can be applied to extend the range in case required.

• Derived data type:


• User defined data type:

QUALIFIERS

  • Qualifiers are keywords used to modify the attribute of any declared variable. Generally used qualifiers are sign and size along with const; sign qualifier includes signed and unsigned, size qualifier include short and long.
  • unsigned int count; – unsigned is a qualifier which makes the variable count – which is of integer data type- hold only positive values.
  • long double amount; – long is a size qualifier which increases the range of values that can be hold by variable amount which is of type double.


Statement


Statement is the smallest standalone element of an imperative programming language that expresses some action to be carried out. Different types of statements in C programming are:

  1. Labeled Statements: statements with labels, which are ended with a colon, are labeled statements.
  2. Expression statements: consists of an expression followed by a semicolon.
  3. Selection statements: the sub-statement of the selection statement will be executed only if the expression in selection statement is non-zero. If else and switch case are examples of selection statements.
  4. Iteration statements: the sub-statement of any iteration statement will be executed repeatedly as long as the control expression results in non-zero value. while loop and for loop are two examples.
  5. Jump Statements: changes the control of the program from one position to another within the same program. The goto, which is seldom used, along with break, continue and return statements are examples of jump statements.

Operator


operator is a symbol which is used to perform a logical and mathematical manipulation. The constants or variable which is acted upon operator is called operands.


On the basis of operands:

  1. Unary operator: the operator which is acted upon only one operands is called unary operator. Eg: ++1, ++a, +4,- 3 etc.
  2. Binary operator: the operator which is acted upon two operands is called binary operator. Eg: 1 + 2, a -b etc.
  3. Ternary operator: the operator which acted upon three operands is called ternary operator. Eg: 1 + 2 + 3 .

on the basis of action

  1. Arithmetic Operators: symbols or characters used for arithmetic operations such as addition, subtraction, division and so on. Few examples can be +, -, /, %, *. Division operator
    (/) gives the quotient after division while modulus (%) operator results in remainder after division. For eg: 5/3 = 1 whereas 5%3 = 2.
  2. Relational Operator: it provides the relation of two operands whether they are equal, greater or lesser and other possible relations. Few examples are > (greater), < (lesser), == (equal), != (not equal). If the relation is true then it results in non-zero value else results zero. If a = 4, b = 5 and c = a > b, then c= 0, for instance.
  3. Logical Operators: used for logical operations and combine multiple conditions into one. AND (&&), OR (||) and NOT (!) are logical operators.
  4. Assignment operators: Used to assign the result of an expression to a variable. It includes =, +=, -=, /=, %=. For instance, a = 6 uses = as an assignment operator. Also a % = b is equivalent to a = a % b.
  5. Increment and decrement operators: It increases or decreases the value of an operand by one. It includes ++ and –. If the operator precedes the operand then it is called pre increment or decrement whereas if the operand precedes the operator then it is called post increment or decrement. For example, a++ is post increment while –a is pre decrement.
  6. Conditional Operator: It is used to test a particular condition. Its general form is:
    variable = expression?expression1:expression2
    For example, x = a > b? a : b here, if the expression (a > b) is true then x= a (expression1) else x = b (expression2)
  7. Other operators
     Address operator (&): gives the address of an operand.
     sizeof operator (sizeof()): provides the size of the operand.
     dot operator (.): use to access the member in structure.
     Bitwise operator: for bitwise operations.

Type casting and type promotion:


The mechanism of converting the type of an expression into another type is referred as type casting. The process by which values of lower type are converted to higher type is type promotion.

Leave a Reply

Your email address will not be published. Required fields are marked *