The C Character Set
A character denotes any alphabet, digit or special symbol used to
represent information. Figure shows the valid alphabets,
numbers and special symbols allowed in C.
C-Language keywords
Types of C Constants
C constants can be divided into two major categories:
(a) Primary Constants
(b) Secondary Constants
Rules for Constructing Integer Constants
(a) An integer constant must have at least one digit.
(b)It must not have a decimal point.
(c) It can be either positive or negative.
(d) If no sign precedes an integer constant it is assumed to be
positive.
(e) No commas or blanks are allowed within an integer constant.
(f) The allowable range for integer constants is -32768 to 32767.
Rules for Constructing Real Constants
Real constants are often called Floating Point constants. The real
constants could be written in two forms—Fractional form and
Exponential form.
Following rules must be observed while constructing real
constants expressed in fractional form:
(a)A real constant must have at least one digit.
(b)It must have a decimal point.
(c)It could be either positive or negative.
(d)Default sign is positive.
(e)No commas or blanks are allowed within a real constant.
In exponential form of representation, the real constant is
represented in two parts. The part appearing before ‘e’ is called
mantissa, whereas the part following ‘e’ is called exponent.
Following rules must be observed while constructing real
constants expressed in exponential form:
(a)The mantissa part and the exponential part should be
separated by a letter e.
(b)The mantissa part may have a positive or negative sign.
(c)Default sign of mantissa part is positive.
(d)The exponent must have at least one digit, which must be a
positive or negative integer. Default sign is positive.
(e)Range of real constants expressed in exponential form is
-3.4e38 to 3.4e38.
Rules for Constructing Character Constants
(a)A character constant is a single alphabet, a single digit or a
single special symbol enclosed within single inverted
commas.
(b)Both the inverted commas should point to the left.
For example, ’A’ is a valid character constant whereas ‘A’ is
not.
The maximum length of a character constant can be 1
character.
DATA TYPES
Hierarchy of Operations
Arithmetic Instruction
A C arithmetic instruction consists of a variable name on the left
hand side of = and variable names & constants on the right hand
side of =. The variables and constants appearing on the right hand
side of = are connected by arithmetic operators like +, -, *, and /.
Ex.: int ad ;
float kot, deta, alpha, beta, gamma ;
ad = 3200 ;
kot = 0.0056 ;
deta = alpha * beta / gamma + 3.2 * 2 / 5 ;
Here,
*, /, -, + are the arithmetic operators.
= is the assignment operator.
2, 5 and 3200 are integer constants.
3.2 and 0.0056 are real constants.
ad is an integer variable.
kot,
deta,
alpha,
beta,
gamma are real variables.
Use of Logical Operators
C allows usage of three logical operators, namely, &&, || and !.
These are to be read as ‘
AND’ ‘
OR’ and ‘
NOT’ respectively.
The first two operators,
&& and
||, allow two or more conditions
to be combined in an if statement.
if ( ( per >= 40 ) && ( per < 50 ) )
printf ( "z" ) ;
else
printf("zz");
z gets printed if both the conditions evaluate to true. If one of the conditions
evaluate to false then the whole thing is treated as false. and
zz is printed.
Similarly
if ( ( per >= 40 )
|| ( per < 50 ) )
printf ( "z" ) ;
else
printf("zz");
z gets printed if one of the conditions or both off the condition evaluate to true. If both conditions
evaluate to false then the whole thing is treated as false. and
zz is printed.
The ! Operator
This
! operator reverses the result of the expression it operates on.
Hierarchy of Operators Revisited Including logical Operator
Comment
Single Line Comment can be used by using //
MultiLine Comment about the program should be enclosed within /* */.
A comment can be split over more than one line, as in,
/* This is
a jazzy
comment */
Such a comment is often called a multi-line comment.
Assuming that you are using a Turbo C or Turbo C++ compiler
here are the steps that you need to follow to compile and execute
your first C program…
(a) Start the compiler at C> prompt. The compiler (TC.EXE is
usually present in C:\TC\BIN directory).
(b) Select New from the File menu.
(c) Type the program.
(d) Save the program using F2 under a proper name (say
Program1.c).
(e) Use Ctrl + F9 to compile and execute the program.
(f) Use Alt + F5 to view the output.
WAP TO PROGRAM TO PERFORM ADDITION,SUBTRACTION,MULTIPLICATION,DIVISION.
/* here stdio.h is the header file.it is used for standard input and output..it is enclosed in angle bracket or Double Quotes.Printf() function is used to display value on screen.scanf() function is used for inputting value from the user.to use header file we use #include it */
#include<stdio.h>
int main()
{
int i,j;
int d,e,k,h;
printf("\nENTER TWO NUMBERS : \n");
scanf("%d%d", &i, &j);
printf("\nTHE TWO NUMBERS ARE : \n%d%s%d", i," ", j);
d = i + j;
printf("\nTHE ADDITION OF TWO NUMBERS ARE: %d", d);
e = i - j;
printf("\n\nTHE SUBTRACTION OF TWO NUMBERS ARE : %d", e);
k = i * j;
printf("\n\nTHE MULTIPLICATION OF TWO NUMBERS ARE : %d", k);
h = i / j;
printf("\n\nTHE DIVISION OF TWO NUMBERS ARE : %d", h);
getch();
}