The document contains a C++ program that calculates the circumference of a circle. It defines constants for pi and the radius, declares a variable to store the circumference result, calculates the circumference using the formula 2*pi*r, and prints the result. The program includes the necessary headers, declares main() and returns 0 at the end. It provides a simple example of defining constants, declaring variables, performing calculations, and outputting results in C++.
The document discusses intermediate code generation in compilers. It describes how compilers generate an intermediate representation from the abstract syntax tree that is machine independent and allows for optimizations. One popular intermediate representation is three-address code, where each statement contains at most three operands. This code is then represented using structures like quadruples and triples to store the operator and operands for code generation and rearranging during optimizations. Static single assignment form is also covered, which assigns unique names to variables to facilitate optimizations.
The document discusses code generation which is the final phase of a compiler that generates target code such as assembly code by selecting memory locations for variables, translating instructions into assembly instructions, and assigning variables and results to registers, and it outlines some of the key issues in code generation such as handling the input representation, the target language, instruction selection, register allocation, and evaluation order.
The document discusses various topics related to compiler design including ambiguous grammar, leftmost and rightmost derivations, infix and postfix notation, and implementations of three-address code. It provides examples of ambiguous grammar in C and describes leftmost and rightmost derivations in parsing. It also compares infix, postfix and prefix notation for mathematical expressions and describes converting between the notations. Finally, it discusses different implementations of three-address code including using quadruples, triples and indirect triples.
The document provides an overview of the C programming language. It discusses the history and creation of C, key features of C like portability and efficiency, C program structure, data types in C including integer, floating point, and character types, and variable naming conventions. It also covers basic C programs and examples to illustrate the use of data types, operators, and input/output functions in C.
This document discusses code generation in compilers. It covers:
- The code generator takes an intermediate representation and produces target code that is correct and efficient for the target machine.
- Symbol tables are used to track variable semantics, data types, scopes, and storage addresses. Common implementations are unordered lists and ordered linear lists.
- The target machine format can be absolute machine language, relocatable machine language, or assembly language. Memory management involves mapping names to runtime memory addresses.
- Basic blocks, control flow graphs, and structure-preserving transformations like common subexpression elimination are discussed for code optimization.
This document discusses compiler architecture and intermediate code generation. It begins by describing the typical phases of a compiler: parsing, static checking, and code generation. It then discusses intermediate code, which ties the front end and back end phases together and is language and machine independent. Various forms of intermediate code are described, including trees, postfix notation, and triple/quadruple intermediate code. The rest of the document focuses on triple/quadruple code, including how it represents expressions, statements, addressing of arrays, and the translation process from source code to triple/quadruple intermediate code.
The document summarizes issues in the design of a code generator, which is the final phase of the compiler. It discusses the input to the code generator, which is an intermediate representation from the front end. It also discusses the target program output formats like absolute machine language, relocatable machine language, and assembly language. Additional topics covered include memory management mapping names to runtime addresses, instruction selection based on the target machine's instruction set, register allocation, choices of evaluation order, and approaches to code generation focusing on producing correct code.
The document discusses intermediate code generation in compilers. It describes how compilers generate an intermediate representation from the abstract syntax tree that is machine independent and allows for optimizations. One popular intermediate representation is three-address code, where each statement contains at most three operands. This code is then represented using structures like quadruples and triples to store the operator and operands for code generation and rearranging during optimizations. Static single assignment form is also covered, which assigns unique names to variables to facilitate optimizations.
The document discusses code generation which is the final phase of a compiler that generates target code such as assembly code by selecting memory locations for variables, translating instructions into assembly instructions, and assigning variables and results to registers, and it outlines some of the key issues in code generation such as handling the input representation, the target language, instruction selection, register allocation, and evaluation order.
The document discusses various topics related to compiler design including ambiguous grammar, leftmost and rightmost derivations, infix and postfix notation, and implementations of three-address code. It provides examples of ambiguous grammar in C and describes leftmost and rightmost derivations in parsing. It also compares infix, postfix and prefix notation for mathematical expressions and describes converting between the notations. Finally, it discusses different implementations of three-address code including using quadruples, triples and indirect triples.
The document provides an overview of the C programming language. It discusses the history and creation of C, key features of C like portability and efficiency, C program structure, data types in C including integer, floating point, and character types, and variable naming conventions. It also covers basic C programs and examples to illustrate the use of data types, operators, and input/output functions in C.
This document discusses code generation in compilers. It covers:
- The code generator takes an intermediate representation and produces target code that is correct and efficient for the target machine.
- Symbol tables are used to track variable semantics, data types, scopes, and storage addresses. Common implementations are unordered lists and ordered linear lists.
- The target machine format can be absolute machine language, relocatable machine language, or assembly language. Memory management involves mapping names to runtime memory addresses.
- Basic blocks, control flow graphs, and structure-preserving transformations like common subexpression elimination are discussed for code optimization.
This document discusses compiler architecture and intermediate code generation. It begins by describing the typical phases of a compiler: parsing, static checking, and code generation. It then discusses intermediate code, which ties the front end and back end phases together and is language and machine independent. Various forms of intermediate code are described, including trees, postfix notation, and triple/quadruple intermediate code. The rest of the document focuses on triple/quadruple code, including how it represents expressions, statements, addressing of arrays, and the translation process from source code to triple/quadruple intermediate code.
The document summarizes issues in the design of a code generator, which is the final phase of the compiler. It discusses the input to the code generator, which is an intermediate representation from the front end. It also discusses the target program output formats like absolute machine language, relocatable machine language, and assembly language. Additional topics covered include memory management mapping names to runtime addresses, instruction selection based on the target machine's instruction set, register allocation, choices of evaluation order, and approaches to code generation focusing on producing correct code.
This chapter discusses fundamental concepts of C programming language and basic input/output functions. It covers C development environment, C program structure including main functions and statements, basic data types, input/output functions like printf and scanf, and common programming errors.
A parser is a program component that breaks input data into smaller elements according to the rules of a formal grammar. It builds a parse tree representing the syntactic structure of the input based on these grammar rules. There are two main types of parsers: top-down parsers start at the root of the parse tree and work downward, while bottom-up parsers start at the leaves and work upward. Parser generators use attributes like First and Follow to build parsing tables for predictive parsers like LL(1) parsers, which parse input from left to right based on a single lookahead token.
The document discusses intermediate code generation in compilers. It describes how compilers generate intermediate code representations after parsing source code. Intermediate representations allow separating the front-end and back-end of compilers, facilitating code optimization and retargeting compilers to different architectures. Common intermediate representations discussed include abstract syntax trees, postfix notation, static single assignment form, and three-address instructions. The document also provides examples of generating three-address code using syntax-directed translation.
The document discusses intermediate code in compilers. It defines intermediate code as the interface between a compiler's front end and back end. Using an intermediate representation facilitates retargeting a compiler to different machines and applying machine-independent optimizations. The document then describes different types of intermediate code like triples, quadruples and SSA form. It provides details on three-address code including quadruples, triples and indirect triples. It also discusses addressing of array elements and provides an example of translating a C program to intermediate code.
The document discusses intermediate code generation in compiler design. It introduces intermediate code, features like retargeting and optimization. It describes three address code statements like a = b op c and quadruples which consist of four fields - op, arg1, arg2, and result to represent instructions. The conclusion states that intermediate code acts as an interface between the front-end and back-end of a compiler.
The document describes code generation for two commercial compilers:
1) The Borland C 3.0 compiler for the 80X86 generates assembly code using static simulation and frame pointers for function calls and local variable access.
2) The Sun 2.0 compiler for SPARCstations uses register-based calling conventions and generates efficient SPARC assembly code.
Both compilers handle code generation for arithmetic expressions, arrays, structures, pointers, control flow, and function calls.
The document discusses code generation in compilers. It covers:
- The main tasks of a code generator are instruction selection, register allocation and assignment, and instruction ordering.
- Code generators map an intermediate representation to target machine code for a specific architecture. This mapping can vary in complexity depending on the level of the intermediate representation and the target architecture.
- Key issues in code generator design include addressing in the target code, representing the program as basic blocks and flow graphs, register allocation, and selecting machine instructions to represent operations.
This document summarizes key topics in intermediate code generation discussed in Chapter 6, including:
1) Variants of syntax trees like DAGs are introduced to share common subexpressions. Three-address code is also discussed where each instruction has at most three operands.
2) Type checking and type expressions are covered, along with translating expressions and statements to three-address code. Control flow statements like if/else are also translated using techniques like backpatching.
3) Backpatching allows symbolic labels in conditional jumps to be resolved by a later pass that inserts actual addresses, avoiding an extra pass. This and other control flow translation topics are covered.
This document provides an overview of C++ programming fundamentals. It discusses two main categories of software: system software and application software. It then introduces the C language, covering its history, evolution, and justification. The document also examines the development environment for C, including tools like editors, compilers, debuggers, and integrated development environments. It provides examples of basic C++ programs and explains the parts and structure of a C++ program.
The document discusses intermediate code generation in compilers. It describes how compilers take source code and convert it to an intermediate representation that is then converted to machine code. The intermediate code is machine independent, allowing portability. It can be optimized before generating target code. Common intermediate representations discussed include postfix notation, three-address code using quadruples or triples, and syntax trees.
Here is a C program to produce a spiral array as described in the task:
#include <stdio.h>
int main() {
int n = 5;
int arr[n][n];
int num = 1;
int rowBegin = 0;
int rowEnd = n-1;
int colBegin = 0;
int colEnd = n-1;
while(rowBegin <= rowEnd && colBegin <= colEnd) {
// Top row
for(int i=colBegin; i<=colEnd; i++) {
arr[rowBegin][i] = num++;
}
rowBegin++;
// Right column
for(int i=rowBegin;
The document describes intermediate code generation during compilation.
1) An intermediate language is used to translate source programs into a form that is CPU independent yet close to machine language. This facilitates code optimization and retargeting of compilers.
2) Common intermediate languages include syntax trees, postfix notation, and three-address code using quadruples. Three-address code breaks down expressions into single assignment statements to simplify optimization.
3) Semantic rules for syntax-directed translation are described to generate three-address code for expressions, assignments, procedures, and other language constructs. Attributes track temporary variables and generated code.
The document discusses the problem solving process in programming. It is divided into several steps:
1. Identifying the problem and developing a hierarchy chart to break it down into sub-problems.
2. Developing an algorithm by writing step-by-step instructions and identifying variables.
3. Creating a flowchart to visually represent the logic and flow of the algorithm.
4. Writing pseudocode to describe the steps using a generic syntax along with English phrases.
5. Developing the actual program code in a language like C by implementing the algorithm using appropriate syntax and commands.
The document then provides examples at each step and discusses key concepts in C programming like variables, data types,
The document discusses functions in C programming. It defines a function as a block of code that performs a task. Functions make code more modular and reusable. There are two types of functions: predefined/library functions and user-defined functions. User-defined functions allow programmers to create their own functions. Functions help reduce code length and make programs easier to design, understand and debug. Parameters and return values allow functions to accept input and return output. Pointers and recursion are also discussed.
The document provides information on the C programming language. It discusses that C was developed by Dennis Ritchie at Bell Labs in 1972 and is a general purpose programming language well suited for business and scientific applications. It describes the basic structure of a C program including sections for links, definitions, variables, functions, and input/output statements. It also covers various C language concepts like data types, operators, decision making statements, looping statements, functions, and more.
This document discusses backpatching and syntax-directed translation for boolean expressions and flow-of-control statements. It describes using three functions - Makelist, Marklist, and Backpatch - to generate code with backpatching during a single pass. Boolean expressions are translated by constructing syntax trees and associating semantic actions to record quadruple indices for later backpatching. Flow-of-control statements like IF and WHILE are handled similarly, using marker nonterminals to record quadruple numbers for backpatching statement lists.
This document provides an overview of C programming basics including character sets, tokens, keywords, variables, data types, and control statements in C language. Some key points include:
- The C character set includes lowercase/uppercase letters, digits, special characters, whitespace, and escape sequences.
- Tokens in C include operators, special symbols, string constants, identifiers, and keywords. There are 32 reserved keywords that should be in lowercase.
- Variables are named locations in memory that hold values. They are declared with a data type and initialized by assigning a value.
- C has primary data types like int, float, char, and double. Derived types include arrays, pointers, unions, structures,
Intermediate code generation in Compiler DesignKuppusamy P
The document discusses intermediate code generation in compilers. It begins by explaining that intermediate code generation is the final phase of the compiler front-end and its goal is to translate the program into a format expected by the back-end. Common intermediate representations include three address code and static single assignment form. The document then discusses why intermediate representations are used, how to choose an appropriate representation, and common types of representations like graphical IRs and linear IRs.
Pastor Elio Marrocco's "Secrets of the Believer's Victory" sermon at New Life Christian Church on September 2012. You can learn more about New Life Christian Church here: http://www.newlifecc.ca
Andrew wallis china experience presentationApril Pei
Andrew Wallis taught English and traveled around China in 2006, documenting his experiences in photos and captions. Some highlights included teaching rowdy students, taking a cruise down the Yangtze River with other teachers, seeing the Leshan Giant Buddha statues and Terracotta Warriors in Xian, and climbing the Great Wall. Throughout his travels, Wallis maintained his witty sense of humor, poking fun at cultural differences and his own experiences in China.
This chapter discusses fundamental concepts of C programming language and basic input/output functions. It covers C development environment, C program structure including main functions and statements, basic data types, input/output functions like printf and scanf, and common programming errors.
A parser is a program component that breaks input data into smaller elements according to the rules of a formal grammar. It builds a parse tree representing the syntactic structure of the input based on these grammar rules. There are two main types of parsers: top-down parsers start at the root of the parse tree and work downward, while bottom-up parsers start at the leaves and work upward. Parser generators use attributes like First and Follow to build parsing tables for predictive parsers like LL(1) parsers, which parse input from left to right based on a single lookahead token.
The document discusses intermediate code generation in compilers. It describes how compilers generate intermediate code representations after parsing source code. Intermediate representations allow separating the front-end and back-end of compilers, facilitating code optimization and retargeting compilers to different architectures. Common intermediate representations discussed include abstract syntax trees, postfix notation, static single assignment form, and three-address instructions. The document also provides examples of generating three-address code using syntax-directed translation.
The document discusses intermediate code in compilers. It defines intermediate code as the interface between a compiler's front end and back end. Using an intermediate representation facilitates retargeting a compiler to different machines and applying machine-independent optimizations. The document then describes different types of intermediate code like triples, quadruples and SSA form. It provides details on three-address code including quadruples, triples and indirect triples. It also discusses addressing of array elements and provides an example of translating a C program to intermediate code.
The document discusses intermediate code generation in compiler design. It introduces intermediate code, features like retargeting and optimization. It describes three address code statements like a = b op c and quadruples which consist of four fields - op, arg1, arg2, and result to represent instructions. The conclusion states that intermediate code acts as an interface between the front-end and back-end of a compiler.
The document describes code generation for two commercial compilers:
1) The Borland C 3.0 compiler for the 80X86 generates assembly code using static simulation and frame pointers for function calls and local variable access.
2) The Sun 2.0 compiler for SPARCstations uses register-based calling conventions and generates efficient SPARC assembly code.
Both compilers handle code generation for arithmetic expressions, arrays, structures, pointers, control flow, and function calls.
The document discusses code generation in compilers. It covers:
- The main tasks of a code generator are instruction selection, register allocation and assignment, and instruction ordering.
- Code generators map an intermediate representation to target machine code for a specific architecture. This mapping can vary in complexity depending on the level of the intermediate representation and the target architecture.
- Key issues in code generator design include addressing in the target code, representing the program as basic blocks and flow graphs, register allocation, and selecting machine instructions to represent operations.
This document summarizes key topics in intermediate code generation discussed in Chapter 6, including:
1) Variants of syntax trees like DAGs are introduced to share common subexpressions. Three-address code is also discussed where each instruction has at most three operands.
2) Type checking and type expressions are covered, along with translating expressions and statements to three-address code. Control flow statements like if/else are also translated using techniques like backpatching.
3) Backpatching allows symbolic labels in conditional jumps to be resolved by a later pass that inserts actual addresses, avoiding an extra pass. This and other control flow translation topics are covered.
This document provides an overview of C++ programming fundamentals. It discusses two main categories of software: system software and application software. It then introduces the C language, covering its history, evolution, and justification. The document also examines the development environment for C, including tools like editors, compilers, debuggers, and integrated development environments. It provides examples of basic C++ programs and explains the parts and structure of a C++ program.
The document discusses intermediate code generation in compilers. It describes how compilers take source code and convert it to an intermediate representation that is then converted to machine code. The intermediate code is machine independent, allowing portability. It can be optimized before generating target code. Common intermediate representations discussed include postfix notation, three-address code using quadruples or triples, and syntax trees.
Here is a C program to produce a spiral array as described in the task:
#include <stdio.h>
int main() {
int n = 5;
int arr[n][n];
int num = 1;
int rowBegin = 0;
int rowEnd = n-1;
int colBegin = 0;
int colEnd = n-1;
while(rowBegin <= rowEnd && colBegin <= colEnd) {
// Top row
for(int i=colBegin; i<=colEnd; i++) {
arr[rowBegin][i] = num++;
}
rowBegin++;
// Right column
for(int i=rowBegin;
The document describes intermediate code generation during compilation.
1) An intermediate language is used to translate source programs into a form that is CPU independent yet close to machine language. This facilitates code optimization and retargeting of compilers.
2) Common intermediate languages include syntax trees, postfix notation, and three-address code using quadruples. Three-address code breaks down expressions into single assignment statements to simplify optimization.
3) Semantic rules for syntax-directed translation are described to generate three-address code for expressions, assignments, procedures, and other language constructs. Attributes track temporary variables and generated code.
The document discusses the problem solving process in programming. It is divided into several steps:
1. Identifying the problem and developing a hierarchy chart to break it down into sub-problems.
2. Developing an algorithm by writing step-by-step instructions and identifying variables.
3. Creating a flowchart to visually represent the logic and flow of the algorithm.
4. Writing pseudocode to describe the steps using a generic syntax along with English phrases.
5. Developing the actual program code in a language like C by implementing the algorithm using appropriate syntax and commands.
The document then provides examples at each step and discusses key concepts in C programming like variables, data types,
The document discusses functions in C programming. It defines a function as a block of code that performs a task. Functions make code more modular and reusable. There are two types of functions: predefined/library functions and user-defined functions. User-defined functions allow programmers to create their own functions. Functions help reduce code length and make programs easier to design, understand and debug. Parameters and return values allow functions to accept input and return output. Pointers and recursion are also discussed.
The document provides information on the C programming language. It discusses that C was developed by Dennis Ritchie at Bell Labs in 1972 and is a general purpose programming language well suited for business and scientific applications. It describes the basic structure of a C program including sections for links, definitions, variables, functions, and input/output statements. It also covers various C language concepts like data types, operators, decision making statements, looping statements, functions, and more.
This document discusses backpatching and syntax-directed translation for boolean expressions and flow-of-control statements. It describes using three functions - Makelist, Marklist, and Backpatch - to generate code with backpatching during a single pass. Boolean expressions are translated by constructing syntax trees and associating semantic actions to record quadruple indices for later backpatching. Flow-of-control statements like IF and WHILE are handled similarly, using marker nonterminals to record quadruple numbers for backpatching statement lists.
This document provides an overview of C programming basics including character sets, tokens, keywords, variables, data types, and control statements in C language. Some key points include:
- The C character set includes lowercase/uppercase letters, digits, special characters, whitespace, and escape sequences.
- Tokens in C include operators, special symbols, string constants, identifiers, and keywords. There are 32 reserved keywords that should be in lowercase.
- Variables are named locations in memory that hold values. They are declared with a data type and initialized by assigning a value.
- C has primary data types like int, float, char, and double. Derived types include arrays, pointers, unions, structures,
Intermediate code generation in Compiler DesignKuppusamy P
The document discusses intermediate code generation in compilers. It begins by explaining that intermediate code generation is the final phase of the compiler front-end and its goal is to translate the program into a format expected by the back-end. Common intermediate representations include three address code and static single assignment form. The document then discusses why intermediate representations are used, how to choose an appropriate representation, and common types of representations like graphical IRs and linear IRs.
Pastor Elio Marrocco's "Secrets of the Believer's Victory" sermon at New Life Christian Church on September 2012. You can learn more about New Life Christian Church here: http://www.newlifecc.ca
Andrew wallis china experience presentationApril Pei
Andrew Wallis taught English and traveled around China in 2006, documenting his experiences in photos and captions. Some highlights included teaching rowdy students, taking a cruise down the Yangtze River with other teachers, seeing the Leshan Giant Buddha statues and Terracotta Warriors in Xian, and climbing the Great Wall. Throughout his travels, Wallis maintained his witty sense of humor, poking fun at cultural differences and his own experiences in China.
- Christians have authority over demons and sickness through the name and power of Jesus.
- Believers can exercise this authority through praying in faith using God's word as a weapon against the enemy.
- The document discusses discovering and exercising believers' authority, the armor of God, and responsibilities as Christians to use authority with humility, love, and for the benefit of others.
An outline of some of Christ's characteristics to be used in tandem with a talk about service. The main text of focus is Luke 19:14-28 - The parable of the nobleman and his ten servants.
1) God gave humanity authority over the earth according to scripture, and Jesus gave believers the authority to complete his work through his name.
2) The pastor encourages believers to truly listen to what God says and walk in his authority, not be caught up in religion or darkness.
3) To walk in authority, believers must follow God's strategy of submission, accountability, and commitment (SAC) to his word and each other, not the enemy's strategy of pride, apathy, and confidence in the world.
This document summarizes Dean Shareski's presentation at the Bucks Lehigh EduSummit on August 12, 2014 about the classroom of the future. The presentation discusses how learning has changed with increased access to information online and the need to rethink traditional classroom structures and assessments. It also emphasizes fostering student joy, engagement, and creativity through personalized learning experiences.
Introduction to Programming for students who have very basic knowledge of coding and either want to learn basics of coding or are taking a course in their Bachelors. I have made this presentation to teach Industrial Engineering students in Pakistan. Other students can also take it up for a light reference. You can consult with me about the content through PIM or comments
The document discusses various C++ programming concepts including variables, data types, input/output streams, and expressions. It defines variables as memory locations that can store values, and describes different data types like int, double, char. It also covers input with cin, output with cout, and formatting output values.
This document provides an overview of an intermediate computer programming course at the University of Gondar in Ethiopia. The course code is CoEng2111 and it is taught by instructor Wondimu B. Topics that will be covered in the course include C++ basics, arrays, strings, functions, and recursion. The course materials are presented over several pages that define concepts, provide code examples, and explain key ideas like variables, data types, operators, and array implementation in C++.
This document discusses program structure, data types, variables, operators, input/output functions, and debugging in C programming. It provides sample code for a program that calculates the sum of two integers entered by the user. The key steps are: 1) declaring integer variables for the two numbers and their sum, 2) using printf and scanf functions to input the numbers and output the result, and 3) returning 0 at the end of the main function. The document also covers preprocessor directives, data types, naming conventions, arithmetic and logical operators, and debugging techniques.
02a fundamental c++ types, arithmetic Manzoor ALam
The document discusses fundamental C++ types including integers, characters, and floating-point numbers. It describes integer types like int, short, and long and their typical sizes. Character types represent single characters with examples of escape codes. Floating-point types can represent real numbers in formats like float and double. The document also covers C++ concepts such as variable definitions and declarations, arithmetic operators, assignment, and increment/decrement operators.
This document provides an overview of the C++ programming language. It discusses key C++ concepts like classes, objects, functions, and data types. Some key points:
- C++ is an object-oriented language that is an extension of C with additional features like classes and inheritance.
- Classes allow programmers to combine data and functions to model real-world entities. Objects are instances of classes.
- The document defines common C++ terms like keywords, identifiers, constants, and operators. It also provides examples of basic programs.
- Functions are described as modular and reusable blocks of code. Parameter passing techniques like pass-by-value and pass-by-reference are covered.
- Other concepts covered include
This document provides an introduction to C++ programming, covering key concepts like characters, tokens, keywords, identifiers, literals, operators, input/output, variables, comments, and common errors. It explains that C++ was created by Bjarne Stroustrup in the 1980s as an extension of C with object-oriented features from Simula 67.
This document provides an introduction to C++ programming, covering key concepts like characters, tokens, keywords, identifiers, literals, operators, I/O streams, variables, comments, and common errors. It explains that Bjarne Stroustrup extended C to create C++, adding object-oriented features from Simula. The main components discussed are the building blocks of any C++ program - characters, tokens, data types, and basic input/output operations.
C is a structured programming language that supports modularity through functions. It uses header files for precompiled code and functions. The main function acts as the program entry point. Comments improve readability. C supports primitive data types, user-defined types like structures, and arrays as aggregate data types. Control flow is managed through selection statements like if-else and repetition statements like for, while, and do-while loops. Pointers store addresses of variables and are used for call by reference.
This document provides an introduction to the C programming language. It discusses fundamental C elements like data types, variables, constants, operators, and input/output functions. It explains how a basic C program is structured and compiled. Examples are provided to demonstrate simple C statements, arithmetic expressions, and how to write and run a first program that prints text. The key topics covered include basic syntax, program structure, data types, identifiers, operators, and input/output functions like printf() and scanf().
This document provides an overview of basic C++ programming concepts including:
1) The main parts of a C++ program including comments, preprocessor directives, namespaces, and the main function.
2) Different data types in C++ like integers, characters, floating-point numbers, and Booleans.
3) Keywords, variables, literals, and operators used in C++.
4) Input and output streams like cout and cin for displaying and getting user input.
3) Concepts like expressions, order of operations, comments, and programming style.
This document provides an overview of key concepts in C++ programming including program structure, variables, data types, operators, input/output, control structures, and functions. It discusses the basic building blocks of a C++ program including comments, header files, declaring variables, reading/writing data, and program flow. Control structures like if/else, switch, while, for, break and continue are explained. The document also covers fundamental C++ concepts such as variables, data types, operators, and basic input/output.
Embedded C is a subset of the C programming language used for embedded systems that excludes large features and focuses on efficiency; it uses preprocessor directives, handles variables in local and global scopes, and can pass parameters by value or reference. Embedded C++ further restricts C++ for embedded use by removing features like multiple inheritance and runtime type identification. The document discusses optimizing embedded C and C++ code, common patterns like super loop architectures, and guidelines for writing embedded C code.
This document provides an overview of the C programming language. It discusses that C was developed in 1972 at Bell Labs and is a popular systems and applications programming language. The document then covers various C language concepts like data types, variables, operators, input/output functions, and provides examples of basic C programs and code snippets.
The document provides an overview of key concepts for getting started with C programming, including data types, variables, functions, operators, and common errors. It explains concepts like data type declaration, arithmetic expressions, the main() function, and input/output functions like printf(). Examples are provided to demonstrate proper syntax and usage of these basic C programming elements.
C++ was created in the 1980s by Bjarne Stroustrup as an extension of the C language with object-oriented features. It combined features from C and Simula 67. The document provides an overview of the basic building blocks of C++ programs including characters, tokens, keywords, identifiers, literals, punctuators, operators, comments, streams, variables, and common errors. It describes the different data types and rules for writing identifiers, literals, and comments. It also explains common tokens like keywords, operators, and punctuators and how they are used in C++.
The document discusses C++ basics including variables, data types, input/output, and expressions. It covers declaring and initializing variables, assigning values, and built-in data types like int, double, char. It also covers input using cin and output using cout, including formatting real numbers.
The document provides an introduction to algorithms and key concepts related to algorithms such as definition, features, examples, flowcharts, pseudocode. It also discusses different types of programming languages from first to fifth generation. Key points of structured programming approach and introduction to C programming language are explained including data types, variables, constants, input/output functions, operators, type conversion etc.
The document provides an introduction to the C programming language, including its history, features, character sets, tokens, data types, operators, and the basic structure of a C program. It discusses key concepts such as variables, constants, comments, functions, input/output, and how to compile and execute a C program.
Using recycled concrete aggregates (RCA) for pavements is crucial to achieving sustainability. Implementing RCA for new pavement can minimize carbon footprint, conserve natural resources, reduce harmful emissions, and lower life cycle costs. Compared to natural aggregate (NA), RCA pavement has fewer comprehensive studies and sustainability assessments.
ACEP Magazine edition 4th launched on 05.06.2024Rahul
This document provides information about the third edition of the magazine "Sthapatya" published by the Association of Civil Engineers (Practicing) Aurangabad. It includes messages from current and past presidents of ACEP, memories and photos from past ACEP events, information on life time achievement awards given by ACEP, and a technical article on concrete maintenance, repairs and strengthening. The document highlights activities of ACEP and provides a technical educational article for members.
Literature Review Basics and Understanding Reference Management.pptxDr Ramhari Poudyal
Three-day training on academic research focuses on analytical tools at United Technical College, supported by the University Grant Commission, Nepal. 24-26 May 2024
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELgerogepatton
As digital technology becomes more deeply embedded in power systems, protecting the communication
networks of Smart Grids (SG) has emerged as a critical concern. Distributed Network Protocol 3 (DNP3)
represents a multi-tiered application layer protocol extensively utilized in Supervisory Control and Data
Acquisition (SCADA)-based smart grids to facilitate real-time data gathering and control functionalities.
Robust Intrusion Detection Systems (IDS) are necessary for early threat detection and mitigation because
of the interconnection of these networks, which makes them vulnerable to a variety of cyberattacks. To
solve this issue, this paper develops a hybrid Deep Learning (DL) model specifically designed for intrusion
detection in smart grids. The proposed approach is a combination of the Convolutional Neural Network
(CNN) and the Long-Short-Term Memory algorithms (LSTM). We employed a recent intrusion detection
dataset (DNP3), which focuses on unauthorized commands and Denial of Service (DoS) cyberattacks, to
train and test our model. The results of our experiments show that our CNN-LSTM method is much better
at finding smart grid intrusions than other deep learning algorithms used for classification. In addition,
our proposed approach improves accuracy, precision, recall, and F1 score, achieving a high detection
accuracy rate of 99.50%.
A review on techniques and modelling methodologies used for checking electrom...nooriasukmaningtyas
The proper function of the integrated circuit (IC) in an inhibiting electromagnetic environment has always been a serious concern throughout the decades of revolution in the world of electronics, from disjunct devices to today’s integrated circuit technology, where billions of transistors are combined on a single chip. The automotive industry and smart vehicles in particular, are confronting design issues such as being prone to electromagnetic interference (EMI). Electronic control devices calculate incorrect outputs because of EMI and sensors give misleading values which can prove fatal in case of automotives. In this paper, the authors have non exhaustively tried to review research work concerned with the investigation of EMI in ICs and prediction of this EMI using various modelling methodologies and measurement setups.
Advanced control scheme of doubly fed induction generator for wind turbine us...IJECEIAES
This paper describes a speed control device for generating electrical energy on an electricity network based on the doubly fed induction generator (DFIG) used for wind power conversion systems. At first, a double-fed induction generator model was constructed. A control law is formulated to govern the flow of energy between the stator of a DFIG and the energy network using three types of controllers: proportional integral (PI), sliding mode controller (SMC) and second order sliding mode controller (SOSMC). Their different results in terms of power reference tracking, reaction to unexpected speed fluctuations, sensitivity to perturbations, and resilience against machine parameter alterations are compared. MATLAB/Simulink was used to conduct the simulations for the preceding study. Multiple simulations have shown very satisfying results, and the investigations demonstrate the efficacy and power-enhancing capabilities of the suggested control system.
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...University of Maribor
Slides from talk presenting:
Aleš Zamuda: Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapter and Networking.
Presentation at IcETRAN 2024 session:
"Inter-Society Networking Panel GRSS/MTT-S/CIS
Panel Session: Promoting Connection and Cooperation"
IEEE Slovenia GRSS
IEEE Serbia and Montenegro MTT-S
IEEE Slovenia CIS
11TH INTERNATIONAL CONFERENCE ON ELECTRICAL, ELECTRONIC AND COMPUTING ENGINEERING
3-6 June 2024, Niš, Serbia
6. Pakistan Air force Schools
F.Sc. PAF Inter college Lahore
B.E. Mechanical Engineering (CEME NUST)
Pak Elektron Limtd. Lahore
Millat Tractors Sheikhupura Road
Descon Lahore
Olayan Descon Saudia
Descon Dubai
3/26/2015 6
7. M.Sc. Sustainable Technology, Sweden
Heritage-University of South Asia
3/26/2015 7
8. C++ (See plus pluss)
To follow syntax and rules of Turbo C++ and Borland
C+
Text editors e.g. WordPad and note pad
These are used to write the code
Compilers are used to run the code
Source code written and stored in first.cpp
Compiled code stored/saved as first.obj
Executed code stored as first.exe
3/26/2015 8
9. Contains following three parts
◦ Preprocessor directives
◦ The main( ) Function
◦ C++ statement
3/26/2015 9
10. Preprocessor Directives
Instructions given before beginning of actual program
Also called Compiler Directives
To define certain actions or special instructions (include
arithmetic equation)
Normally begin with number sign (#)
May include keywords like ―include‖ or ―define‖
3/26/2015 10
13. Preprocessor Directives
Header file
C++ source file
Contains definitions of function/objects
―include‖ is used to add ―iostream‖ into the program
Has Large number of header files in which library
functions are defined
3/26/2015 13
14. Example 1-01
#include <iostream>
using namespace std;
int main ( )
{
cout <<―this is my first program‖;
return 0;
}
3/26/2015 14
17. Header file
―iostream‖ is short of ―input output stream‖
Has definitions of several input and output objects or
functions
Which was it in the last example?
―cout‖ (see out)
Syntax
◦ #include <name of the header file>
3/26/2015 17
19. The main ( ) Function
Indicates the beginning of a program
After the preprocessor directives
Must be included in every program
Syntax
◦ main ( )
{
program statements…
}
3/26/2015 19
20. C++ Statements
Syntax
◦ main ( )
{
program statements…
}
The statements are written under main ( )
Between { }
Are the body of the program
Each statement ends with ‗;‘
3/26/2015 20
22. C++ Statements
Key words
Words used by languages for
Special purposes
Also called ‗reserved words‘
Cannot be used as variable names
3/26/2015 22
28. C++ Statements
Variables
Not a constant
Which may change during execution of a program
Represented by a symbol or a name
Nadeem, fox pro, x, y etc.
It represents a storage location on a computer
Data stored may change, the variable does not
Also known as a object
In C++ variable names consists of alphabets and digits
3/26/2015 28
29. C++ Statements
Rules for writing a variable name
First character must be alphabetic, exception ‗_‘
No blank spaces
Arithematic characters not allowed #, ^, etc
Reserved words are not allowed
Maximum length depends up on compiler
Must be declared
Again, case sensitive language
3/26/2015 29
30. Variables Valid/Invalid Remarks
Nadeem valid
perform valid
double invalid C++ reserved word
foxpro valid
switch invalid C++ reserved word
Marriam valid
int invalid C++ reserved word
3taq invalid Starts with numeral
unsigned invalid C++ reserved word
x-y invalid
Special character is not
allowed
Taq Ahd invalid Space is not allowed
3/26/2015 30
31. Each variable (we define) is specified by the data types of
the data stored in it
Each variable is Declared by its type
C++ has 5 basic data types
◦ int Integer 25, 100, 5000
◦ float Floating Point 3.4×105
◦ double double precision 3.4×105
◦ char characters almost all
◦ bool Boolean logic type variables
3/26/2015 31
32. The ‗int‘ Data Type
Represents the integer type data
Integer is a whole number!
i.e. without fraction or decimal
◦ 601, 250, -6, 501
The range depends the computer system being used
◦ In MS-DOS range is -32768 to 32767
Range can be changed by using following qualifiers
◦ short int
◦ long int
◦ unsigned int
3/26/2015 32
33. The ‗float‘ Data Type
Represents real or floating type data
Real, decimal or exponential notation
Float, signed or unsigned
3/26/2015 33
34. The ‗double‘ Data Type
Represents real or floating type data
Twice the storage capacity than ‗float data type‘
Long double Data type
3/26/2015 34
35. The ‗char‘ Data Type
char stands for character
Used to declare character type variables
Variables, alphabetic characters, numeric digits and
special characters can be stored
Twice the storage capacity than ‗float data type‘
Long double Data type
3/26/2015 35
36. Declaration of Variables
Assigning the name a variable can hold
◦ Zohaib, sum, addition, x, xyz etc
Assigning the data type a variable can hold
◦ int, float etc
Example
◦ int a;
◦ int abc, xyz, d, s;
Can be more than one variables but separated by a
comma (if of same data type)
3/26/2015 36
37. Declaration of Variables
If not, written in each individual line where each
statement is ended with a ‗;‘
Syntax
◦ type list of variables
Example
int a, xy;
Float b;
Char nm [15]
double sum;
3/26/2015 37
38. Initialization of Variables
Before we declared a variable
Declared variable gets a memory location assigned to it
that specifies it has a place in memory on the computer
Now a value to the variable must also be assigned or
defined
A known value is assigned to it
◦ int a = 110
The statement can be written as
◦ int a = 110, b = 60, c;
3/26/2015 38
39. Example 1-03
#include<iostream.h>
using namespace std;
int main ( )
{
int abc = 4, b = 1997;
float xy = 3.4;
char name[15] = ―Marriam Ahmed‖;
cout <<name<<endl;
cout<<abc<<endl;
cout<<b<<endl;
cout<<xy<<endl;
return 0;
}
3/26/2015 39
41. Constants
A value that cannot be changed during execution of a
program
◦ int a = 44
Four types of constants in C++
◦ Integer constants
◦ Floating point constants
◦ Character constants
◦ String constants
3/26/2015 41
42. Constants
Integer constants
Numerical value without a decimal part
+ can also be used with it
Integer constants are used in expressions for calculations
◦ int a = 44, b = 55;
sum = a+b;
cout<<sum<<endl;
3/26/2015 42
43. Constants
Floating-point contant
Numeric values having both integer and decimal part
Can also be written in exponential notation
In exponential notation, can be written as
◦ 123.5E2
◦ Where E represents the exponent
both the constant and the E notation can be +
3/26/2015 43
44. Example 1-04
#include<iostream>
int main ( )
{
int r;
const float p = 3.14;
float peri;
r = 2;
peri = 2*p*r;
cout<<―Result is = ―<<peri;
return 0;
}
3/26/2015 44
46. The ―define‖ Directive
It is a preprocessor directive, used at the beginning of
the program
Used to define a constant quantity
Syntax
◦ #define identifier constant
◦ #define p 3.14
Value defined is ‗p‘, where 3.14 is the constant assigned
to ‗p‘
3.14 remains same throughout the program
‗p‘ can not be used again in the program to define other
3/26/2015 46
47. The ―define‖ Directive
Identifier does not have any data type but any data type
can be assigned to it
3/26/2015 47
50. Arithmetic Operators
Symbols that represent arithmetic operations
Used in arithmetic expressions
Following are the arithmetic operators in C++
Operators Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
% For remainder
3/26/2015 50
51. Example 1-06
#include <iostream.h> redundant lines will be excluded
using namespace std;
int main ( )
{
int d, p, s, m, r;
p = 5+2;
s = 5-2;
m = 5*2;
d = 5/2;
r = 5%2;
cout<<―Addition of 5 & 2 is =―<<p<<endl;
cout<<―Subtraction of 5 & 2 is =―<<s<<endl;
cout<<―multiplication of 5 & 2 is =―<<m<<endl;
cout<<―division of 5&2 is =―<<d<endl;
cout<<―remainder of 5/2 is =―<<r<<endl; }
3/26/2015 51
53. Arithmetic Expression
It is a combination of variables, constants and arithmetic
operators
◦ p = m*x+100 where m=10 and x=5
Used to calculate value of an arithmetic formula
Returns a single value after evaluation
Here ‗=‗ is called the assignment operator
After evaluation the resultant variable is called the
―receiving variable‖
◦ res = m*x+100
3/26/2015 53
54. Order of Precedence of Operation
It is the order in which the expression is evaluated
C++ only performs one operation at a time
Following is the order of precedence
◦ All multiplications and divisions are performed first from left to
right
◦ All additions and subtractions are then performed left to right
◦ If parenthesis are used in an expression, the expressions within
parentheses are first computed from left to right
◦ When parentheses are used within parentheses, the expression
within innermost parentheses is evaluated first
3/26/2015 54
55. Order of Precedence of Operation
Example (4-(3*5))+2 is evaluated as follows
First?
Solution
◦ (3*5) is computed and returns value of 15.
◦ 4-15 is computed and returns value of -11
◦ -11+2 is computed and returns the value of -9
3/26/2015 55
56. Statements used to get some data and assign to variables
are input statements
◦ Int a=10, b=510
Statements used to receive data from computer memory
and send to output devices (monitor) are output
statements
◦ cout<<―your total GPA is = ―<<m<<endl;
3/26/2015 56
57. The ‗cout‘ object –Output Stream
The flow of data from-and-to a device is called a stream
‗cout‘ (see-out) stands for console out
Here the console out is the display screen (monitor)
‗cout‘ is used as an output statement and is part of
iostream header file
Example
◦ cout<<―One kilobyte = ―<<1024<<―bytes‖;
There are two string constants, one numeric constants
and three put to operators
3/26/2015 57
60. Example 1-08
#include <iostream>
#include <conio> used for functions such as
clearing the screen
int main ( )
{
clrscr ( )
cout<<―C++is a powerful programming language‖;
cout<<―UNIX operating system is written in C++‖;
cout<<―it is an easy to learn language‖;
return 0;
}
3/26/2015 60
64. The Escape Sequence
‗endl‘ is similar to an escape sequence
Do you remember what it did?
These are special non-printing characters
Used to control printing on the output device
Combination of ‗‘ and a code character
For example, n is an escape sequence which is used to
transfer the printing control to a new line
Used inside a string constant or independently
In single or double quotes
3/26/2015 64
65. The Escape Sequence
Can be used anywhere in the output stream
for example
◦ cout<<―I Love Pakistann‖;
◦ cout<<―I n Love n Pakistan‖;
3/26/2015 65
66. The Escape Sequence
Escape Sequence Explaination
a sounds an alert or alarm
b
backspace, print sequnce moves
a space back
cout<<"Pakistanb";
cout<<"Punjab";
the ouptput will be
PakistaPunjab
3/26/2015 66
67. The ―endl‖ Manipulator
Is an important and most common used manipulator
These are the operators used with put to (<<) operators
Stands for end of line
Has the same effect as ―n‖
For example
◦ cout<<―C++ n‖<<―programming n‖<<―language‖;
Is equivalent to
◦ Cout<<―C++ ―<<endl<<―programming ―<<endl<<―language‖;
3/26/2015 67
70. The ―setw‖ Manipulator
Stands for set width
Used to set width of the output on the output on the
screen
The output is left-justified
Syntax
◦ setw(n) where n is the specified width and is an integer
For example
◦ cout<<setw(10)<<―Pakistan‖<<setw(15)<<―Islamabad‖;
Is a part of ―iomanip.h‖ header file
3/26/2015 70
74. Example 1-12 (Assignment Statement)
#include <iostream.h>
int main ( )
{
int a, b, c;
a=200;
b=100;
c=a
a=b
b=c
cout<<―value of a = ―<<a<<endl;
cout<<―value of b = ―<<b<<endl;
}
3/26/2015 74
78. The ―cin‖ Object— Input Stream
‗cin‘ (see-in) stands for console input
This is an input stream
It is a part of iostream header file
It requires you to input from your keyboard during the execution
of a program
Value is input and press Enter to input the value
Syntax
cin>>var1[>>var2….]; >> is an extraction operator or get from
operator
Usually a separate statement is used for each variable
For example
◦ cin>>a>>b>>c; and press Enter to for typing each data
3/26/2015 78
79. Example 1-14
#include <iostream.h>
int main ( )
{
int n1, n2, s, p;
cout<<―Enter the first number ? ―;
cin>>n1;
cout<<―Enter the second number ? ―;
cin>>n2;
s=n1+n2;
p=n1*n2
cout<<―Sum of numbers = ―<<s<<endl;
cout<<―Product of numbers = ―<<p<<endl;
}
3/26/2015 79
81. Example 1-15
#include <iostream>
{
int age;
long int age_mon;
char name[50];
cout<<―Enter the name of the person ―;
cin>>name;
cout<<―Enter the age of person in years ―;
cin>>age;
age_mon = age*12;
cout<<―Name of the person = ―<<name<<endl;
cout<<―Age in months = ―<<age_mon<<endl;
}
3/26/2015 81
83. Example 1-16
float avg;
char name[20];
int total, cpp, os, edp;
cout<<―Enter the name of the student ―;
cin>>name;
cout<<―Enter the marks obtained in C++―;
cin>>cpp;
cout<<―Enter the marks obtained in Operating Systems―;
cin>>os;
cout<<―Enter the marks obtained in EDP―;
cin>>edp;
total = cpp+os+edp;
avg = total/3.0;
cout<<―Name of the student = ―<<name<<endl;
cout<<―Total Marks = ―<<total<<endl;
cout<<―Average Marks = ―<<avg<<endl;
3/26/2015 83
85. Example 1-17
{
float c, f;
cout << "Enter the temperature in Fahrenheit? ";
cin>>f;
c=(f-32)*5.0/9.0;
cout<<"The temperature in Celsius is = "<<c<<endl;
return 0;
}
3/26/2015 85
87. Example 1-18
{
float r,h,v;
cout << "Enter the radius of the cylinder = ";
cin>>r;
cout << "Enter the height of the cylinder = ";
cin>>h;
v=3.14*r*r*h;
cout<<"The volume of the cylinder is = "<<v;
return 0;
}
3/26/2015 87
89. Compound Assignment Statement
We have previously used simple statements, to assign
values to a variable
Like
◦ m=x*100+50
◦ v=p*r*r*h
The same assignment statements can be used to assign
one value to more than one variable.
E.g.
◦ x = y = 16;
3/26/2015 89
90. Example 1-19
{
int x, y, a, b, c, s;
x = y = a = b = c = 515;
s = x+y+a+b+c;
cout << "the sum is = " <<s<< endl;
return 0;
}
3/26/2015 90
92. Compound Assignment Expression
Is used to add, subtract, multiply etc a value to or from a
variable
◦ Without writing on either side of op ‗=‗
The arithmetic operator is combined with the
assignment operator (=)
Syntax
◦ var op = expression
xy = xy + 10;
◦ Here 10 is added to the variable xy
◦ Where xy already has some value
3/26/2015 92
93. Compound Assignment Expression
Which can also be written as
xy + = 10;
Similarly x += 9; is the same as?
◦ x = x + 9;
x -=9; is the same as?
◦ x = x – 9;
3/26/2015 93
96. The Comment Statement
Used to show comment on the coding statements in a
program
Used to explain the logic of the program
It is a non-executable statement
◦ // This is a my first program in C++
◦ // Java language is similar to C++
Can be given in any line of the program
e.g.
◦ sum=a+b //used to take sum of two variables
3/26/2015 96
97. Example 1-21
{
// declare the variables
int a,c; //a&c are variable names
a=10; //value 10 is assigned to a
c=a*a*a; //assignment statement to calculate cube
/* next statement is the output statement to
print the cube of 10 */
cout << "cube of "<<a <<" = "<<c<< endl;
// this is the end of the program
return 0;
}
3/26/2015 97