Std-10-Computer- Chapter 10 Introduction to C Language
Std-10-Computer- Chapter 10 Introduction to C Language
NEED OF TRANSLATOR
Computers do not understand the language that we speak neither does it understand the
programming language.
Computer only understands 0 and 1.
The problem of computers not understanding our language is solved by using software
programs called translators.
The translator is known as compiler that converts the programming language into
binary code (0 or 1)
FEATURES OF C LANGUAGE
C is a structured language.
Usually programs written in C can be ported to different machines having different
operating systems and compilers with almost negligible modification. Thus it is considered
to be portable language.
C is also considered to be a middle level language by some and higher level language by
others. In any case it has all the features that a programmer would like to have.
Presented by Nuzhat Ibrahim Memon 1
STRUCTURE OF C PROGRAM
C program is a set of blocks called functions. A function is made of one or more
statements used for performing a predefined task.
FUNCTION
C provides
des us a facility of breaking a single
program into set of small pieces. These
pieces are known as functions. Function
allows our program to be broken into small
pieces.
Set of such functions then becomes a C
program.
These functions once generated are reusable.
Taking such an approach helps us to solve
problem arising in the program easily, a as we
have to concentrate on only one functio
function
rather than an entire program
NOTE:
If we write user-defined
defined function after main( ) then prototype of function is needed
subtract(int, int); Function prototype
void main( ){
subtract(a,b);
}
void subtract(int a, int b){
……..
}
C Character Set
Each language has its
ts alphabets which can be used to form words and sentences.
So does c language has its own character set.
C character set can be divided into four categories:
IDENTIFIER
User defined names given by user to variable, function or symbolic constant for the
purpose of identification
A word that a user can construct by making use of C character set is known as identifier
It consists of set of letters(totalcost),
ters(totalcost), digits(totalcost1), underscore(total_cost)
Example: pi, qty, total, principal, interest, main, difference
Rule 1: The First character of variable name must be a letter or underscore (totalcost,
_totalcost)
Rules 2: No Special Character (other than underscore _ )
Variable name consists of Letter (a-z, A-Z), Digit (0 -9), Underscore (_)
Rule 3: No Keywords - Keyword cannot be used as a variable name.
Rule 4: Maximum length of variable name as per ANSI standards is 31 characters.
Rule 5: Case sensitive .. Total, total, TOTAL all are different
Numeric Constant
The constant that store numeric value is known as numeric constant.
The numeric constants are divided in two categories:: integer constant & real constant.
Integer constant
Integer constant refers to whole numbers.
numbers
Three types of integer constants:
constants decimal, hexadecimal and octal.
octal
The decimal constants use numeric digits from 0 to 9.
The hexadecimal constants use numeric digits from 0 to 9 and letter A to F. Here A
to F refers to numeric values 10 to 15 respectively. The hexadecimal numbers have
base 16. The
he hexadecimal numbers are uses 0x or 0X as prefix.
Character constant
Character constant contain characters.
There are two types of character constants in C are Single character constant &
String Constant
String Constant
String constants are denoted by using sequence of characters enclosed within double
quotes.
String constants don’t have any ASCII value associated with it.
Character will be allocated only one memory space. Whereas String will be allocated
two memory space. This is due to the fact that strings in C are ended by adding ‘\0’, a
null character.
Backslash Characters
The single character constants use single character, while string character uses
sequence of characters.
C also provides a special character constant that uses two characters. These constants
are known as backslash characters or escape sequences.
They are known as backslash character as the first character is always a backslash ‘\’,
while they are known escape sequence characters as the output of these constants is
not a character but white spaces.
These constants also have an ASCII value associated with them.
The escape sequences are mostly used for formatting purpose. For eg ‘\n’ is used for
inserting new line at the time of input/output.
Symbolic Constant
Certain numeric and character constants can be defined using symbolic identifier. Such
constants are known as symbolic constant.
#define is known as a preprocessive directive,
STEP 1: Write a program using any text editor, the program that we write using an editor is
known as source code or source program.
program
The extension of the source file written in C language is ““c”
STEP 2: Compile the source program
ogram using a compiler.
A compiler is a translator that converts a source program into machine language program
known as object code or object program
program.
STEP 3: A program called linker is then used to link the object code with the library functions
giving executable program or executable code.
STEP 4: Finally executable code is loaded on to memory by a program called loader with the
data required to give us the output.
HISTORY OF C LANGUAGE
The origin of C has been dated back to 1972 in Bell laboratories.
The man who owns the credit of creating C language is Dennis M. Ritchie.
It was derived from Basic Combined Programming Language commonly known as BCPL.
The aim of developing C was to build robust system software. But it became a pet of
programmers in coming years and has been used for developing all kind of software.
Hence it has come to be known as general purpose progr
programming
amming language.
Although born in 1972, it was standardized in 1989 by American National Standards
Institute (ANSI).
From there on it came to be known as ANSI C, Different operating systems and compilers
support this standard.