SlideShare a Scribd company logo
1 of 11
© 2015UPESJuly 2015 Department. Of Civil Engineering
UNIT-2
Introduction to C programming,
control and flow instructions
© 2015UPESJuly 2015 Department. Of Civil Engineering
INTRODUCTION
C was developed in the early 1970s by Dennis Ritchie at Bell Laboratories
C was initially developed for writing system software
Today, C has become a popular language and various software programs are written using this language.
Many other commonly used programming languages such as C++ and Java are also based on C
Characteristics of C
A high level programming language
Small size. C has only 32 keywords. This makes it relatively easy to learn
Makes extensive use of function calls
C is well suited for structured programming.
Unlike PASCAL it supports loose typing (as a character can be treated as an integer and vice versa)
Stable language.
Quick language
Facilitates low level (bitwise) programming
Supports pointers to refer computer memory, array, structures and functions.
C is a core language
C is a portable language.
C is an extensible language
© 2015UPESJuly 2015 Department. Of Civil Engineering
USES OF C
C language is primarily used for system programming. The portability, efficiency,
the ability to access specific hardware addresses and low runtime demand on
system resources makes it a good choice for implementing operating systems and
embedded system applications.
C has been so widely accepted by professionals that compilers, libraries, and
interpreters of other programming languages are often implemented in C.
For portability and convenience reasons, C is sometimes used as an intermediate
language by implementations of other languages. Example of compilers which use
C this way are BitC, Gambit, the Glasgow Haskell Compiler, Squeak, and Vala.
C is widely used to implement end-user applications
STRUCTURE OF A C PROGRAM
main()
{
Statement 1;
Statement 2;
……………
……………
Statement N;
}
Function1()
{
Statement 1;
Statement 2;
……………
……………
Statement N;
}
Function2()
{
Statement 1;
Statement 2;
……………
……………
Statement N;
}
………………….
………………….
FunctionN()
{
Statement 1;
Statement 2;
……………
……………
Statement N;
}
A C program contains one or more functions
The statements in a C program are written in a logical sequence to perform a
specific task.
Execution of a C program begins at the main() function
You can choose any name for the functions. Every program must contain one
function that has its name as main().
© 2015UPESJuly 2015 Department. Of Civil Engineering
YOUR FIRST C PROGRAM
// This is my first program in C
#include<stdio.h>
int main()
{
printf("n Welcome to the world of C ");
return 0;
}
© 2015UPESJuly 2015 Department. Of Civil Engineering
Basic Structure of C Program
© 2015UPESJuly 2015 Department. Of Civil Engineering
FILES USED IN A C PROGRAM
Source code file
 The source code file contains the source code of the program. The file extension of any C source code file
is “.c”. This file contains C source code that defines the main function and maybe other functions. The
main() is the starting point of execution when you successfully compile and run the program. A C program
in general may include even other source code files (with the file extension .c).
 Header Files
 When working with large projects, it is often desirable to make sub-routines and store them in a different
file known as header file. The advantage of header files can be realized when : a) The programmer wants
to use the same subroutines in different programs.
b) The programmer wants to change, or add, subroutines, and have those changes be reflected in all other
programs.
 Conventionally, header files names ends with a “.h” extension and its name can use only letters, digits,
dashes, and underscores.
 While some standard header files are available in C, but the programmer may also create his own user
defined header files
Files in a C program
Source File Header File Object File Executable File
© 2015UPESJuly 2015 Department. Of Civil Engineering
FILES USED IN A C PROGRAM contd.
Object Files
 Object files are generated by the compiler as a result of processing the source code file. Object
files contain compact binary code of the function definitions. Linker uses this object file to
produce an executable file (.exe file) by combining the of object files together. Object files
have a “.o” extension, although some operating systems including Windows and MS-DOS
have a “.obj” extension for the object file.
Binary Executable File
 The binary executable file is generated by the linker. The linker links the various object files to
produce a binary file that can be directly executed.
COMPILING AND EXECUTING C PROGRAMS
The compilation process in the figure 2.5 is done in two steps.
In the first step, the preprocessor program reads the source file as text, and produces another text
file as output. Source code lines which begin with the hash symbol are actually not written in C
but in the preprocessor language. The output of the preprocessor is a text file which does not
contain any preprocessor statements. This file is ready to be processed by the compiler.
The linker combines the object file with library routines (supplied with the compiler) to produce
the final executable file.
© 2015UPESJuly 2015 Department. Of Civil Engineering
Compiling and Linking in One Step
 Example Program Hello World (C Version)
File hello.c:
#include <stdio.h>
main ()
{
printf("Hello worldn");}
 gcc hello.c carries out both the compiling (preprocessing,
compiling and assembling) and linking processes in a single
step. The default name of the output file is a.out.
 Use the -o option to create an output file with a different name:
gcc hello.c -o hello
© 2015UPESJuly 2015 Department. Of Civil Engineering
Compilation and Linking in Several Steps
 Preprocessing only
gcc -E hello.c -o hello.i
hello.i contains the source code with all macros expanded.
 To stop after the stage of compilation proper and produce assembly
language in hello.s:
gcc -S hello.i
 Compiling without linking can be done with the -c option. The output
file will be hello.o and will contain object code.
gcc -c hello.s (contains the assembly language code)
# as helloworld.s -o helloworld.o
Linking
gcc -o hello hello.o
© 2015UPESJuly 2015 Department. Of Civil Engineering
COMPILING AND EXECUTING C PROGRAMS
Source
File
Library
Files
Source
File
Library
Files
Pre-
proce
ss
Pre-
proce
ss
Compiler
Compiler
Object
Files
Object
Files
Library
Files
Linker Executable
Files
© 2015UPESJuly 2015 Department. Of Civil Engineering
USING COMMENTS
 It is a good programming practice to place some comments in the code to help the reader understand
the code clearly.
 Comments are just a way of explaining what a program does. It is merely an internal program
documentation.
 The compiler ignores the comments when forming the object file. This means that the comments are
non-executable statements.
C supports two types of commenting. // is used to comment a single statement. This is known as a line
comment. A line comment can be placed anywhere on the line and it does not require to be
specifically ended as the end of the line automatically ends the line.
 /* is used to comment multiple statements. A /* is ended with */ and all statements that lie within
these characters are commented.
KEYWORDS
 C has a set of 32 reserved words often known as keywords. All keywords are basically a sequence of
characters that have a fixed meaning. By convention all keywords must be written in lowercase
(small) letters.
 Example: for, while, do-while, auto break, case, char, continue, do, double, else, enum, extern, float,
goto, if, int, long, register, return, short, signed, sizeof, static, struct, switch, typedef, union,
unsigned, void, volatile

More Related Content

What's hot

C programming short notes by pulkit modi
C programming short notes by pulkit modiC programming short notes by pulkit modi
C programming short notes by pulkit modiPulkitmodi1998
 
What is c#
What is c#What is c#
What is c#shwet18
 
1. over view and history of c
1. over view and history of c1. over view and history of c
1. over view and history of cHarish Kumawat
 
A Research Study of Data Collection and Analysis of Semantics of Programming ...
A Research Study of Data Collection and Analysis of Semantics of Programming ...A Research Study of Data Collection and Analysis of Semantics of Programming ...
A Research Study of Data Collection and Analysis of Semantics of Programming ...IRJET Journal
 
Programming language
Programming languageProgramming language
Programming languageDhani Ahmad
 
5.Hello World program Explanation. ||C Programming tutorial.
5.Hello World program Explanation. ||C Programming tutorial.5.Hello World program Explanation. ||C Programming tutorial.
5.Hello World program Explanation. ||C Programming tutorial.Fiaz Hussain
 
Turbo C Compiler Reports
Turbo C Compiler Reports Turbo C Compiler Reports
Turbo C Compiler Reports Sunil Kumar R
 
3. Introduction to C language ||Learn C Programming Complete.
3. Introduction to C language ||Learn C Programming Complete.3. Introduction to C language ||Learn C Programming Complete.
3. Introduction to C language ||Learn C Programming Complete.Fiaz Hussain
 
1 introduction to c programming language
1 introduction to c programming language1 introduction to c programming language
1 introduction to c programming languageNarendra Soni
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming LanguageRamaBoya2
 
PROGRAMMING LANGUAGES
PROGRAMMING LANGUAGESPROGRAMMING LANGUAGES
PROGRAMMING LANGUAGESABHINAV SINGH
 
Programming languages
Programming languagesProgramming languages
Programming languagesSimon Mui
 

What's hot (20)

Since the release of c
Since the release of cSince the release of c
Since the release of c
 
C programming short notes by pulkit modi
C programming short notes by pulkit modiC programming short notes by pulkit modi
C programming short notes by pulkit modi
 
Oops index
Oops indexOops index
Oops index
 
What is c#
What is c#What is c#
What is c#
 
Characteristics of c#
Characteristics of c#Characteristics of c#
Characteristics of c#
 
1. over view and history of c
1. over view and history of c1. over view and history of c
1. over view and history of c
 
Compiler lec 1
Compiler lec 1Compiler lec 1
Compiler lec 1
 
C# Introduction brief
C# Introduction briefC# Introduction brief
C# Introduction brief
 
C language part 1
C language part  1C language part  1
C language part 1
 
A Research Study of Data Collection and Analysis of Semantics of Programming ...
A Research Study of Data Collection and Analysis of Semantics of Programming ...A Research Study of Data Collection and Analysis of Semantics of Programming ...
A Research Study of Data Collection and Analysis of Semantics of Programming ...
 
Programming language
Programming languageProgramming language
Programming language
 
5.Hello World program Explanation. ||C Programming tutorial.
5.Hello World program Explanation. ||C Programming tutorial.5.Hello World program Explanation. ||C Programming tutorial.
5.Hello World program Explanation. ||C Programming tutorial.
 
Turbo C Compiler Reports
Turbo C Compiler Reports Turbo C Compiler Reports
Turbo C Compiler Reports
 
3. Introduction to C language ||Learn C Programming Complete.
3. Introduction to C language ||Learn C Programming Complete.3. Introduction to C language ||Learn C Programming Complete.
3. Introduction to C language ||Learn C Programming Complete.
 
1 introduction to c programming language
1 introduction to c programming language1 introduction to c programming language
1 introduction to c programming language
 
C compilation process
C compilation processC compilation process
C compilation process
 
C
CC
C
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
 
PROGRAMMING LANGUAGES
PROGRAMMING LANGUAGESPROGRAMMING LANGUAGES
PROGRAMMING LANGUAGES
 
Programming languages
Programming languagesProgramming languages
Programming languages
 

Similar to Unit 2 l1

C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptxMugilvannan11
 
Lecture-1&2.pdf Visual Programming C# .net framework
Lecture-1&2.pdf Visual Programming C# .net frameworkLecture-1&2.pdf Visual Programming C# .net framework
Lecture-1&2.pdf Visual Programming C# .net frameworkAbdullahNadeem78
 
CS8251_QB_answers.pdf
CS8251_QB_answers.pdfCS8251_QB_answers.pdf
CS8251_QB_answers.pdfvino108206
 
Unit-2_Getting Started With ‘C’ Language (3).pptx
Unit-2_Getting Started With ‘C’ Language (3).pptxUnit-2_Getting Started With ‘C’ Language (3).pptx
Unit-2_Getting Started With ‘C’ Language (3).pptxSanketShah544615
 
Basics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxBasics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxCoolGamer16
 
C programming slide day 01 uploadd by md abdullah al shakil
C programming slide day 01 uploadd by md abdullah al shakilC programming slide day 01 uploadd by md abdullah al shakil
C programming slide day 01 uploadd by md abdullah al shakilZenith SVG
 
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 CANTTBatra Centre
 
Understanding C and its Applications.pdf
Understanding C and its Applications.pdfUnderstanding C and its Applications.pdf
Understanding C and its Applications.pdfAdeleHansley
 
Intoduction to c language
Intoduction to c languageIntoduction to c language
Intoduction to c languageStudent
 
Introduction To C++ programming and its basic concepts
Introduction To C++ programming and its basic conceptsIntroduction To C++ programming and its basic concepts
Introduction To C++ programming and its basic conceptsssuserf86fba
 
C Unit 1 notes PREPARED BY MVB REDDY
C Unit 1 notes PREPARED BY MVB REDDYC Unit 1 notes PREPARED BY MVB REDDY
C Unit 1 notes PREPARED BY MVB REDDYRajeshkumar Reddy
 

Similar to Unit 2 l1 (20)

Unit 2 ppt
Unit 2 pptUnit 2 ppt
Unit 2 ppt
 
Introduction to c language
Introduction to c language Introduction to c language
Introduction to c language
 
C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptx
 
Lecture-1&2.pdf Visual Programming C# .net framework
Lecture-1&2.pdf Visual Programming C# .net frameworkLecture-1&2.pdf Visual Programming C# .net framework
Lecture-1&2.pdf Visual Programming C# .net framework
 
Programming in c
Programming in cProgramming in c
Programming in c
 
CS8251_QB_answers.pdf
CS8251_QB_answers.pdfCS8251_QB_answers.pdf
CS8251_QB_answers.pdf
 
Unit-2_Getting Started With ‘C’ Language (3).pptx
Unit-2_Getting Started With ‘C’ Language (3).pptxUnit-2_Getting Started With ‘C’ Language (3).pptx
Unit-2_Getting Started With ‘C’ Language (3).pptx
 
INTRODUCTION TO C LANGUAGE.pptx
INTRODUCTION TO C LANGUAGE.pptxINTRODUCTION TO C LANGUAGE.pptx
INTRODUCTION TO C LANGUAGE.pptx
 
Basics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxBasics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptx
 
C programming slide day 01 uploadd by md abdullah al shakil
C programming slide day 01 uploadd by md abdullah al shakilC programming slide day 01 uploadd by md abdullah al shakil
C programming slide day 01 uploadd by md abdullah al shakil
 
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
 
C language
C languageC language
C language
 
Unit 1.1 - Introduction to C.pptx
Unit 1.1 - Introduction to C.pptxUnit 1.1 - Introduction to C.pptx
Unit 1.1 - Introduction to C.pptx
 
Understanding C and its Applications.pdf
Understanding C and its Applications.pdfUnderstanding C and its Applications.pdf
Understanding C and its Applications.pdf
 
Intoduction to c language
Intoduction to c languageIntoduction to c language
Intoduction to c language
 
Introduction To C++ programming and its basic concepts
Introduction To C++ programming and its basic conceptsIntroduction To C++ programming and its basic concepts
Introduction To C++ programming and its basic concepts
 
C Unit 1 notes PREPARED BY MVB REDDY
C Unit 1 notes PREPARED BY MVB REDDYC Unit 1 notes PREPARED BY MVB REDDY
C Unit 1 notes PREPARED BY MVB REDDY
 
C lecture notes new
C lecture notes newC lecture notes new
C lecture notes new
 
CS3251-_PIC
CS3251-_PICCS3251-_PIC
CS3251-_PIC
 
8844632.ppt
8844632.ppt8844632.ppt
8844632.ppt
 

More from Mitali Chugh (20)

Loc and function point
Loc and function pointLoc and function point
Loc and function point
 
Unit1
Unit1Unit1
Unit1
 
Module 4
Module 4Module 4
Module 4
 
Blogs
BlogsBlogs
Blogs
 
Module 5 and 6
Module 5 and 6Module 5 and 6
Module 5 and 6
 
Types of computer
Types of computerTypes of computer
Types of computer
 
Module 2 os
Module 2 osModule 2 os
Module 2 os
 
Os ppt
Os pptOs ppt
Os ppt
 
Upes ppt template
Upes ppt templateUpes ppt template
Upes ppt template
 
Functions
FunctionsFunctions
Functions
 
Structures
StructuresStructures
Structures
 
Functions
FunctionsFunctions
Functions
 
Strings
StringsStrings
Strings
 
Arrays
ArraysArrays
Arrays
 
Control flow stataements
Control flow stataementsControl flow stataements
Control flow stataements
 
Unit1
Unit1Unit1
Unit1
 
How to compile and run a c program on ubuntu linux
How to compile and run a c program on ubuntu linuxHow to compile and run a c program on ubuntu linux
How to compile and run a c program on ubuntu linux
 
Blogs
BlogsBlogs
Blogs
 
Module 4
Module 4Module 4
Module 4
 
Module 3
Module 3Module 3
Module 3
 

Recently uploaded

Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 

Recently uploaded (20)

Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 

Unit 2 l1

  • 1. © 2015UPESJuly 2015 Department. Of Civil Engineering UNIT-2 Introduction to C programming, control and flow instructions
  • 2. © 2015UPESJuly 2015 Department. Of Civil Engineering INTRODUCTION C was developed in the early 1970s by Dennis Ritchie at Bell Laboratories C was initially developed for writing system software Today, C has become a popular language and various software programs are written using this language. Many other commonly used programming languages such as C++ and Java are also based on C Characteristics of C A high level programming language Small size. C has only 32 keywords. This makes it relatively easy to learn Makes extensive use of function calls C is well suited for structured programming. Unlike PASCAL it supports loose typing (as a character can be treated as an integer and vice versa) Stable language. Quick language Facilitates low level (bitwise) programming Supports pointers to refer computer memory, array, structures and functions. C is a core language C is a portable language. C is an extensible language
  • 3. © 2015UPESJuly 2015 Department. Of Civil Engineering USES OF C C language is primarily used for system programming. The portability, efficiency, the ability to access specific hardware addresses and low runtime demand on system resources makes it a good choice for implementing operating systems and embedded system applications. C has been so widely accepted by professionals that compilers, libraries, and interpreters of other programming languages are often implemented in C. For portability and convenience reasons, C is sometimes used as an intermediate language by implementations of other languages. Example of compilers which use C this way are BitC, Gambit, the Glasgow Haskell Compiler, Squeak, and Vala. C is widely used to implement end-user applications STRUCTURE OF A C PROGRAM main() { Statement 1; Statement 2; …………… …………… Statement N; } Function1() { Statement 1; Statement 2; …………… …………… Statement N; } Function2() { Statement 1; Statement 2; …………… …………… Statement N; } …………………. …………………. FunctionN() { Statement 1; Statement 2; …………… …………… Statement N; } A C program contains one or more functions The statements in a C program are written in a logical sequence to perform a specific task. Execution of a C program begins at the main() function You can choose any name for the functions. Every program must contain one function that has its name as main().
  • 4. © 2015UPESJuly 2015 Department. Of Civil Engineering YOUR FIRST C PROGRAM // This is my first program in C #include<stdio.h> int main() { printf("n Welcome to the world of C "); return 0; }
  • 5. © 2015UPESJuly 2015 Department. Of Civil Engineering Basic Structure of C Program
  • 6. © 2015UPESJuly 2015 Department. Of Civil Engineering FILES USED IN A C PROGRAM Source code file  The source code file contains the source code of the program. The file extension of any C source code file is “.c”. This file contains C source code that defines the main function and maybe other functions. The main() is the starting point of execution when you successfully compile and run the program. A C program in general may include even other source code files (with the file extension .c).  Header Files  When working with large projects, it is often desirable to make sub-routines and store them in a different file known as header file. The advantage of header files can be realized when : a) The programmer wants to use the same subroutines in different programs. b) The programmer wants to change, or add, subroutines, and have those changes be reflected in all other programs.  Conventionally, header files names ends with a “.h” extension and its name can use only letters, digits, dashes, and underscores.  While some standard header files are available in C, but the programmer may also create his own user defined header files Files in a C program Source File Header File Object File Executable File
  • 7. © 2015UPESJuly 2015 Department. Of Civil Engineering FILES USED IN A C PROGRAM contd. Object Files  Object files are generated by the compiler as a result of processing the source code file. Object files contain compact binary code of the function definitions. Linker uses this object file to produce an executable file (.exe file) by combining the of object files together. Object files have a “.o” extension, although some operating systems including Windows and MS-DOS have a “.obj” extension for the object file. Binary Executable File  The binary executable file is generated by the linker. The linker links the various object files to produce a binary file that can be directly executed. COMPILING AND EXECUTING C PROGRAMS The compilation process in the figure 2.5 is done in two steps. In the first step, the preprocessor program reads the source file as text, and produces another text file as output. Source code lines which begin with the hash symbol are actually not written in C but in the preprocessor language. The output of the preprocessor is a text file which does not contain any preprocessor statements. This file is ready to be processed by the compiler. The linker combines the object file with library routines (supplied with the compiler) to produce the final executable file.
  • 8. © 2015UPESJuly 2015 Department. Of Civil Engineering Compiling and Linking in One Step  Example Program Hello World (C Version) File hello.c: #include <stdio.h> main () { printf("Hello worldn");}  gcc hello.c carries out both the compiling (preprocessing, compiling and assembling) and linking processes in a single step. The default name of the output file is a.out.  Use the -o option to create an output file with a different name: gcc hello.c -o hello
  • 9. © 2015UPESJuly 2015 Department. Of Civil Engineering Compilation and Linking in Several Steps  Preprocessing only gcc -E hello.c -o hello.i hello.i contains the source code with all macros expanded.  To stop after the stage of compilation proper and produce assembly language in hello.s: gcc -S hello.i  Compiling without linking can be done with the -c option. The output file will be hello.o and will contain object code. gcc -c hello.s (contains the assembly language code) # as helloworld.s -o helloworld.o Linking gcc -o hello hello.o
  • 10. © 2015UPESJuly 2015 Department. Of Civil Engineering COMPILING AND EXECUTING C PROGRAMS Source File Library Files Source File Library Files Pre- proce ss Pre- proce ss Compiler Compiler Object Files Object Files Library Files Linker Executable Files
  • 11. © 2015UPESJuly 2015 Department. Of Civil Engineering USING COMMENTS  It is a good programming practice to place some comments in the code to help the reader understand the code clearly.  Comments are just a way of explaining what a program does. It is merely an internal program documentation.  The compiler ignores the comments when forming the object file. This means that the comments are non-executable statements. C supports two types of commenting. // is used to comment a single statement. This is known as a line comment. A line comment can be placed anywhere on the line and it does not require to be specifically ended as the end of the line automatically ends the line.  /* is used to comment multiple statements. A /* is ended with */ and all statements that lie within these characters are commented. KEYWORDS  C has a set of 32 reserved words often known as keywords. All keywords are basically a sequence of characters that have a fixed meaning. By convention all keywords must be written in lowercase (small) letters.  Example: for, while, do-while, auto break, case, char, continue, do, double, else, enum, extern, float, goto, if, int, long, register, return, short, signed, sizeof, static, struct, switch, typedef, union, unsigned, void, volatile