Module 1 Part 1
Module 1 Part 1
BASICS OF C
What will you learn?
What is Programming Language
Types of Programming Languages
Introduction to C Language
Structure of C Program
Compilation and Execution of C Programs
WHAT IS
PROGRAMMING ? computer
Programming is letting the
to learn
how to do the things.
-------------------------------------
Programming is giving training to computer
to do things
as it is non – intelligent body
------------------------------------
Programming is meant for
solving the problems by the Computer
PROGRAMMING LANGUAGES
Programming language is a notations, which are used to
create(write) a programs.
It appears that there will be yet another ANSI C standard officially dated
1999 or in the early 2000 years; it is currently known as "C99."
Learning Analogy for
C
Grammar
Rules
Learning Analogy for
C
Character Programs
Tokens Statements
Set
Syntax
Rules
PROGRAMMING LANGUAGE
TRANSLATORS
It can classified into 4 types.
1.Compiler
2.Interpreter
3.Assembler
4.Linker
COMPILER:-
The software that reads a program written in high level language and
translates it into an equivalent program in machine language is called as
compiler.
The complier converts the entire source code into machine level
program at a time.
Source Program:-
Object Program:-
Linker:-
A linker or link editor is a computer program that takes one or
more object files generated by a compiler and combines them into a
single executable file, library file, or another object file.
BRIEF HISTORY OF C
Example:-
Main Function
Bottom up
DIFFERENCE BETWEEN PROCEDURAL AND
OBJECT ORIENTED LANGUAGES
Procedural and Object oriented languages are high-
level languages:
Procedural Oriented Languages Object Oriented Languages
In procedural oriented language, In object oriented language, large
large programs are divided into sub- programs are divided into small parts
programs called “functions “. called “objects” .
It support top-down approach. It support bottom-up approach.
Problems are solved top to bottom. Problems are solved bottom to top.
To add new data and functions not To add new data and functions are so
so easy. easy.
Partially support Object oriented Fully support Object oriented
programming concepts. programming concepts.
Programs are oriented around Programs are oriented around
functions. objects.
Example : C, PASCAL, BASIC Example : C++, JAVA, .NET
CHARECTERESTICS OF A C
PROGRAM
1. Middle level language.
High level languages Middle level languages don’t Low level languages
provide almost everything provide all the built-in functions provides nothing
that the programmer might found in high level languages, other than access to
need to do as already built but provides all building blocks the machines basic
into the language. that we need to produce the result instruction set.
we want.
Examples: Java,
Examples: C, C++ Examples:
Python Assembler
CHARECTERESTICS OF A C
PROGRAM
1. Small size – has only 32 keywords.
2. Extensive use of function calls- enables the end user to
add their own functions to the C library.
3. Supports loose typing – a character can be treated as an
integer & vice versa.
4. Pointer implementation - extensive use of pointers for
memory, array, structures and functions.
5. It produces efficient programs.
6. It can be compiled on a variety of computers.
CREATING AND RUNNING
PROGRAMS
To create and run the programs the following steps are to
be performed:
Pre
Source Compil Object Executable
process Linker
File or
er Files Files
Library
Library Files
Files
STRUCTURE OF C
PROGRAM
The program written in C language follows this basic
structure.
1. Documentation section
2. Linking section or Pre process or statements
3. Definition section
4. Global declaration section
5. Main function section
{
Declaration Section
Executable section
}
Example:
Token
Note: The keywords with at least one uppercase letter can be used as an identifier.
constant
Identifier function
name
array
pointer
Constants can be of any of the basic data types like an integer literal, a floating literal, a
character literal, or a string literal.
Integer literals
Floating-point literals
A floating-point literal has an integer part, a decimal point, a fractional part, and an
exponent part. You can represent floating point literals either in decimal form or
exponential form.
Character literals are enclosed in single quotes, e.g., 'x' and can be stored in
Note:-
String literals or constants are enclosed in double quotes "". A string contains
Examples:
"hello, dear"
"hello, dear"
BACKSLASH CHARACTER
CONSTANTS:
C supports some special backslash character constants that are used in
<datatype> <variable_name>;
Example:
1. int rollno;
Valid Variable Declaration
2. char grade;
3. float temperature;
statement used to specify the variable name and its data type.
Note:
functions.
to the variable.
Variable.
1.Static initialization
2.Dynamic initialization
TYPES OF INITIALIZATION
1.Static initialization:-
In this method, the variable is assigned a value in
advance.
Example:-
Example:-
scanf(“%d”,&speed);
DATA TYPES
A data type consists of the values it represents and the operations
defined upon it.
BASIC DATA TYPES IN
CData types are used to specify two things to the compiler:
1. How much memory has to be allocated for an identifier to
store the data.
Formatted Unformatted
Input/output Input/output
statement statement
-getch()
-printf() -getche()
-scanf() -getchar()
-putchar()
-gets()
-puts()
-putch()
FORMATTED I/O STATEMENTS
IN C
Formatted I/O functions are used to take various inputs from
the user and display multiple outputs to the user.
These I/O supports all data types like int, float, char, and
many more.
FORMAT SPECIFIERS IN C
INPUT AND OUTPUT
STATEMENTS
OUTPUT Statement:
IN C
The printf ( ) function is used to display the information required by the user
and also prints the values of the variables.
Where variable list is list of variables to be displayed and these are displayed
as formatted in the control string.
Control string may also contain text, captions, identifiers or any other text
that is to be readable.
EXAMPLE FOR
PRINTF():
//C Program to implement printf() function.
#include<stdio.h> Output:- 20
#include<conio.h>
void main()
getch();
Note:
The control string specified the type and format of the data that has
to be obtained from the keyboard and stored in the memory
locations pointed by the arguments arg1, arg2, arg3,….., argN.
#include<stdio.h>
#include<conio.h>
void main()
getch();
}
EXAMPLES:
It is possible to read and write multiple variables at the
same time
char x;
float y;
int z;
getch();
or
variable-name = getch();
EXAMPLE FOR
GETCH():
//C Program to implement getch() function.
#include<stdio.h>
#include<conio.h>
void main()
getch();
Syntax:
getche();
or
variable-name = getche();
EXAMPLE FOR
GETCHE():
//C Program to implement getche() function.
#include<stdio.h>
#include<conio.h>
void main()
getche();
Syntax:
variable-name = getchar();
EXAMPLE FOR
GETCHAR():
//C Program to implement getchar() function.
#include<stdio.h>
#include<conio.h>
void main()
printf(“enter a character”);
getch();
g
UNFORMATTED I/O
STATEMENTS IN C
putchar():
The function is used to display a single character at a time
by passing that character directly to it or by passing a
variable that has already stored a character.
Syntax:
putchar(variable_name);
EXAMPLE FOR
PUTCHAR():
//C Program to implement putchar() function.
#include<stdio.h>
#include<conio.h>
void main()
printf(“enter a character”);
getch();
g
UNFORMATTED I/O
STATEMENTS IN C
gets():
The gets() function reads a group of characters or strings
from the keyboard by the user and these characters get
stored in a character array.
Syntax:
gets(str);
EXAMPLE FOR GETS():
//C Program to implement gets() function.
#include<stdio.h>
#include<conio.h>
void main()
getch();
Syntax:
puts(identifier_name);