KEMBAR78
Introduction of C Language | PDF | Computer Program | Programming
0% found this document useful (0 votes)
22 views33 pages

Introduction of C Language

C is a high-level, structured programming language used for system programming and general-purpose applications. It features a flexible syntax, supports limited data types, and allows for functions and recursion. The document also details the compilation process, the role of tokens, identifiers, constants, and operators, as well as input/output functions in C.

Uploaded by

harshatharithika
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views33 pages

Introduction of C Language

C is a high-level, structured programming language used for system programming and general-purpose applications. It features a flexible syntax, supports limited data types, and allows for functions and recursion. The document also details the compilation process, the role of tokens, identifiers, constants, and operators, as well as input/output functions in C.

Uploaded by

harshatharithika
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

• C is a high level, structured and third generation

programming Language

• It is also a system programming language since it is used


to develop system programs such as UNIX operating
system and compilers.

• C is one of the most dominant development languages


for general purpose applications such as utility software
and low-level software for many devices.
ALGOL 60(Algorithmic language)
Developed by an International Committee, 1960

CPL (Combined Programming Language)


Developed by Cambridge and the University of London,
1963

BCPL (Basic CPL)


Developed by Martin Richards, 1967

B
Developed by Ken Thompson, Bell Labs, 1970

C
Developed by DENNIS RITCHIE, Bell Labs, 1972
• General-purpose language.
• Structured language.
• System programming language.
• Relatively low-level language.
• Machine independent and hence portable.
• Flexible and powerful.
• Fast running and efficient.
• Free format.
• Supports limited data types.
• Commands may be inserted anywhere in a program.
• Permits initialisation of variables in the declaration itself.
• Programs are made up of functions.
• Permits recursion.
• More built-in functions.
• Treats upper case and lower case letters distinctively
(Case sensitive).
 The solution to a problem is written in the form of
program while computer is used.

 A program is a set of instructions written in a


programming language.

 A programming language provides the medium for


conveying the instructions to the computer.
• Low Level Language/ Machine Language
– Computer hardware can understand instructions only
in the form of machine codes i.e. 0's and 1's.
– Low level language or machine language is the
programming language used to communicate with the
hardware of a computer.
– Difficulties
• Very difficult to understand the machine language
because instructions are a sequence of 0’s and 1’s.
• It is difficult to identify errors in the machine language
programs.
• Low level languages are machine dependent.
 To overcome the difficulties of machine languages, high
level languages like BASIC, FORTRAN, PASCAL,
COBOL and C were developed.
 High level languages allow some English-like words and
mathematical expressions that facilitate the better
understanding of the logic involved in a program.
 High level languages are machine independent.
 A computer system can not follow programs written in a
high level language, high level language programs are
translated into low level language programs and then
executed.
• Translation of a high level language program (source
code) to a low level language program (object code) is
done by a software known as compiler.
• Object code is an intermediate code between the source
code and the executable machine code.
• Linker performs the linking of libraries with the object
code, to make the generated object code into an
executable machine code.
• Object code becomes an input to the linker, which
produces an executable machine code.
• Instead of a compiler, an interpreter may also be
used.
• An interpreter reads one instruction at a time
and carries out the actions implied by that
instruction.
• It does not perform any translation.
• It executes all the instructions one by one in a
program.
• But, a compiler translates the entire instructions.
Only after completing the translation process,
execution can be carried out while using a
compiler
S.No Complier Interpreter
1 Complier takes entire program Interpreter takes single
as a input instruction as input
2 Intermediate object code is No Intermediate object is
generated generateed
3 Conditional control statement Conditional control statement
are Executed faster are Executed slower
4 More memory Less memory
5 Program need not be compiled Every time higher level
every time program is converted into
lower level program
6 Errors are displayed after entire Error are displayed for every
program is checked instruction interpreted
7 Example:Compiler Example:BASIC
DOCUMENTATION SECTION
LINK / PREPROCESSOR SECTION
DEFINITION SECTION

GLOBAL DECLARATION SECTION

main() function Section


{
Declaration part;
Executable Part;
}
sub program section (user defined functions)
{
Body of the subprogram;
}
 Documentation Section
◦ Consists of a set of comments lines giving the name of
the program, the author and other details for
programmer for later use.
 Link Section
◦ Provides instructions to the compiler to link functions from the system
library. In this section, we can write header files are use in our
program. #include<stdio.h>
 Definition Section
◦ Defines all symbolic constants. Example #define PI 3.14
 Global Declaration Section
◦ Some variables are used in more than one functions and
such variables are called as global variable
 main() function section
◦ Has 2 parts
 Declaration part - Declaration part declares all variables
used in executable part
 Executable part - Executable part contains at least one
statement

 Subprogram section
◦ Contains all user defined functions that can be
called in the main functions
◦ Placed immediately after main function

 All section, except main function may be


present when they are not required
/* Example program */ /* Documentation section */
#include<stdio.h> /* Linking section*/
#define a 10 /* Definition section */
int b; /* Global variable declaration */
main() /* Main function */
{
int c;
b=10;
c=a+b;
printf(“Sum : %d”,c);
sub(b);
}

void sub(int y) /* (Sub program or function) */


{
int z; / * Local variable declaration for function */
z=a-y;
printf(“Subt : %d”,z);
}
Source
Code High level
language
program
Compiler

Object
Code Low level
language
program
Object
Linker
Libraries

Executable
Machine Code
Start

Editor
Source
Program
Name.C
Compiler

Yes
Error
? Object
Program
No Name.obj

System Linker
Library Executable
Code
Execute
Name.exe

Logic Error Logic


and data
Error ?
No error

Correct output

Stop
 A programming language needs a set of
characters to write a program. The set of
characters used in a language is known as its
character set.
 Character set for ANSI Standard C (ANSI C) is
given below.
Upper-case alphabets : A to Z
Lower-case alphabets : a to z
Decimal digits : 0 to 9
Special Characters : + - * / % = < > _
Blank : ; , . ' " ? ! # \ (
)[ ] { } & | ^ ~
 Grammar is important to form sentences
using words in any language.

 In programming languages, the grammar is


known as syntax.

 The syntax of a programming language gives


the forms of various entities in a program and
the rules to be followed while using them in a
program.
 A comment explains briefly what a program does.
 Comments should be included in appropriate
places to improve the readability of a program
 In C programs, the characters between /* and */
are treated as comments and are ignored by the
compiler when the program is compiled.
 Comments may appear anywhere in a C program.
 For a compiler a token is an individual entity of a program.
 A compiler identifies and splits a program into a number of
tokens.
 A token may be a single character or a group of characters which
has a specific meaning.
 The following are the tokens that can be identified by a C
compiler during the translation process.

◦ Identifiers ---- Float, int ,float.,


◦ Keywords ---- main ,a , cost
◦ Constants ---- 50, 12.5
◦ String Constants ---- “Computer” , “C”
◦ Operators ____ +-* / %
◦ Special symbols ---- { [ ? …
• For example: if(age>=21)
The key word if is a token.
The character ( is the next token.
The variable age is the subsequent
token.
The operator >= is the next token
(largest possible token).
The constant 21 is the next token.
The character ) is the next token.
 Every C word is classified as either a keyword or an identifier.
 All keywords have fixed meaning and these meanings cannot
be changed.
 Keywords serve as basic building blocks for program
statements.
 All keywords must be written in lower case.

auto double int struct


break else long switch
case enum register typedef
char exturn return union
const float short unsigned
continue for signed void
default goto sizeof vollatile
do if static while
 Identifiers refer to the names of variables,
function and arrays.
 These are user-defined names and consist of
a sequence of letters and digits with as a first
character.
 Identifier should not be a keyword.
Variable: A variable is a data name that may be
used to store a data value. A variable may take
different values at different times during
execution. The programmer can choose a
variable name in a meaningful way.
Rules for a variable:
 The first character of the variable name should be a letter
(alphabet).
 A variable should not be a keyword.
 A variable name can be of any length in recent compilers but
some implementations of C recognize the first eight characters
as the valid variable name.
 No special characters are allowed in the variable name except
underscore.
 The blank space characters are also not allowed while
constructing variable names.
 Upped and lower case letters are different in variable names.
Because C is case sensitive language.
 It is always useful to give the meaningful names to the variables.
 Some valid variable names are.
 ROLLNO, Area, arc, n1, n_1, n1_n2……
 Constants in C refer to fixed values that do not
change during the execution of a program.
Constant

Numbered Character
Constants Constants

Integer Float Single String Back slash

Decimal
Octal
Hexadecimal
 Anoperator is a symbol that tells the computer to
perform certain mathematical manipulations.

Types of Operators:
1. Arithmetic
2. Relational
3. Logical
4. Assignment
5. Increment and decrement
6. Conditional
7. Bitwise
8. Special
 Every c program should have exactly one main function.

 C program Execution always start from main

 Execution of c program begins at openning braces of a function and ends at


closing brace of the function.

 Generally all the statements in the c written in Lowercase Letters.

 UpperCase Letters are used for Symbolicname,Output Strings and


Message.

 Every C statement must ends with semicolon

 All variables must be declared with respective data types before using.

 Comments can be inserted anywhere in C program

 Braces generally used for the grouping of statement


 In „C‟ language I/O functions are categorized
into following two types
Input/output
function

Unformatted I/O Formatted I/O

getchar(); putchar();
gets(); scanf(); printf();
puts();
getch();
getche();
 Conversion character Meaning
%d Integer
%f Float
%c Character
%s String
%lf Double
 The scanf() function is an input function.
 It used to read the mixed type of data from the
keyboard.
 You can read integer, float and character data by using
its control codes or format codes.
Syntax:
scanf(“control string”,&v1,&v2…);
Example: scanf(“%d”,&n);

 The control string %d specifies that an integer value is


to be read from the terminal (keyboard).
 printf() fi\unction for printing captions and numerical
results the general form of printf statement is….
Syntax:
printf(“controle string”,arg1,arg2…);

control string consists of three types of items:

 Characters that will be printed on the screen as they


appear.
 Format specifications that define the output format for
display of each item.
 Escape sequence character such as \n,\t….. the control
string indicates how many arguments follow and what
their types are the argument arg1,arg2… are the
variable whose values are formatted and printed
according to the specification of control string.

You might also like