Você está na página 1de 34

WHAT IS C LANGUAGE ?

C IS A GENERAL PURPOSE,HIGH LEVEL


LANGUAGE.
C WAS ORIGINALLY DEVELOPED BY DENNIS
M.RITCHIE AT BELL LABS
C WAS INVENTED TO WRITE AN OPERATING
SYSTEM CALLED UNIX.
C WAS FORMALIZED IN 1988 BY THE
AMERICAN NATIONAL STANDARD
INSTITUTE(ANSI).
TODAYS MOST POPULAR LINUX OS AND
RDBMS MYSQL HAVE BEEN WRITTEN IN C.

USES OF C LANGUAGE

Efficiency: intended for applications where


assembly language had traditionally been used.
Portability: hasnt splintered into incompatible
dialects; small and easily written.
Power: large collection of data types and
operators.
Flexibility: not only for system but also for
embedded system commercial data processing.
Standard library.
Integration with UNIX.

DISADVANTAGE OF C
LANGUAGE

Error-prone
Difficult to understand

Difficult to modify

WHAT IS C STANDARD LIBRARY?


The C standard library is the standard library for
the C programming language, as specified in
the ANSI Cstandard. Since ANSI C was adopted by
the INTERNATIONAL ORGANISATION FOR
STANDARDIZATION, the C standard library is also
called the ISO C library.
The C standard library provides macros, type
definitions, and functions for tasks
like string handling, mathematical computations,
input/output processing, memory allocation and
several other operating system services.
.

HEADER FILES IN C
LANGUAGE

A header file is a file with


extension .h which contains C function
declarations and macro definitions and to
be shared between several source files.
We request the use of a header file in our
program by including it, with the C
preprocessing directive#include like we
have seen inclusion of stdio.h header file,
which comes along with our compiler.
EXAMPLE- #include<stdio.h>

HEADER FILES
HEADER FILE

EXPLANATION

stdio.h

File and console


IO:open,close,printf,scanf,w
rite,read,etc

conio.h

Hold out :getch(),etc

string.h

String and byte


manipulation:strlen,strcpy,et
c.

math.h

Math functions:exp,sqrt,etc

ctype.h

Characters type:tolower,
etc.

stdint.h

Standard integer:int_n,etc

time.h

Time related

DATA TYPE IN C
LANGUAGE
In the c programming language, data
types refers to an extensive system
for declaring variables of different
types. The language itself provides
basic arithmetic types and syntax to
build array and compound types.
Several headers in the standard
library contain definitions of support
types, that have additional properties.

DATA TYPES AND ITS SIZE

VARIABLES IN C
LANGUAGE
A variable is just a named area of storage
that can hold a single value (numeric or
character). The C language demands
that you declare the name of each
variable that you are going to use and its
type, or class, before you actually try to
do anything with it.
The Programming language C has two
main variable types Local Variables
Global Variables

LOCAL VARIABLES

Local variables scope is confined within


the block or function where it is defined.
Local variables must always be defined
at the top of a block.
When a local variable is defined - it is not
initalised by the system, we must initalise
it ourself.
When execution of the block starts the
variable is available, and when the block
ends the variable 'dies'.

GLOBAL VARIABLE

Global variable is defined at the top of


the program file and it can be visible and
modified by any function that may
reference it.
Global variables are initalised
automatically by the system when you
define them!
Note-If same variable name is being
used for global and local variable then
local variable takes preference in its
scope. But it is not a good practice to
use global variables and local variables
with the same name.

CONSTANT IN C
LANGUAGE
Constant value is the one
which does not change during
the execution of a program. C
supports several types of
constants.
A C constant is usually just
the written version of a
number.

INTEGER CONSTANTSAn integer constant is a


sequence of digits. There are
3 types of integers namely
decimal integer, octal
integers and hexadecimal
integer.For example-1, 0,
5.73, 12.5e9

REAL CONSTANTS
Real Constants consists of a fractional part in their representation.
Integer constants are inadequate to represent quantities that vary
continuously. These quantities are represented by numbers
containing fractional parts like 26.082.
Example of real constants are
0.0026
-0.97
435.29
+487.0
Real Numbers can also be represented by exponential notation.

SINGLE CHARACTER CONSTANTS


A Single Character constant represent a
single character which is enclosed in a pair
of quotation symbols.
Example for character constants are

'5'
'x'
';'
''
All character constants have an equivalent
integer value which are called ASCII
Values.

STRING CONSTANTS
A string constant is a set of
characters enclosed in double
quotation marks. The characters in a
string constant sequence may be a
alphabet, number, special character
and blank space. Example of string
constants are
"VISHAL"
"1234"
"God Bless"
"!.....?"

USE OF scanf
scanf() function is
used to read
character, string,
numeric data from
keyboard.

USE OF printf
printf() function is used to print the character,
string, float, integer, octal and hexadecimal values
onto the output screen.
We use printf() function with %d format specifier to
display the value of an integer variable.
Similarly %c is used to display character, %f for
float variable, %s for string variable, %lf for double
and %x for hexadecimal variable.
To generate a newline,we use \n in C printf()
statement.

Note:

C language is case sensitive. For example, printf()


and scanf() are different from Printf() and Scanf().
All characters in printf() and scanf() functions must
be in lower case.

WHAT IS AN ESCAPE SEQUENCE?

In C, an escape sequence refers to a


combination of characters beginning
with a back slash (\) followed by letters
or digits. Escape sequences represent
non-printable and special characters
in character and literal strings. As
such, they allow users to
communicate with a display device or
printer by sending non-graphical
control characters to specify actions
like question marks and carriage
returns.

ESCAPE SEQUENCE
LIST

USE OF getch(); AND clrscr();


clrscr(); :- This is used for clearing the output screen i.e
console
suppose we run a program, alter it and run it again you
may find that the previous output is still stuck there
itself, at this time clrscr(); would clean the previous
screen.
One more thing to remember always use clrscr(); after
the declaration like
int a,b,c;
float total;
clrscr();
getch(); :- getch is used to hold the screen. In simple
language, if we don't write this the screen will just flash
and go away.

PROGRAMMING LAYOUT
ALGORITHM
FLOWCHART
PROGRAM
COMMENTS

COMPILING AND

EXECUTION

ALGORITHM
A sequential solution of any
program that written in human
language,called algorithm.
Algorithm

is first step of the


solution process, after the
analysis of problem,
programmer write the
algorithm of that problem.

Example of AlgorithmQ. Write a algorithm to find out number is


odd or even?
Ans.
step 1 : start
step 2 : input number
step 3 : rem=number mod 2
step 4 : if rem=0 then
print "number even"
else
print "number odd"
endif
step 5 : stop

FLOWCHART
A Flowchart is a type of diagram (graphical or symbolic)
that represents an algorithm or process. Each step in the
process is represented by a different symbol and
contains a short description of the process step. The
flow chartsymbols are linked together with arrows
showing the process flow direction. A flowchart typically
shows the flow of data in a process, detailing the
operations/steps in a
pictorial format which is easier to understand than
reading it in a textual format.

SYMBOLS USED IN FLOWCHART


Terminator: An oval flow chart shape indicates the start or end of
the
process, usually containing the word Start or End.

STAR
T

Process: A rectangular flow chart shape indicates a


normal/generic
process flow step.

PROCESS

Decision: A diamond flow chart shape indicates a branch in the


process flow. This symbol is used when a decision needs to be made,
commonly a Yes/No question or True/False test.

DECISION

Connector: A small, labelled, circular flow chart shape used to


indicate a jump in the process flow. Connectors are generally used in
complex or multi-sheet diagrams.

CONNECTOR

Data: A parallelogram that indicates data input


or output (I/O) for a process.

INPUT/OUTPUT

Arrow: used to show the flow of control in a process. An arrow


coming from one symbol and ending at another symbol represents that
control passes to the symbol the arrow points to.

PROGRAM

Ques-Write a program
to swap two variables
without using third
variable.

SOLUTION#include<stdio.h>
file
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf(Enter value in a);
scanf(%d,&a);
printf( Enter value in b);
scanf( %d,&b);
a=a+b;
b=a-b;
a=a-b;
printf( \n After swapping a=%d, a);
printf( \n After swapping b=%d, b);
getch();
}

/* header
*/

/*variables*/
/*clearscreen*/

/*
statements
*/

COMMENTS IN C
A "comment" is a sequence of characters
beginning with a forward slash/asterisk
combination (/*) that is treated as a single
white-space character by the compiler and
is otherwise ignored. A comment can
include any combination of characters from
the representable character set, including
newline characters, but excluding the "end
comment" delimiter (*/). Comments can
occupy more than one line but cannot be
nested. The Microsoft compiler also
supports single-line comments preceded by
two forward slashes (//). These comments
cannot extend to a second line.

COMPILING AND EXECUTION


Step by step process is as followsCREATING AND EDITING PROGRAM.
SAVE PROGRAM USING .C EXTENSION
FILE SAVED WITH .C EXTENSION IS CALLED
SOURCE PROGRAM.
C SOURCE CODE WITH .C EXTENSION IS GIVEN
AS INPUT TO COMPILER AND COMPILER
CONVERTS IT INTO EQUIVALENT MACHINE
INSTRUCTION.
NOW THE COMPILER CHECKS FOR ERROR.IF
SOURCE CODE IS ERROR FREE THEN CODE IS
CONVERTED INTO OBJECT FILE OTHERWISE THE
PROGRAMMER REVIEWS IT.

Você também pode gostar