C++ Programming Language is better than C Programming.
C is the basic programming language.
C is a programming language developed at the Bell Lab of USA in 1972. It was designed and written by a man named Danish Richie. C become too much popular because it is reliable simple portable and easy to use. It is not tied to any one operating system or machine. It is also called system programming language because it is useful writing compiler and operating system. It has been used to write major program in many different domain.The first major use of the C was to write an operating system known as UNIX. UNIX is the most widely used operating system for all varieties of computer. Current popularity of C is due to its efficiency and its connection to UNIX. Many program used by UNIX are written in C.
Important of C:
- It is a simple and easy language with rich set of in build functions.
- Program written in C are efficient and fast.
- It is highly portable language.
- Major parts of popular operating system like windows, UNIX, Linux etc. are still written in C.
- It is also used to write programs for mobile or any other micro-processor based system.
- Provide easier way to handle hardware devices.
Variable and Constants:-
Variable:In C, quantity that may change during program execution is called variable. A variable may take different value at the different time during the execution of the program. Variables are the name to give in the memory of the computer where different constants are store. These location can contain integer, real or character constant. A variable name can be given by the programmer in a meaningful way so as to reflect its function or nature in the program. The syntax for the variable declaration is data type variable1, variable2……….;
Example x, y Average, sum;
Rules for the constructing variable Names:
- A variable name is any combination of alphabets, digits or underscore.
- The first character in the variable name must be alphabet or underscore.
- No commas or blank spaces are allowed within variable name.
- No special symbol other than underscore can be used in a variable name.
- A keyword can’t be used as a variable name.
- Uppercase and lowercase letter are different.
- Length of variable names are compiler dependent.
Constants: A quantity that do not change during the execution of a program is known constant.
Example: 100, 17.95,
Types of constant
Primary Constant:
- Integer
- Floating Point
- Character Constant
- Secondary Constant
- Array
- Structure
- Union
- Primary Constant: An integer constant is a sequence of digits without decimal points.
Example: 500, 175, 1000
Rules of constructing integer constant
- An integer constant must have at least one digit.
- It must not have a decimal point.
- It can be either positive or negative but default sign is positive.
- No commas or blank spaces are allow within an integer constant.
- The range value for the integer constant is -32768 to 32768.
- Floating point(real) constant: Numeric constant that contain decimal point are called real constant or floating point constant. Example 174.45, 955.00, 1000,54
Rules of constructing Real constant:
- A real constant must have at least one digit.
- It must have a decimal point.
- It could have a decimal point either negative or positive but default sign is positive.
- No commas or blank spaces are allow within real constant.
- The range value for the real constant 3.4e38 to 3.4e38.
- Character constant: A constant that contains a single alphabet or a digit enclosed within single inverted commas is called character constant.
Example: ’a’, ‘5’, ‘+’, ‘=’
Rules of constructing character constant:
- A character constant must be as single alphabet, a single digit or sinlge special symbol enclosed within single inverted comas.
- Both the inverted commas of a character constant can be one character.
- Data Types: Data types are the keywords that are used to define the type of the value that a variable can store. All C compiler support three fundamental data types , they are integer (int), floating point(float) and character(char).
- Integer data types: This type of data can hold numeric values without decimal point or fractional part. The size of integer data type depend on the operating system used. It occupy 2 byte in 16 bit operating system and 4 byte in 64 bit operating system. C has three classes of integer storage name short int , int and long int both in signed and unsigned form.
- Floating point: It is a data type which holds decimal part as its value. They occupy 4 byte space in both 16 bit and 64 bit operating system. Floating point number are defined in C by the key word float. The extended form of floating point data are double and long double.
- Character Constant: This type of data can hold single character and enclosed within the single inverted commas. It occupy 1 bit space in memory of computer.
- Operator:
An operator is a symbol that tells the computer to perform certain mathematical or logical operation. Operators are used in program to manipulate data and variables. C supports different types of operations they are :
2. Arithmetic operator:
Operators that are used for arithmetic calculation are known arithmetic operators. C provides all the basic operators. They are listed below
Operator Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
% Modular division
3) Relational Operator:
The operators that are used to compare quantities are called relational operators. The different types of relational operators used in C are as follows:
Operators Meaning
> is greater than
>= is greater than or equal to
< is less than
<= is less than or equal to
== is equal to
!= not equal
4) Logical Operators:
Logical operators are used to combine two or more relational operators i.e to test more than one condition simultaneously. The different type of conditional operators are used in C are as follows:
Operators Meaning
&& logical AND
|| logical OR
! logical NOT
5) Assignment Operators:
Assignment operators is used to assign the result of expression to a variable is ‘=’. In addition C has a shorthand set of assignment operators of the form.
Vop=exp
Where v is variable , op an arithmetic operator and exp is an expression.
Example: a= a+1 is equivalent to
a+=1
6) Increment and Decrements operators:
C has two very useful operators that not generally found in any languages. These are the increment(++) and decrement(--) opeartors. The operators ++ increment the value of operand involve by one and the operand – decrement the value of operand involve by 1. Both are the unary operators and take the following form:
++m, m++
--m, m--
The prefix operator increment the value before statement execution and the postfix operator increment the value after the statement execution.
7) Conditional Operator:
A ternary operator pair?: is available in C to construct the conditional exp of the form exp?exp2:exp3 where exp1, exp2, exp3 are the expressions exp1 is evaluated first, if it is non zero than thte exp2 is evaluated and become the value od expression. If exp1 is false than exp3 is evaluated and its value becomes the result
X=5
Y=5
Z=x>x:y
8). Bitwise operator:
Bitwise operators are the operators for the manipulation of data at bit level. These operators are used for testing the bit or shifting them right or left. Bitwise operators may not be applied to floating point data. The Bitwise operator and meaning are as follows:
Operators Meaning
& Bitwise AND
|
| Bitwise OR
<< Bitwise shift left
>> Bitwise shift right
7) Special Opearators:
C support some special operators such as comma operator, size of operator , pointer(& and *), member selection operator(. and ->). Comma operator can be used to link the related expression is a compile time operator and is used for dynamic memory allocation.
Keywords:
Keywords can be used defined as reserved words and they can’t be used as names or other user program user elements. Keywords are just like valid words in any language. The meaning of keyword has already been given to the compiler. Example int, char, float, if , else, break, continue, for, while, do, case, etc
Identifiers:
Identifiers can be defined as the names of variables, functions, array, structure etc created by program. They are the fundamental requirement of any language. Identifiers are used to give unique names to the objects in the program. Keywords can also be considered to else identifiers but they are used for every special meaning. Example function name, Array name, Structure name etc.
Rules for naming identifiers:
- An identifiers is name any combination of one or more letters or digits.
- The first character in the identifier must be a letter.
III. It must not contain any character other than letters or digits.
- The underscore is taken as a letter.
- Identifiers may have any numbers of letters and digits.
- Uppercase and lowercase letters are different.
Comment:
A comment is a non-executable statement that give information about the purpose of particular variable or function in ac C.
Comments are two types:
- Single comment(//)
- Block comment(/*……………….*/)
Example: //Welcome to C programming.
/* This comment
Contains a number of
Lines.*/
Header Files:
Header files are the file containing standard library functions. They have extensions .h .When we include header file, it indicate that they should be included at compilation. Generally header file are kept at the top of program.
Example: math.h, conio.h, stdlib.h, graphics.h
Format Specifier:
Format specifier are the character starting with % and followed with a character. It specifies the type of data that is being processed. It is also called conversion specification. Some data type and their specifier are give below:
Data types Format Specifier
Integer %d
Unsigned integer %u
Long integer %/d
Float %/f
Double %lf
Character %c
String %s
Simple Input / Output functions in C:
There exist several functions in C which can be used to perform input/output operation. These function are collectively known standard input/output library and are pre-defined in special file called header file.
- The printf():
This function is used to display formatted output on the screen. It is defined in the header file stdio.h and can be used in two ways:
printf(“Any text message”);
printf(“format specifier”, variable list);
Example:
main()
{
printf(“Welcome to C program”);
}
The scanf() function:
This function is use to receive input through the keyboard. It is also used defined in the header file. Stdio.h. The general syntax of scanf() function is:
Scanf(“format specifier”, variable list);
Example:
main(){
int x;
scanf(“%d”,&x);
printf(“%d”,x);
No comments:
Post a Comment