C
The C programming language was originally developed by Dennis Ritchie of Bell Laboratories,
and was designed to run on a PDP-11 with a UNIX operating system. Although it was originally
intended to run under UNIX, there was a great interest in running it on the IBM PC and compatibles, and other systems. It allows the
programmer a wide range of operations from high level down to a very low level approaching
the level of assembly language. There seems to be no limit to the flexibility available.
IDENTIFIER
An identifier is used as name containing use of letters , numbers and a special character underscore ( _ ). It is used to identify variable , function , symbolic constant etc. Maximum 31 characters is used including letters , numbers and special character. It is case sensitive.
Ex: name , name_a , name_1 etc.
CONSTANTS
Any unchanged value in a program at the time of program execution are constants.
Numeric Constant: 25 - 40 , +30(decimal) , 043 , 039 , +04(octal constant) , 0x8a , +0x3(hexadecimal constant) , 0.343 , 2.343 (float value)
• Float value should also in octal and hexadecimal form supported by C language because C language support decimal , octal and hexadecimal constant values.
String Constant : “Sum of number is = “ , Total students are “ etc.
VARIABLES
A variable is an any name which is used to refer any value to it and it can change during program execution. It is also called an identifier and declared by using combination of letters , numbers and underscore ( _ ) starts with alphabet. Ex: x , sum , c34 , name_1 etc.
• Here small and capital letter two variables of same text is count as two variables.
DATA TYPE
There are four basic data types used in C language.
Data Type Size Value Range Value in decimal form
char 1 byte -27 to 2 7 -1 -128 to 127
int 2 bytes -2 15 to 2 15 -1 -32768 to 32767
float 4 bytes -2 31 to 2 31 -1 -2147483648 to 2147483647
double 8 bytes -2 63 to 2 63 -1 1.7e-308 to 1.7e+308
OPERATORS
Arithmetic operator
These operators are used to perform arithmetic or calculation type of work.In C language some arithmetic operators are as:
Operator Meaning Example Result
+ addition 5 + 2 7
- subtraction 5 - 2 3
* multiplication 5 * 2 10
/ division 5 / 2 2
% modulus operator to get remainder in integer division 5 % 2 1
Relational operator
Relational operators are used to compare between two values or expressions to produce a logical value which is either TRUE or FALSE. Some relational operators used in C language are as:
Operator Meaning Example Result
< less than 9 < 2 false
> greater than 5 > 2 true
<= less than or equal to 9 <= 2 false
>= greater than or equal to 5 >=2 true
== equal to 7 == 4 false
!= not equal to 5 != 2 true
Logical operator
Logical operator is used to add more relational operators to create a complex expression. Resultant value of adding to relational operator is logical i.e. TRUE or FALSE. Some Logical operators used in C language are as:
Operator Meaning Example Result
&& logical and ( 5<2) && (5>3) false
|| logical or (7<5) || (7>3) true
! logical not ( negation ) !(5<2) true
• Scanf( ) : This function is used to read values of any variable from keyboard.
Example: scanf( “%d “ , &a); # used to read decimal value
scanf( “%c ” , &b); # used to read character values
scanf( “%f” , &c); # used to read float values
scanf( “%s ” , &d); # used to read string values
• Printf( ) : This function is used to print values of any variable on monitor screen.
Example: printf(“ Hello how are you ? “);
Output : Hello how are you?
Printf( “ % d “ , a); (if a=5)
Output: 5
Printf( “ Value of a is = % d “ , a);
Output: Value of a is = 5 ………and so on
• getchar( ) : Used to read one character at a time from keyboard. Ex : char s;
s = getchar( );
• putchar( ) : Used to print one character at a time.
Ex : char d;
putchar( d );
• gets( ) : Used to read string of characters including blank spaces. Here note that blank space can not be read using scanf( ). Ex : char st[25]; gets( st );
• puts ( ) : Used to print character string. Ex: char str[25] = “ Good Morning”; puts (str);
• getche ( ) : Used to read a character from keyboard without waiting for enter key.
Ex : char letter; letter = getche( ) ;
• clrscr ( ) : Used to clear the screen. Syntex : clrscr ( );
No comments:
Post a Comment