Вы находитесь на странице: 1из 45

INTRODUCTION TO

C LANGUAGE
CHAPTER 18

C LANGUAGE

C language is derived from the Basic


Combined programming language
Basic Combined programming language is
also called as B language.
B was developed in 1970.
C Was developed in 1972.
At AT&T Bell Laboratories by Dennis
Ritchie.

SPECIAL ABOUT C
It

has many built-in functions.


It is well suited for writing both
system software and business
packages.
The first program written in C was the
UNIX.

BASIC STRUCTURE OF C

BASIC STRUCTURE OF C
DOCUMENTATION SECTION
IT CONSISTS OF A SET OF COMMENT LINES GIVING
THE NAME OF THE PROGRAM, THE AUTHOR AND OTHER
DETAILS
LINK SECTION
PROVIDES INSTRUCTION TO THE COMPILER TO LINK
FUNCTIONS FROM THE SYSTEM LIBRARY.
DEFINITION SECTION
DEFINES ALL THE SYMBOLIC CONSTANTS.
GLOBAL DECLARATION VARIABLES
THIS IS MEANT FOR DECLARING GLOBAL VARIABLES

PROGRAMMING IN C

CREATING A PROGRAM

COMPILING A PROGRAM

LINKING THE PROGRAM WITH


FUNCTIONS
EXECUTING THE PROGRAM

CREATING A PROGRAM
A

C Program can be written by using


either vi or ed

With
The

the extension of .c

fresh Program is called as Source


Program.
Ex: Pay.c

COMPILING A PROGRAM
cc

<filename> - to compile

The

result of the Compilation is


another file - With the extension .o

Object Program

Ex:

Pay.o

LINKING THE PROGRAM WITH


FUNCTIONS
After

the process of Compiling


automatically the process of Linking starts

After

the process of Linking the output is


another file with named Pay.out (Unix)/
Pay.exe (DOS)

Otherwise

code

called as Executable object

EXECUTING THE PROGRAM


In

Unix, type Pay.out

IN

Dos, type - Pay

CONSTANTS
Constants in C refer to fixed values
that do no change during the execution
of a program.
There are two types of constants they
are

Primary Constants

Secondary Constants

C constants

Primary Constants

Secondary Constants

Integer Constants

Array

Real Constants

Pointer

Character Constants

Structure

String Constants

Union
Enum

INTEGER CONSTANTS

It refers to a sequence of digits


Types of Integers
It should have at least one digit
no decimal point
can be either positive or negative
no commas or blanks
The range is -32768 to +32767
Example 123, -346, 0

REAL CONSTANTS
This constant will represent by no. containing
fractional parts.
Real constants are also called as floating points.
Real constants can be positive or negative.
example 34.5, 0.0073, -0.67
Real Constants can be expressed in Exponential
or Scientific Notation.
In Exponential form, the real constant is
represented in 2 parts

REAL CONSTANTS

Example 316.65 can be written as 3.1665e2 in


exponential notation.

The part appearing before e is called as mantissa


The part following e is called exponent.
Mantissa is either a real number in decimal point or
an integer.

The exponent is an integer with an optimal + or


sign.

The range of real constants is -3.4e38 to +3.4e38

CHARACTER CONSTANTS
This Constant contain a single character.
It should be mentioned within a single
quotes
examples 4, y
4 is not same as 4
Each character constant has its own
integer value known as ASCII
example a has as ASCII value of 97

STRING CONSTANTS

IT is a sequence of characters
enclosed in double quotes

example Good Morning

VARIABLE
A data name that is used to store a
data value.
it may be chosen by the programmer
in a meaningful way in order to reflect
its function or nature in the program.
some valid variable names are
Average, height

CHARACTERISTICS OF
VARIABLES
It should always begin with a letter
length of variables should not exceed
8 character
variables are case sensitive
AVERAGE is not same as Average or
average.
same variable name should be used
throughout the program.

CHARACTERISTICS OF
VARIABLES

keyword should not be used as a variable


name

no space should be left

no special symbol other than an underscore


is allowed

Ex: ph-value is wrong ; ph_value is correct.

DATA TYPES

C SUPPORTS 4 DATA TYPES

Primary or fundamental data types

User defined data types

Derived data types

Empty data set

PRIMARY DATA TYPES

Integral type

Floating type

INTEGRAL DATA TYPE

Integral type

Integer

Character

FLOATING DATA TYPE


Floating Type

float

double

Long double

Data type declaration

int idnumber;
int transaction_number;
int __my_phone_number__;
float its4me;
double VeRyStRaNgE;
float myCash;
int CaseNo;
int CASENO;
int caseno;

USER DEFINED DATA TYPE

PLEASE VERIFY THE PAGE NO:


230,231

GLOBAL VARIABLES & LOCAL


VARIABLES

STORAGE CLASS
AUTO

Default for all local variables

STATIC

- static is the default storage


class for global variables
REGISTER- register is used to define local
variables that should be stored in a
register instead of RAM
EXTERN - extern defines a global variable
that is visible to ALL object modules

STORAGE CLASS

OPERATORS

A symbol that instructs the computer


to perform certain mathematical or
logical manipulations.

it is used to manipulate data and


variables.

Different types of operators


Arithmetic

operators
Relational operators
Logical operators
ASSIGNMENT OPERATORS
Increment & Decrement Operators
Conditional Operators
Bitwise Operators

Arithmetic operators
Operator
+

Meaning

Addition or
unary plus
Subtraction or
unary minus
Multiplication

Division

Modulo division

Relational operators

This operators enable comparison between


two quantities

Operator
<
<=
>
>=
==
!=

Meaning
Is less than
Is less than or equal to
Is greater than
Is greater than or equal
to
Is equal to
Is not equal to

Logical operators
Logical

operators are used when there


is more than one condition.
example p>q && p != q
&& - logical And
|| - logical or
! logical not

ASSIGNMENT OPERATORS

THESE OPERATORS ARE ALSO CALLED


AS SHORTHAND ASSIGNMENT
OPERATORS.

Ex:

a=b-5

Increment & Decrement


Operators

++n;

n++
--n; n--;
++n is equal to n=n+1; (n+=1)
--n is equal to n=n-1; (n-=1)
Ex: n=4;
Ex: n=4;
x=++n;
o/p -> x=5

x=n++;
o/p -> n=5

CONDITIONAL OPERATORS
?,

: ARE CONDITIONAL OPERATORS


SYNTAX:
<conditional expression>?expression1:expression2
Ex: if (x<0)
grade=0;
else
grade=1;
The above stmt can be rewritten by using conditional
operator as follows:
grade=(x<0)?0:1;

Bitwise Operators
Bitwise

operations
Not suitable for float & double
& - Bitwise AND
! - Bitwise OR
^ - Bitwise XOR
<<- Shift Left
>>- Shift Right
~ - Bitwise NOT (Complement)

RELATIONAL EXPRESSION
An

expression containing a relational


operators is termed as relational
expression.
The value of relation expression is 1
if the relation is true and 0 if the
relation is false.
relational expressions are used in
the statements such as if and while

TRUTH TABLE
OP 1 OP - 2 Value of
the
expressio
n
Op-1 &&
op-2
1

op-1 || op-2

I/O Functions
Scanf

Input function

Printf

Output function

#include

< stdio.h>

Reading & Writing a


Character
<variable
Putchar

name> = getchar( );

( a);

CHARACTER TEST FUNCTION


PAGE
PGM

NO:235 TABLE

ON PAGE NO: 236

FORMATTED I/O
TABLE

IN THE PAGE NO: 237

EX:

SCANF (%2d %4d,


&num1,&num2);

Ex: PRINTF (control string,arg1,arg2,..,argn);


Refer

Table no: 18.11 in the Page No: 238

Thank

you

Вам также может понравиться