SlideShare una empresa de Scribd logo
1 de 20
Modelling 2A
C Lecture 1
Chapter 3
Philip Robinson
2015
Compiling a program
• The typical process for creation of a program is
– Editing the source code using a text editor
– Compilation of source code resulting in object code
– Linking of any required external libraries or code which results in an
executable file.
– This file can be executed by the OS
2
source file linkercompiler
source
file
object
file
executable
file
Included Libraries
The Command Line
• A command-line interface (CLI) is a mechanism for interacting
with a computer operating system or software by typing text
commands to perform specific tasks.
• The commands that are executed are themselves small programs
that together make up the operating system.
– Eg. Copy, Del, Move
• The command prompt represents a position in the file system of
the computer
• Some useful command for navigating the file system:
– cd is change directory (cd .. goes down one directory)
– dir gives you a list of all the folders and files in the current folder
• If you type the name of an executable file that is in the same path
as the command prompt the OS will run that program
3
Compiling a program
• Originally programs were edited using a text editing program and
then compiled using the command line interface to run the
Compiler and provide it with the source code file that needs to be
compiled
– Eg. C:>gcc simple.c –o output.exe
• The most popular way to create programs is to use an Integrated
Development Environment (IDE)
– Single program that provides the functions of a text editor, compiler and
debugger.
– For C/C++ development Dev-C++ and Code::Blocks are popular free IDE’s
4
Four steps to writing a C program
1. Typing in the code in a text window and saving the
resulting text as a separate file (source file). The text of a
C program is stored in a file with the extension .c for C
programming language
2. Compiling the code produces an intermediate object file -
with the extension .obj or .o. The source file must be
translated into binary numbers understandable to the
computer's Central Processing Unit This process
3. Linking the code to include library routines (routines
written by the manufacturer of the compiler to perform a
variety of tasks, from input/output to complicated
mathematical functions). In the case of C the standard
input and output functions are contained in a library
(stdio.h) so even the most basic program will require a
library function. After linking the file extension is .exe which
are executable files
4. Executing (running) the code. Run .exe files as you can
other applications, simply by typing their names at the
DOS prompt
5
Pass 1: Quick Synopsis
• The first line tells the computer to include information found in the
file stdio.h, which file is part of the C compiler package:
• #include <stdio.h> <= Include another file
• C programs consist of one or more functions, which are the basic
modules of a C program.
• This program consists of one function called main.
• The parentheses identify main() as a function name:
• main() <= Function name
• You can use the symbols /* and */ to enclose Comments, which
are remarks to help clarify a program. They are intended only for
the reader and are ignored by the computer:
• /* a simple program */ <= Comment
• // comment <= Single line comment
6
Pass 1: Quick Synopsis
• The opening brace { marks the start of the statements that make
up the function.
• The function definition is ended with a closing brace }
• { <.=Beginning of the body of the function
• The declaration statement announces that we will use a variable
called num and that num is an integer:
• int num; <= Declaration statement
• The assignment statement assigns the value 1 to num:
• num = 1; <= Assignment statement
• C statements all use the semi-colon ; to terminate!
7
Pass 1: Quick Synopsis
• The following line prints the phrase within the quotation marks (I
am a simple).
• printf(”I am a simple “);<= Print statement
• The following line prints the word computer to the end of the last
phrase printed. The n tells the computer to start a new line:
• printf (“computer .n”); <= Another print statement
• The following line prints the value of num (which is 1) embedded
in the phrase quotation marks. The %d instructs the computer
where and in what form to print n value:
• printf(”My favourite number is %d because It is first.n”, num);
• As noted earlier, the program ends with a closing brace:
• } <= Program end
8
Pass 2: Details
• #include Directives and Header Files
– The stdio.h file is supplied as part of a C compiler package,
and it contains information about input and output functions
(such as printf (for the compiler to use:
• #include <stdio.h>
– The name stands for standard input/output header.
– C users refer to a collection of information that goes at the top
of a file as the header, and C implementations typically come
with several header files.
• The effect of #include <stdio.h> is the same as if we were to copy
the entire contents of the stdio.h file into our file at the position the
line appears.
• Such #include files provide a convenient way to handle
information that is required by many programs.
• Note the use of the angle brackets (< and >) around the header's
name. These indicate that the header file is to be looked for on
the system disk which stores the rest of the C program application9
Pass 2: Details
• The main( ) Function
• All C programs will consist of at least one function, but it is usual
to write a C program that comprises several functions.
• The only function that has to be present is the function called
main.
• For more advanced programs the main function will act as a
controlling function calling other functions in their turn to do the
dirty work
• The main function is the entry point into the program and is the
first function that is called when your program executes.
• The parentheses following a function name generally enclose
information being passed along to the function. For our simple
example, nothing is passed along with main( ), so the parenthesis
remain empty.
• The int indicates the return data type from the main function.
10
Pass 2: Details
• Comments
• Using comments makes it easier for someone (including yourself)
to understand your program by adding descriptions.
• Everything between the opening /* and the closing */ is ignored by
the compiler:
– /* a simple program */
• // indicates a single line comment. Anything appearing in a line
following // will be ignored by the compiler
– int num; //this will be ignored.
11
Pass 2: Details
• Braces ({,}) mark the beginning as well as the end of the body of
a function:
• {
• .
• .
• .
• }
• Braces also mark the beginning and end of blocks of statements
within flow constructs such as if, for, while and switch constructs.
12
Pass 2: Details
• Declarations
• The declaration statement is one of the most important features of
C.
– As noted earlier, our example declares two things:
– int num;
• First, somewhere in the function, we use a variable having the
name num.
– In C, all variables must be declared, which means you must
list all the variables you use in a program, and you must show
what “type” each variable is.
– Second, int proclaims num as an integer, that is, a whole
number without a decimal point.
• The word int is a C keyword that identifies one of the basic C data
types.
• Keywords are specific words used to express a language; they
may not be usurped for other purposes.
13
Pass 2: Details
• The compiler uses the information in the declaration statement to
arrange for suitable storage space in memory for the num
variable.
• The semicolon at the end of the line identifies the line as a C
statement or instruction.
• Data Types
• C deals with several kinds (or types) of data: integers, characters,
and floating point numbers for example.
• Declaring a variable to be an integer or a character type makes it
possible for the computer to store, fetch, and interpret the data
properly.
• An integer and a single precision floating point variable are
represented in memory using the same number of bits but the
compiler knows how to interpret those bits to represent:
– a integer ranging from -32768 to 32767
– or a float ranging from 3.4x10-38 to 3.4x10+38
14
Pass 2: Details
• Name Choice
• Use meaningful names for variables.
• The number of characters you can use varies among
implementations.
• To name variables you may use lowercase letters, uppercase
letters, digits, and the underscore (_), which is counted as a letter.
• The first character must be a letter. The following are some
examples:
15
Valid Names Invalid names
Squiggles &^#Z**
cat1 1cat
Human_names Human-names
_iCounter Don’t
Pass 2: Details
• Assignments
• The assignment statement is one of the most basic operations.
– num = 1;
• In our example, the assignment statement means “give the
variable num the value of 1”.
• Note that the assignment statement, like the declaration
statement, is completed with a semicolon.
16
Functions
• A function contains a set of instructions that are executed
whenever that function is called.
• To call a function you need only to use its name followed by
brackets
– Eg printf();
• It is possible to send data to a function by making use of the
parameters defined by the function. These parameters will be
places between the brackets following the function name.
– Eg. sum(2,5)
• Defining parameters in a function are optional.
• A function can also return resulting value but this is not required.
17
Printf()
• The function writes a sequence of data to the standard output.
• The text sequence to be written is passed to the printf() function
via its first parameter.
• A string of text must be bounded by “ ”
• There are special types of characters that affect how this string is
printed to the screen
• Escape sequence characters represent characters that are not
possible to type on a keyboard but are understood by a computer
such as tabs and newline characters.
• These characters are preceded with a 
• Example
– n represents a new line
– t represents a tab
18
Printf()
• The sequence can be formatted using a set of specifiers
– %d or %i Decimal Signed Integer
– %f Decimal floating point number
– …many more
• These specifiers are placeholders that tell the printf() function
where to print the value of variables specified by the parameters
that follow the first control string parameter.
• Printf(“This is an integer %d, this is a double %f.”,12, 12.55);
– This is an integer 12, this is a double 12.55.
• Can specify formatting of numbers
– Printf(“This is an integer %3d, this is a double %4.3f.”,12, 12.55);
– This is an integer 012, this is a double 0012.550.
• http://www.cplusplus.com/reference/clibrary/cstdio/printf/
19
Libraries
• For the purpose of modularity it is possible to create a source
code file that contains a collection of functions that are used often.
• So that it is not necessary to include the source of these common
functions in every source code file you write it is possible to just
link a library that contains the functions to your program.
• This is done using the #include directive
– E.g. #include <math.h>
• This directive essentially copies the contents of the library into
that position in your program source code and after this directive
one can access the functions in the library as if they were
declared.
20

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 
Unit 2 introduction to c programming
Unit 2   introduction to c programmingUnit 2   introduction to c programming
Unit 2 introduction to c programming
 
The C++ Programming Language
The C++ Programming LanguageThe C++ Programming Language
The C++ Programming Language
 
Compiler Design File
Compiler Design FileCompiler Design File
Compiler Design File
 
Compiler Design Material
Compiler Design MaterialCompiler Design Material
Compiler Design Material
 
Lexical Analysis
Lexical AnalysisLexical Analysis
Lexical Analysis
 
Compiler Design Tutorial
Compiler Design Tutorial Compiler Design Tutorial
Compiler Design Tutorial
 
C Programming - Refresher - Part IV
C Programming - Refresher - Part IVC Programming - Refresher - Part IV
C Programming - Refresher - Part IV
 
C languaGE UNIT-1
C languaGE UNIT-1C languaGE UNIT-1
C languaGE UNIT-1
 
C programming
C programming C programming
C programming
 
what is compiler and five phases of compiler
what is compiler and five phases of compilerwhat is compiler and five phases of compiler
what is compiler and five phases of compiler
 
Chapter 3(1)
Chapter 3(1)Chapter 3(1)
Chapter 3(1)
 
Hm system programming class 1
Hm system programming class 1Hm system programming class 1
Hm system programming class 1
 
Handout#01
Handout#01Handout#01
Handout#01
 
Principles of compiler design
Principles of compiler designPrinciples of compiler design
Principles of compiler design
 
File handling With Solve Programs
File handling With Solve ProgramsFile handling With Solve Programs
File handling With Solve Programs
 
Phases of the Compiler - Systems Programming
Phases of the Compiler - Systems ProgrammingPhases of the Compiler - Systems Programming
Phases of the Compiler - Systems Programming
 
Cp week _2.
Cp week _2.Cp week _2.
Cp week _2.
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
 
Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
 

Destacado (6)

Ch 2
Ch 2Ch 2
Ch 2
 
Ayes Report: Kotler-Chapter 3
Ayes Report: Kotler-Chapter 3Ayes Report: Kotler-Chapter 3
Ayes Report: Kotler-Chapter 3
 
Cd6813 business mkt
Cd6813 business mktCd6813 business mkt
Cd6813 business mkt
 
Lec3
Lec3Lec3
Lec3
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Chapter 2 mktg
Chapter 2 mktgChapter 2 mktg
Chapter 2 mktg
 

Similar a Lecture 1

Chapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this pptChapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this pptANISHYAPIT
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.pptManiMala75
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.pptManiMala75
 
C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptxMugilvannan11
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAAiman Hud
 
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
 
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).pptxrajkumar490591
 
Whole c++ lectures ITM1 Th
Whole c++ lectures ITM1 ThWhole c++ lectures ITM1 Th
Whole c++ lectures ITM1 ThAram Mohammed
 
Programming Fundamentals and basic knowledge
Programming Fundamentals and basic knowledge Programming Fundamentals and basic knowledge
Programming Fundamentals and basic knowledge imtiazalijoono
 
Lecture 1.pptx
Lecture 1.pptxLecture 1.pptx
Lecture 1.pptxMark82418
 
Introduction to C Unit 1
Introduction to C Unit 1Introduction to C Unit 1
Introduction to C Unit 1SURBHI SAROHA
 
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
 
Introduction to the c programming language (amazing and easy book for beginners)
Introduction to the c programming language (amazing and easy book for beginners)Introduction to the c programming language (amazing and easy book for beginners)
Introduction to the c programming language (amazing and easy book for beginners)mujeeb memon
 

Similar a Lecture 1 (20)

Chapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this pptChapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this ppt
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
 
Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
 
C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptx
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
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
 
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
 
Whole c++ lectures ITM1 Th
Whole c++ lectures ITM1 ThWhole c++ lectures ITM1 Th
Whole c++ lectures ITM1 Th
 
C language unit-1
C language unit-1C language unit-1
C language unit-1
 
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDYC LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
 
Chap 2 c++
Chap 2 c++Chap 2 c++
Chap 2 c++
 
Programming Fundamentals and basic knowledge
Programming Fundamentals and basic knowledge Programming Fundamentals and basic knowledge
Programming Fundamentals and basic knowledge
 
The smartpath information systems c pro
The smartpath information systems c proThe smartpath information systems c pro
The smartpath information systems c pro
 
Prog1-L1.pdf
Prog1-L1.pdfProg1-L1.pdf
Prog1-L1.pdf
 
Lecture 1.pptx
Lecture 1.pptxLecture 1.pptx
Lecture 1.pptx
 
Introduction to C Unit 1
Introduction to C Unit 1Introduction to C Unit 1
Introduction to C Unit 1
 
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
 
Rr
RrRr
Rr
 
Introduction to the c programming language (amazing and easy book for beginners)
Introduction to the c programming language (amazing and easy book for beginners)Introduction to the c programming language (amazing and easy book for beginners)
Introduction to the c programming language (amazing and easy book for beginners)
 

Último

KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoordharasingh5698
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptMsecMca
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projectssmsksolar
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 

Último (20)

KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 

Lecture 1

  • 1. Modelling 2A C Lecture 1 Chapter 3 Philip Robinson 2015
  • 2. Compiling a program • The typical process for creation of a program is – Editing the source code using a text editor – Compilation of source code resulting in object code – Linking of any required external libraries or code which results in an executable file. – This file can be executed by the OS 2 source file linkercompiler source file object file executable file Included Libraries
  • 3. The Command Line • A command-line interface (CLI) is a mechanism for interacting with a computer operating system or software by typing text commands to perform specific tasks. • The commands that are executed are themselves small programs that together make up the operating system. – Eg. Copy, Del, Move • The command prompt represents a position in the file system of the computer • Some useful command for navigating the file system: – cd is change directory (cd .. goes down one directory) – dir gives you a list of all the folders and files in the current folder • If you type the name of an executable file that is in the same path as the command prompt the OS will run that program 3
  • 4. Compiling a program • Originally programs were edited using a text editing program and then compiled using the command line interface to run the Compiler and provide it with the source code file that needs to be compiled – Eg. C:>gcc simple.c –o output.exe • The most popular way to create programs is to use an Integrated Development Environment (IDE) – Single program that provides the functions of a text editor, compiler and debugger. – For C/C++ development Dev-C++ and Code::Blocks are popular free IDE’s 4
  • 5. Four steps to writing a C program 1. Typing in the code in a text window and saving the resulting text as a separate file (source file). The text of a C program is stored in a file with the extension .c for C programming language 2. Compiling the code produces an intermediate object file - with the extension .obj or .o. The source file must be translated into binary numbers understandable to the computer's Central Processing Unit This process 3. Linking the code to include library routines (routines written by the manufacturer of the compiler to perform a variety of tasks, from input/output to complicated mathematical functions). In the case of C the standard input and output functions are contained in a library (stdio.h) so even the most basic program will require a library function. After linking the file extension is .exe which are executable files 4. Executing (running) the code. Run .exe files as you can other applications, simply by typing their names at the DOS prompt 5
  • 6. Pass 1: Quick Synopsis • The first line tells the computer to include information found in the file stdio.h, which file is part of the C compiler package: • #include <stdio.h> <= Include another file • C programs consist of one or more functions, which are the basic modules of a C program. • This program consists of one function called main. • The parentheses identify main() as a function name: • main() <= Function name • You can use the symbols /* and */ to enclose Comments, which are remarks to help clarify a program. They are intended only for the reader and are ignored by the computer: • /* a simple program */ <= Comment • // comment <= Single line comment 6
  • 7. Pass 1: Quick Synopsis • The opening brace { marks the start of the statements that make up the function. • The function definition is ended with a closing brace } • { <.=Beginning of the body of the function • The declaration statement announces that we will use a variable called num and that num is an integer: • int num; <= Declaration statement • The assignment statement assigns the value 1 to num: • num = 1; <= Assignment statement • C statements all use the semi-colon ; to terminate! 7
  • 8. Pass 1: Quick Synopsis • The following line prints the phrase within the quotation marks (I am a simple). • printf(”I am a simple “);<= Print statement • The following line prints the word computer to the end of the last phrase printed. The n tells the computer to start a new line: • printf (“computer .n”); <= Another print statement • The following line prints the value of num (which is 1) embedded in the phrase quotation marks. The %d instructs the computer where and in what form to print n value: • printf(”My favourite number is %d because It is first.n”, num); • As noted earlier, the program ends with a closing brace: • } <= Program end 8
  • 9. Pass 2: Details • #include Directives and Header Files – The stdio.h file is supplied as part of a C compiler package, and it contains information about input and output functions (such as printf (for the compiler to use: • #include <stdio.h> – The name stands for standard input/output header. – C users refer to a collection of information that goes at the top of a file as the header, and C implementations typically come with several header files. • The effect of #include <stdio.h> is the same as if we were to copy the entire contents of the stdio.h file into our file at the position the line appears. • Such #include files provide a convenient way to handle information that is required by many programs. • Note the use of the angle brackets (< and >) around the header's name. These indicate that the header file is to be looked for on the system disk which stores the rest of the C program application9
  • 10. Pass 2: Details • The main( ) Function • All C programs will consist of at least one function, but it is usual to write a C program that comprises several functions. • The only function that has to be present is the function called main. • For more advanced programs the main function will act as a controlling function calling other functions in their turn to do the dirty work • The main function is the entry point into the program and is the first function that is called when your program executes. • The parentheses following a function name generally enclose information being passed along to the function. For our simple example, nothing is passed along with main( ), so the parenthesis remain empty. • The int indicates the return data type from the main function. 10
  • 11. Pass 2: Details • Comments • Using comments makes it easier for someone (including yourself) to understand your program by adding descriptions. • Everything between the opening /* and the closing */ is ignored by the compiler: – /* a simple program */ • // indicates a single line comment. Anything appearing in a line following // will be ignored by the compiler – int num; //this will be ignored. 11
  • 12. Pass 2: Details • Braces ({,}) mark the beginning as well as the end of the body of a function: • { • . • . • . • } • Braces also mark the beginning and end of blocks of statements within flow constructs such as if, for, while and switch constructs. 12
  • 13. Pass 2: Details • Declarations • The declaration statement is one of the most important features of C. – As noted earlier, our example declares two things: – int num; • First, somewhere in the function, we use a variable having the name num. – In C, all variables must be declared, which means you must list all the variables you use in a program, and you must show what “type” each variable is. – Second, int proclaims num as an integer, that is, a whole number without a decimal point. • The word int is a C keyword that identifies one of the basic C data types. • Keywords are specific words used to express a language; they may not be usurped for other purposes. 13
  • 14. Pass 2: Details • The compiler uses the information in the declaration statement to arrange for suitable storage space in memory for the num variable. • The semicolon at the end of the line identifies the line as a C statement or instruction. • Data Types • C deals with several kinds (or types) of data: integers, characters, and floating point numbers for example. • Declaring a variable to be an integer or a character type makes it possible for the computer to store, fetch, and interpret the data properly. • An integer and a single precision floating point variable are represented in memory using the same number of bits but the compiler knows how to interpret those bits to represent: – a integer ranging from -32768 to 32767 – or a float ranging from 3.4x10-38 to 3.4x10+38 14
  • 15. Pass 2: Details • Name Choice • Use meaningful names for variables. • The number of characters you can use varies among implementations. • To name variables you may use lowercase letters, uppercase letters, digits, and the underscore (_), which is counted as a letter. • The first character must be a letter. The following are some examples: 15 Valid Names Invalid names Squiggles &^#Z** cat1 1cat Human_names Human-names _iCounter Don’t
  • 16. Pass 2: Details • Assignments • The assignment statement is one of the most basic operations. – num = 1; • In our example, the assignment statement means “give the variable num the value of 1”. • Note that the assignment statement, like the declaration statement, is completed with a semicolon. 16
  • 17. Functions • A function contains a set of instructions that are executed whenever that function is called. • To call a function you need only to use its name followed by brackets – Eg printf(); • It is possible to send data to a function by making use of the parameters defined by the function. These parameters will be places between the brackets following the function name. – Eg. sum(2,5) • Defining parameters in a function are optional. • A function can also return resulting value but this is not required. 17
  • 18. Printf() • The function writes a sequence of data to the standard output. • The text sequence to be written is passed to the printf() function via its first parameter. • A string of text must be bounded by “ ” • There are special types of characters that affect how this string is printed to the screen • Escape sequence characters represent characters that are not possible to type on a keyboard but are understood by a computer such as tabs and newline characters. • These characters are preceded with a • Example – n represents a new line – t represents a tab 18
  • 19. Printf() • The sequence can be formatted using a set of specifiers – %d or %i Decimal Signed Integer – %f Decimal floating point number – …many more • These specifiers are placeholders that tell the printf() function where to print the value of variables specified by the parameters that follow the first control string parameter. • Printf(“This is an integer %d, this is a double %f.”,12, 12.55); – This is an integer 12, this is a double 12.55. • Can specify formatting of numbers – Printf(“This is an integer %3d, this is a double %4.3f.”,12, 12.55); – This is an integer 012, this is a double 0012.550. • http://www.cplusplus.com/reference/clibrary/cstdio/printf/ 19
  • 20. Libraries • For the purpose of modularity it is possible to create a source code file that contains a collection of functions that are used often. • So that it is not necessary to include the source of these common functions in every source code file you write it is possible to just link a library that contains the functions to your program. • This is done using the #include directive – E.g. #include <math.h> • This directive essentially copies the contents of the library into that position in your program source code and after this directive one can access the functions in the library as if they were declared. 20