0% found this document useful (0 votes)
51 views

Std-10-Computer- Chapter 10 Introduction to C Language

Computer ch 10

Uploaded by

saratsahu4453
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

Std-10-Computer- Chapter 10 Introduction to C Language

Computer ch 10

Uploaded by

saratsahu4453
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Chapter 10 Computer

Introduction to C language Class 10


INTRODUCTION
 Flowchart and algorithm form basic solution to any problem.
 This flowchart or algorithm then converted into a program.
 For writing programs many languages are there. C language is one of them.

NEED OF PROGRAMMING LANGUAGE


 Programming language when used allows us to write an instruction that has only one
meaning.
 Programming language consists of set of predefined rules. And these rules form syntax of
that language.
 Hence learning a programming language is only learning new syntax to represent the
instructions we want to give to the computer. It is like learning new grammar when we
learn new 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)

PROGRAM AND CHARACTERISTICS OF PROGRAM


 A program can be defined as finite set of precise and clear instructions given to a
computer for performing a predefined task.
 “The process of writing these step by step instructions using a chosen language is known
as programming.
A good program should possess following characteristics:
1. A program must end after finite number of steps.
2. The instructions must be precisely defined
3. All the instructions must be effective
4. A program may take zero or more inputs.
5. A program may produce one or more outputs.

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

Presented by Nuzhat Ibrahim Memon 2


DOCUMENTATION SECTION
 This section is an optional section consists of set of comment lines (/* and */) that
indicates the purpose of documentation which include purpose of the program, author
name, creation date and other information
 Comments (/*.......... */) are not processed by C compiler and are left as it is.
 Comments in C program can be added anywhere. It is always a good practice to use
comments within the functions as it improves the readability and understanding of the
program.
SYMBOLIC CONSTANT DEFINTION
 Pre processor directive #define is used to define symbolic constant
 It instructs the compiler to replace all occurrences of symbolic constants with the
values specified against it.
 Normally symbolic constants are defined using capital letter.
 The statement #define PI 3.14 defines a symbolic constant PI that has value 3.14. This
statement is known as pre processor directive. It instructs the translator to replace all
occurrence of PI with 3.14 before executing the program.
FILE INCLUDE SECTION
 This section is used to include the required system inbuilt/libraries function or header
files to execute a program
 The extension of header file is .h
 The statement #include <stdio.h> instructs the compiler to include the contents of
header file called “stdio.h” and this file contains information about the inbuilt functions
to be used.
 For predefined function like pow( ) [pow( ) function is used for calculating value of x
raised to given power eg 24 or 43] , sqrt( ) [sqrt () function is used to find square root of a
given number √16 or √49] can be used in our program if needed just by including
<math.h> header file.

GLOBAL VARIABLE DECLARATION SECTION


 Scope in C variable is decided by using opening and closing {} braces.
 The variables defined within curly braces are known as local variables. And this local
variable cannot be used outside the scope.
 At times we need to use a variable in all the functions, such a variable is known as global
variable. This variable is defined before defining all the functions.
MAIN FUNCTION
 All C programs contain one function with the name main().
 This is the function from where the execution of any C program starts.
 The control is first transferred to this function and from here rest of the operations are
carried out.
 The statement int main() returns an integer value whereas void main() does not return
any value.
USER DEFINED FUNCTION
 A function written by the user is called user defined function
 User defined functions are the functions that a user creates as per his/her requirement.
 main( ) is known as user defined function.
Presented by Nuzhat Ibrahim Memon 3
INBUILT/LIBRARY FUNCTION
 The functions already available in C that a user can use in his/her program are known
as inbuilt or library function
 printf( ) is known as inbuilt or library function
function.
 scanf( ) is also known as inbuilt or library function
function.

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){
……..
}

 And if we write user-defined


defined function before main( ) then no need of prototype.
void subtract(int a, int b){
……..
}
void main( ){
subtract(a,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:

Presented by Nuzhat Ibrahim Memon 4


C Tokens
 Tokens are Smallest individual units in a C program.
 C is basically identifies six
x types of token.

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

Presented by Nuzhat Ibrahim Memon 5


VARIABLE
 An entity in C that is capable of storing different values is known as variable.
 A variable is basically a data name that is used to store values.
 The data within the memory space is refer
referred by a name known as variable
 Unlike constants that remain unchanged during the program execution, a variable can
vary and take up several values during the program execution.
Total Value No Blank space is not allowed
total&value No Special cha
character is not allowed
total_value Yes Underscore is allowed
_file Yes First character can be underscore
10marks No First character has to be letter or underscore
mark100 Yes As first character is character so it is allowed
char No Use of reserved keyword not allowed
Double Yes Identifiers
dentifiers are case sensitive, so this is not same as keyword double
INTEREST Yes Capital and small letters are part of C character set

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.

Presented by Nuzhat Ibrahim Memon 6


 The Octal constants use numeric digits from 0 to 7. The base of this number system
is 8. The octal numbers are uses 0 as prefix.
Real constant
 Real constant refer to decimal numbers that have fractional part.
 Real constant can also be represented by using scientific form.
 In this form a number is represented using a mantissa and exponent.

Character constant
 Character constant contain characters.
 There are two types of character constants in C are Single character constant &
String Constant

Single Character Constant


 A Single character constant is represented by using single character enclosed within
single quotes.
 Each character constant is associated with a numeric value known as ASCII (American
Standard Code for Information Interchange) value.

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,

Presented by Nuzhat Ibrahim Memon 7


 The preprocessor directive statement instructs the compiler that the occurrence of the
symbolic constant used in program should be replaced by the constant value specified
in the definition.

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.

Commands in SciTE editor


 Save the file Ctrl + S or File  Save
 Compile Ctrl + F7 or Tools  Compile
 Run F5 or Tools Go

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.

Presented by Nuzhat Ibrahim Memon 8

You might also like