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:
- It is more fast and efficient.
- It is highly portable.
- It is ability to extend itself.
- It is robust language and high strength to built a function.
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:
- Letter: uppercase A to Z, lowercase a to z.
- Digit: all decimals digit 0 to 9.
- White spaces: enter, tab, space etc are white spaces.
- Special characters: some special character is given below:
- % percent sign
- $ dollar sign
- & ampersand
- , comma
- ( Left parenthesis
- ~ Tilde
- ) Right parenthesis
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:
- Naming always starts from alphabet. Such that Anil, ram etc.
- Digit can be use after alphabet. Eg.: anil123 , ram01 etc.
- Naming is case sensitive.
- Special character is not using except underscore.
- Naming is not exceed 32 characters.
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 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, 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 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 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 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:
- Labeled Statements: statements with labels, which are ended with a colon, are labeled statements.
- Expression statements: consists of an expression followed by a semicolon.
- 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.
- 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.
- 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 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:
- Unary operator: the operator which is acted upon only one operands is called unary operator. Eg: ++1, ++a, +4,- 3 etc.
- Binary operator: the operator which is acted upon two operands is called binary operator. Eg: 1 + 2, a -b etc.
- Ternary operator: the operator which acted upon three operands is called ternary operator. Eg: 1 + 2 + 3 .
on the basis of action
- 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.
- 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.
- Logical Operators: used for logical operations and combine multiple conditions into one. AND (&&), OR (||) and NOT (!) are logical operators.
- 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.
- 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.
- 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)
- 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.