SlideShare a Scribd company logo
1 of 31
UNIT-I
OVERVIEW OF C
REFERENCE: PROGRAMMING IN C BY BALAGURUSWAMY
MRS. SOWMYA JYOTHI, SDMCBM, MANGALORE
AMERICAN NATIONAL STANDARD INSTITUTE INTERNATIONAL STANDARDS ORGANIZATION
HISTORY OF C
The root of all modern languages is ALGOL, introduced in the early 1960s. ALGOL was the first computer
language to use a block structure. ALGOL gave the concept of structured programming to the computer science
community.
In 1967, Martin Richards developed a language called BCPL( Basic Combined Programming language) primarily
for writing system software.
In 1970, Ken Thompson created a language using many features of BCPL and called it simply B.
B was used to create early versions of UNIX operating system at Bell Laboratories.
C was evolved from ALGOL, BCPL and B by Dennis Ritchie at Bell Laboratories in 1972.
C uses many concepts from these languages and added the concept of data types and other powerful features.
Since it was developed along with the UNIX operating system, it is strongly associated with UNIX.
ALGOL: ALGORITHMIC LANGUAGE
Importance Of C
1. C is robust language whose rich setup of built in functions and
operators can be used to write any complex program.
2. Programs written in C are efficient and fast due to several varieties
of data types and powerful operators.
3. The C complier combines the capabilities of an assembly language
with the feature of high level language. Therefore it is well suited
for writing both system software and business package.
4. There are only 32 keywords, several standard functions are available
which can be used for developing programs.
5. C is portable language this means that c programs written for one
computer system can be run on another system, with little or no
modification.
6. C language is well suited for structured programming, this requires user to think of a problems in
terms of function or modules or block. A collection of these modules make a program debugging and
testing easier.
7. C language has its ability to extend itself. A C program is basically a collection of functions that are
supported by the C library. We can continuously add our own functions to the library with the availability
of the large number of functions.
8. People use C programming language because it is easy to learn and understand.
C is a high level language.
C is case-sensitive language.
C is a free-form language
Sample C Program
Program 1:- Printing a message
main( )
{
/* ……..printing begins………*/
printf(“I see, I remember”);
/*………printing ends………*/
}
Output: I see, I remember
Sample C Program
Program 1:- Printing a message
main( )
{
/* ……..printing begins………*/
printf(“I see, I remember”);
/*………printing ends………*/
}
The main( ) is a special function used by the C system to tell the
computer where the program starts. Every program must have exactly
one main function.
The empty pair of parentheses immediately following main indicates
that the function main has no arguments (or parameters).
The opening brace “{“marks the beginning of the function main and
the closing brace “}” indicates the end of the function. All the
statements between these 2 braces form the function body. The
function body contains a set of instructions to perform the given task.
printf line is an executable statement. The lines beginning with /* and
ending with */ are known as comment lines. These are used in a
program to enhance its readability and understanding. Comment lines
are not executable statements and therefore anything between /* and
*/ is ignored by the compiler.
Every statement in C should end with a semicolon(;) mark.
FORMAT OF SIMPLE C PROGRAMS
Main function
The main is a part of every C program. C permits different forms of main statement. Following forms are allowed.
main( )
int main( )
void main( )
main(void)
void main(void)
int main(void)
The empty pair of parentheses indicates that the function has no arguments. This may be explicitly indicated by
using the keyword void inside the parentheses. We may also specify the keyword int or void before the word
main. The keyword void means that the function does not return any information to the operating system and
int means that the function returns an integer value to the operating system.
When int is specified, the last statement in the program must be “return 0”.
Program 2: Adding 2 numbers
/*Program Addition*/
main( )
{
int number;
float amount;
number=100;
amount = 30.75 + 75.35;
printf(“%dn”, number);
printf(“%5.2f”, amount);
}
Program 2: Adding 2 numbers
/*Program Addition*/
main( )
{
int number;
float amount;
number=100;
amount = 30.75 + 75.35;
printf(“%dn”, number);
printf(“%5.2f”, amount);
}
It is a good practice to use comment lines in the beginning to
give information such as name of the program, author, date etc.
The words number and amount are variable names that are used
to store numeric data. The numeric data may be either in integer
form or in real form. In C, all variables should be declared to tell
the compiler what the variable names are and what type of data
they hold.
Declaration statements must appear at the beginning of the
functions. All declaration statements end with a semicolon.
The words such as int and float are called the keywords and
cannot be used as variable names. Data is stored in a variable by
assigning a data value to it.
The #define directive
A #define is a preprocessor compiler directive and not a statement. Therefore #define lines should not end with
a semicolon.
Symbolic constants are generally written in uppercase so that they are easily distinguished from lowercase
variable names.
#define instructions are usually placed at the beginning before the main( ) function.
Symbolic constants are not declared in declaration section.
Syntax:
#define constantname value
Example:
#define PI 3.1415
Program 3:- Interest calculation
#define PERIOD 10
#define PRINCIPAL 5000.00
main( ) /*……….Main Program Begins……..*/
{
int year; /*…………Declaration statements…………*/
float amount, value, inrate;
amount = PRINCIPAL; /*…………Assignment Statements………….*/
inrate = 0.11;
year = 0;
while(year<=PERIOD) /*…………Computation using while loop…….*/
{
printf(“%2d %8.2fn”,year,amount);
value = amount + inrate +amount;
year = year + 1;
amount = value;
} /*…………...while loop ends…………..*/
}
#define instruction defines to a symbolic constant. Whenever a symbolic name is encountered, the
compiler substitutes the value associated with the name automatically.
To change the value, we have to change the definition.
In this example, we have defined 2 symbolic constants PERIOD and PRINCIPAL and assigned values 10
and 5000.00 respectively. These values remain constant throughout the execution of the program.
All computations and printing are accomplished in a while loop. While is a mechanism for evaluating
repeatedly a statement or a group of statements. We exit the loop when year becomes greater than
PERIOD.
Program 4: Use of Subroutines
int mul(int a, int b);
main( )
{
int a, b, c;
a=5;
b=10;
c = mul(a,b);
printf(“multiplication of %d and %d is %d”,a,b,c);
}
int mul(int x, int y)
int p;
{
p = x * y;
return(p);
}
/*………..Program Using Function…………*/
The mul function multiplies the values of x and y and the result is returned to the main( ) function when it is called in
the statement
c = mul(a,b);
The mul( ) has 2 arguments x and y that are declared as integers. The values of a and b are passed on to x and y respectively
when the function mul( ) is called.
The #include directive
C programs are divided into modules or functions.
Some functions are written by users like us and many others are stored in the C library.
Library functions are grouped category-wise and stored in different files known as header files. If we want to
access the function stored in the library, it is necessary to tell the compiler about the files to be accessed.
This is achieved by using the preprocessor directive #include as follows: #include<filename>
Filename is the name of the library file that contains the required function definition. Preprocessor directives are
placed at the beginning of a program.
Example:
#include<stdio.h> - standard input output header file
#include<math.h>
Program 5:- Use of math functions /*……..Program using cosine function………….*/
#include<math.h>
#define PI 3.1416
#define MAX 180
main( )
{
int angle;
float x, y;
angle = 0;
printf(“ Angle Cos(angle)nn”);
while(angle <= MAX)
{
x= (PI / MAX) * angle;
y= cos(x);
printf(“%15d %13.4fn”, angle,y);
angle = angle + 10;
}
}
Program 5:- Use of math functions /*……..Program using cosine function………….*/
#include<math.h>
#define PI 3.1416
#define MAX 180
main( )
{
int angle;
float x, y;
angle = 0;
printf(“ Angle Cos(angle)nn”);
while(angle <= MAX)
{
x= (PI / MAX) * angle;
y= cos(x);
printf(“%15d %13.4fn”, angle,y);
angle = angle + 10;
}
}
The standard mathematical functions are defined and kept as a part of C math library. If we want to use any of these mathematical functions,
we must add an #include instruction in the program. #include is a compiler directive that instructs the compiler to link the specified
mathematical functions from the library.
#include<math.h>
Math.h is the filename containing the required function.
Another #include instruction that is often required is
#include<stdio.h>
stdio.h refers to the standard I/O header file containing input and output functions
The #define directive
A #define is a preprocessor compiler directive and not a statement. Therefore #define lines should not end with
a semicolon.
Symbolic constants are generally written in uppercase so that they are easily distinguished from lowercase
variable names. #define instructions are usually placed at the beginning before the main( ) function. Symbolic
constants are not declared in declaration section.
Syntax:
#define constantname value
Example:
#define PI 3.1415
BASIC STRUCTURE OF C PROGRAM
A 'C' program can be viewed as a group of building blocks called functions.
A function is a sub-routine that may include one or more statements designed to perform a specific task. To
write a 'C' program we first create functions and then put them together. A 'C' program may contain a one or
more sections. They are:-
1. The documentations section consists of comment lines giving the name of the program ,the author and
other details which the programmer would like to use later. These comments beginning with the two
Characters * and ending with the characters*.
2. The link section provides to the compiler to link functions from the system library
3. The definition section defines all symbolic constants.
There are some variables that are used in one or more functions, such variables are called global variables and
are declared in the global declaration section that is outside of all the functions.
4) Every C program must have one main () function section. This section can contain two parts; they are
Declaration part and Execution part.
The declaration part declares all the variables used in the executable part. There is at least one statement in
the executable part. These two parts can appear between the opening and closing braces. The program
execution begins at the opening braces and ends at the closing braces. The closing brace of the function section
is the logical end of the program.
All statements in the declaration and executable parts end with a semicolon.
The sub program section contains all the user defined functions that are called in the main () function. User
defined functions are generally placed immediately after the main function. All sections, except the main
function section may be absent when they are not required.
Programming Style
C is a free-form language.
That is, the C compiler does not care where on the line we begin typing.
C program statements are written in lowercase letters. Uppercase letters are used only for symbolic
constants.
Braces group program statements together and mark the beginning and the end of functions.
A proper indentation of braces and statements are indented.
Since C is a free-form language, we can group statements together on one line.
The statements may be written in one line like
main()
{
printf(“Hello C”)};
However, this style make the program more difficult to understand and should not be used.
Comments are included only to increase the readability but also help to understand the program logic.
This is very important for debugging and testing the program.
Executing A ‘C’ program:-
Executing a program written in C involves a series of steps. These are:
1. Creating the program
2. Compiling the program
3. Linking the program with functions that are needed from the C library
4. Executing the program.
Overview of C Mrs Sowmya Jyothi

More Related Content

What's hot

What's hot (20)

POINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdfPOINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
C Tokens
C TokensC Tokens
C Tokens
 
Unit 2. Elements of C
Unit 2. Elements of CUnit 2. Elements of C
Unit 2. Elements of C
 
String in c
String in cString in c
String in c
 
Function in c
Function in cFunction in c
Function in c
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programming
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Functions in c
Functions in cFunctions in c
Functions in c
 
C tokens
C tokensC tokens
C tokens
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Function in c
Function in cFunction in c
Function in c
 
Formatted input and output
Formatted input and outputFormatted input and output
Formatted input and output
 
Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming Language
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
 

Similar to Overview of C Mrs Sowmya Jyothi

C language introduction geeksfor geeks
C language introduction   geeksfor geeksC language introduction   geeksfor geeks
C language introduction geeksfor geeks
AashutoshChhedavi
 

Similar to Overview of C Mrs Sowmya Jyothi (20)

C programming course material
C programming course materialC programming course material
C programming course material
 
C language
C languageC language
C language
 
C language introduction geeksfor geeks
C language introduction   geeksfor geeksC language introduction   geeksfor geeks
C language introduction geeksfor geeks
 
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTTC programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
 
Programming in c
Programming in cProgramming in c
Programming in c
 
Book management system
Book management systemBook management system
Book management system
 
C programming
C programmingC programming
C programming
 
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxIIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
C notes diploma-ee-3rd-sem
C notes diploma-ee-3rd-semC notes diploma-ee-3rd-sem
C notes diploma-ee-3rd-sem
 
Overview of c
Overview of cOverview of c
Overview of c
 
Report on c and c++
Report on c and c++Report on c and c++
Report on c and c++
 
Introduction to C Unit 1
Introduction to C Unit 1Introduction to C Unit 1
Introduction to C Unit 1
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
C programming presentation(final)
C programming presentation(final)C programming presentation(final)
C programming presentation(final)
 
2.Overview of C language.pptx
2.Overview of C language.pptx2.Overview of C language.pptx
2.Overview of C language.pptx
 
C PROGRAMMING p-2.pdf
C PROGRAMMING p-2.pdfC PROGRAMMING p-2.pdf
C PROGRAMMING p-2.pdf
 
Notes of c programming 1st unit BCA I SEM
Notes of c programming  1st unit BCA I SEMNotes of c programming  1st unit BCA I SEM
Notes of c programming 1st unit BCA I SEM
 
chapter 1.pptx
chapter 1.pptxchapter 1.pptx
chapter 1.pptx
 
Unit 2 introduction to c programming
Unit 2   introduction to c programmingUnit 2   introduction to c programming
Unit 2 introduction to c programming
 

More from Sowmya Jyothi

More from Sowmya Jyothi (17)

Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
 
Functions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothiFunctions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothi
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
 
Bca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothiBca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothi
 
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHIBCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
 
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHIBCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
 
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHIBCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
 
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHIBCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
 
HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...
HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...
HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...
 
NETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHI
NETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHINETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHI
NETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHI
 
Introduction to computers MRS. SOWMYA JYOTHI
Introduction to computers MRS. SOWMYA JYOTHIIntroduction to computers MRS. SOWMYA JYOTHI
Introduction to computers MRS. SOWMYA JYOTHI
 
Introduction to graphics
Introduction to graphicsIntroduction to graphics
Introduction to graphics
 
Inter Process Communication PPT
Inter Process Communication PPTInter Process Communication PPT
Inter Process Communication PPT
 
Internal representation of file chapter 4 Sowmya Jyothi
Internal representation of file chapter 4 Sowmya JyothiInternal representation of file chapter 4 Sowmya Jyothi
Internal representation of file chapter 4 Sowmya Jyothi
 
Buffer cache unix ppt Mrs.Sowmya Jyothi
Buffer cache unix ppt Mrs.Sowmya JyothiBuffer cache unix ppt Mrs.Sowmya Jyothi
Buffer cache unix ppt Mrs.Sowmya Jyothi
 
Introduction to the Kernel Chapter 2 Mrs.Sowmya Jyothi
Introduction to the Kernel  Chapter 2 Mrs.Sowmya JyothiIntroduction to the Kernel  Chapter 2 Mrs.Sowmya Jyothi
Introduction to the Kernel Chapter 2 Mrs.Sowmya Jyothi
 
Introduction to Unix operating system Chapter 1-PPT Mrs.Sowmya Jyothi
Introduction to Unix operating system Chapter 1-PPT Mrs.Sowmya JyothiIntroduction to Unix operating system Chapter 1-PPT Mrs.Sowmya Jyothi
Introduction to Unix operating system Chapter 1-PPT Mrs.Sowmya Jyothi
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
Our Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdfOur Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 

Overview of C Mrs Sowmya Jyothi

  • 1. UNIT-I OVERVIEW OF C REFERENCE: PROGRAMMING IN C BY BALAGURUSWAMY MRS. SOWMYA JYOTHI, SDMCBM, MANGALORE
  • 2. AMERICAN NATIONAL STANDARD INSTITUTE INTERNATIONAL STANDARDS ORGANIZATION
  • 3. HISTORY OF C The root of all modern languages is ALGOL, introduced in the early 1960s. ALGOL was the first computer language to use a block structure. ALGOL gave the concept of structured programming to the computer science community. In 1967, Martin Richards developed a language called BCPL( Basic Combined Programming language) primarily for writing system software. In 1970, Ken Thompson created a language using many features of BCPL and called it simply B. B was used to create early versions of UNIX operating system at Bell Laboratories. C was evolved from ALGOL, BCPL and B by Dennis Ritchie at Bell Laboratories in 1972. C uses many concepts from these languages and added the concept of data types and other powerful features. Since it was developed along with the UNIX operating system, it is strongly associated with UNIX.
  • 5.
  • 6. Importance Of C 1. C is robust language whose rich setup of built in functions and operators can be used to write any complex program. 2. Programs written in C are efficient and fast due to several varieties of data types and powerful operators. 3. The C complier combines the capabilities of an assembly language with the feature of high level language. Therefore it is well suited for writing both system software and business package. 4. There are only 32 keywords, several standard functions are available which can be used for developing programs. 5. C is portable language this means that c programs written for one computer system can be run on another system, with little or no modification.
  • 7. 6. C language is well suited for structured programming, this requires user to think of a problems in terms of function or modules or block. A collection of these modules make a program debugging and testing easier. 7. C language has its ability to extend itself. A C program is basically a collection of functions that are supported by the C library. We can continuously add our own functions to the library with the availability of the large number of functions. 8. People use C programming language because it is easy to learn and understand. C is a high level language. C is case-sensitive language. C is a free-form language
  • 8. Sample C Program Program 1:- Printing a message main( ) { /* ……..printing begins………*/ printf(“I see, I remember”); /*………printing ends………*/ } Output: I see, I remember
  • 9. Sample C Program Program 1:- Printing a message main( ) { /* ……..printing begins………*/ printf(“I see, I remember”); /*………printing ends………*/ } The main( ) is a special function used by the C system to tell the computer where the program starts. Every program must have exactly one main function. The empty pair of parentheses immediately following main indicates that the function main has no arguments (or parameters). The opening brace “{“marks the beginning of the function main and the closing brace “}” indicates the end of the function. All the statements between these 2 braces form the function body. The function body contains a set of instructions to perform the given task. printf line is an executable statement. The lines beginning with /* and ending with */ are known as comment lines. These are used in a program to enhance its readability and understanding. Comment lines are not executable statements and therefore anything between /* and */ is ignored by the compiler. Every statement in C should end with a semicolon(;) mark.
  • 10.
  • 11. FORMAT OF SIMPLE C PROGRAMS
  • 12. Main function The main is a part of every C program. C permits different forms of main statement. Following forms are allowed. main( ) int main( ) void main( ) main(void) void main(void) int main(void) The empty pair of parentheses indicates that the function has no arguments. This may be explicitly indicated by using the keyword void inside the parentheses. We may also specify the keyword int or void before the word main. The keyword void means that the function does not return any information to the operating system and int means that the function returns an integer value to the operating system. When int is specified, the last statement in the program must be “return 0”.
  • 13.
  • 14. Program 2: Adding 2 numbers /*Program Addition*/ main( ) { int number; float amount; number=100; amount = 30.75 + 75.35; printf(“%dn”, number); printf(“%5.2f”, amount); }
  • 15. Program 2: Adding 2 numbers /*Program Addition*/ main( ) { int number; float amount; number=100; amount = 30.75 + 75.35; printf(“%dn”, number); printf(“%5.2f”, amount); } It is a good practice to use comment lines in the beginning to give information such as name of the program, author, date etc. The words number and amount are variable names that are used to store numeric data. The numeric data may be either in integer form or in real form. In C, all variables should be declared to tell the compiler what the variable names are and what type of data they hold. Declaration statements must appear at the beginning of the functions. All declaration statements end with a semicolon. The words such as int and float are called the keywords and cannot be used as variable names. Data is stored in a variable by assigning a data value to it.
  • 16. The #define directive A #define is a preprocessor compiler directive and not a statement. Therefore #define lines should not end with a semicolon. Symbolic constants are generally written in uppercase so that they are easily distinguished from lowercase variable names. #define instructions are usually placed at the beginning before the main( ) function. Symbolic constants are not declared in declaration section. Syntax: #define constantname value Example: #define PI 3.1415
  • 17.
  • 18. Program 3:- Interest calculation #define PERIOD 10 #define PRINCIPAL 5000.00 main( ) /*……….Main Program Begins……..*/ { int year; /*…………Declaration statements…………*/ float amount, value, inrate; amount = PRINCIPAL; /*…………Assignment Statements………….*/ inrate = 0.11; year = 0; while(year<=PERIOD) /*…………Computation using while loop…….*/ { printf(“%2d %8.2fn”,year,amount); value = amount + inrate +amount; year = year + 1; amount = value; } /*…………...while loop ends…………..*/ }
  • 19. #define instruction defines to a symbolic constant. Whenever a symbolic name is encountered, the compiler substitutes the value associated with the name automatically. To change the value, we have to change the definition. In this example, we have defined 2 symbolic constants PERIOD and PRINCIPAL and assigned values 10 and 5000.00 respectively. These values remain constant throughout the execution of the program. All computations and printing are accomplished in a while loop. While is a mechanism for evaluating repeatedly a statement or a group of statements. We exit the loop when year becomes greater than PERIOD.
  • 20. Program 4: Use of Subroutines int mul(int a, int b); main( ) { int a, b, c; a=5; b=10; c = mul(a,b); printf(“multiplication of %d and %d is %d”,a,b,c); } int mul(int x, int y) int p; { p = x * y; return(p); } /*………..Program Using Function…………*/ The mul function multiplies the values of x and y and the result is returned to the main( ) function when it is called in the statement c = mul(a,b); The mul( ) has 2 arguments x and y that are declared as integers. The values of a and b are passed on to x and y respectively when the function mul( ) is called.
  • 21. The #include directive C programs are divided into modules or functions. Some functions are written by users like us and many others are stored in the C library. Library functions are grouped category-wise and stored in different files known as header files. If we want to access the function stored in the library, it is necessary to tell the compiler about the files to be accessed. This is achieved by using the preprocessor directive #include as follows: #include<filename> Filename is the name of the library file that contains the required function definition. Preprocessor directives are placed at the beginning of a program. Example: #include<stdio.h> - standard input output header file #include<math.h>
  • 22. Program 5:- Use of math functions /*……..Program using cosine function………….*/ #include<math.h> #define PI 3.1416 #define MAX 180 main( ) { int angle; float x, y; angle = 0; printf(“ Angle Cos(angle)nn”); while(angle <= MAX) { x= (PI / MAX) * angle; y= cos(x); printf(“%15d %13.4fn”, angle,y); angle = angle + 10; } }
  • 23. Program 5:- Use of math functions /*……..Program using cosine function………….*/ #include<math.h> #define PI 3.1416 #define MAX 180 main( ) { int angle; float x, y; angle = 0; printf(“ Angle Cos(angle)nn”); while(angle <= MAX) { x= (PI / MAX) * angle; y= cos(x); printf(“%15d %13.4fn”, angle,y); angle = angle + 10; } } The standard mathematical functions are defined and kept as a part of C math library. If we want to use any of these mathematical functions, we must add an #include instruction in the program. #include is a compiler directive that instructs the compiler to link the specified mathematical functions from the library. #include<math.h> Math.h is the filename containing the required function. Another #include instruction that is often required is #include<stdio.h> stdio.h refers to the standard I/O header file containing input and output functions
  • 24. The #define directive A #define is a preprocessor compiler directive and not a statement. Therefore #define lines should not end with a semicolon. Symbolic constants are generally written in uppercase so that they are easily distinguished from lowercase variable names. #define instructions are usually placed at the beginning before the main( ) function. Symbolic constants are not declared in declaration section. Syntax: #define constantname value Example: #define PI 3.1415
  • 25. BASIC STRUCTURE OF C PROGRAM
  • 26.
  • 27. A 'C' program can be viewed as a group of building blocks called functions. A function is a sub-routine that may include one or more statements designed to perform a specific task. To write a 'C' program we first create functions and then put them together. A 'C' program may contain a one or more sections. They are:- 1. The documentations section consists of comment lines giving the name of the program ,the author and other details which the programmer would like to use later. These comments beginning with the two Characters * and ending with the characters*. 2. The link section provides to the compiler to link functions from the system library 3. The definition section defines all symbolic constants. There are some variables that are used in one or more functions, such variables are called global variables and are declared in the global declaration section that is outside of all the functions.
  • 28. 4) Every C program must have one main () function section. This section can contain two parts; they are Declaration part and Execution part. The declaration part declares all the variables used in the executable part. There is at least one statement in the executable part. These two parts can appear between the opening and closing braces. The program execution begins at the opening braces and ends at the closing braces. The closing brace of the function section is the logical end of the program. All statements in the declaration and executable parts end with a semicolon. The sub program section contains all the user defined functions that are called in the main () function. User defined functions are generally placed immediately after the main function. All sections, except the main function section may be absent when they are not required.
  • 29. Programming Style C is a free-form language. That is, the C compiler does not care where on the line we begin typing. C program statements are written in lowercase letters. Uppercase letters are used only for symbolic constants. Braces group program statements together and mark the beginning and the end of functions. A proper indentation of braces and statements are indented. Since C is a free-form language, we can group statements together on one line. The statements may be written in one line like main() { printf(“Hello C”)}; However, this style make the program more difficult to understand and should not be used. Comments are included only to increase the readability but also help to understand the program logic. This is very important for debugging and testing the program.
  • 30. Executing A ‘C’ program:- Executing a program written in C involves a series of steps. These are: 1. Creating the program 2. Compiling the program 3. Linking the program with functions that are needed from the C library 4. Executing the program.