This document provides an overview of compilers and what they are. It discusses how compilers translate high-level programming languages like C++ into machine-readable machine code. It also covers the basic components of a compiler, including the preprocessor, compiler, linker, and libraries. Finally, it demonstrates a simple C++ program that adds two numbers and outputs the sum, highlighting key elements like variables, data types, and output statements.
C is mother language of all programming language.
It is a system programming language. It is a procedure-oriented programming language. It is also called mid-level programming language.
C evolved from a language called B, written by Ken Thompson at Bell Labs in 1970. Ken used B to write one of the first implementations of UNIX. B in turn was a descendant of the language BCPL (developed at Cambridge (UK) in 1967), with most of its instructions removed.
So many instructions were removed in going from BCPL to B, that Dennis Ritchie of Bell Labs put some back in (in 1972), and called the language C.
The famous book The C Programming Language was written by Kernighan and Ritchie in 1978, and was the definitive reference book on C for almost a decade.
The original C was still too limiting, and not standardized, and so in 1983, an ANSI committee was established to formalize the language definition.
It has taken until now (ten years later) for the ANSI ( American National Standard Institute) standard to become well accepted and almost universally supported by compilers.
C is mother language of all programming language.
It is a system programming language. It is a procedure-oriented programming language. It is also called mid-level programming language.
C evolved from a language called B, written by Ken Thompson at Bell Labs in 1970. Ken used B to write one of the first implementations of UNIX. B in turn was a descendant of the language BCPL (developed at Cambridge (UK) in 1967), with most of its instructions removed.
So many instructions were removed in going from BCPL to B, that Dennis Ritchie of Bell Labs put some back in (in 1972), and called the language C.
The famous book The C Programming Language was written by Kernighan and Ritchie in 1978, and was the definitive reference book on C for almost a decade.
The original C was still too limiting, and not standardized, and so in 1983, an ANSI committee was established to formalize the language definition.
It has taken until now (ten years later) for the ANSI ( American National Standard Institute) standard to become well accepted and almost universally supported by compilers.
Introduction
The term problem solving is used in many disciplines, sometimes with different perspectives and
often with different terminologies. The problem-solving process starts with the problem
specification and end with a correct program.
The steps to follow in the problem-solving process are:
Problem definition
Problem Analysis
Algorithm development
Coding
Testing & Debugging
Documentation & Maintenance
The stages of analysis, design, programming, implementation and maintenance form the life cycle
of the system.
Steps of Learning Programming Language. and much more with and easy way. Like ---
History of C language, What is C, Step by step procedure to learn C language with interview questions.
C, C language ppt, Learn C, Basic C, What is C?, How to learn C, language, programming language ppt, OOPs, POOPs, Learn C ppt, C ppt, C Program, first program, Variable in C, Keyword in C, constant in C ?
C & C++ Training Centre in Ambala! BATRA COMPUTER CENTREjatin batra
Are you in search of C & C++ Training in Ambala? Now your search ends here.. BATRA COMPUTER CENTRE provides best training in:Basics of Computer, HTML,PHP,WebDesigning
Web Development , SEO, SMO and So many other courses are available here.
SULTHAN's - C Programming Language notesSULTHAN BASHA
This book contains programming techniques, learning objectives of C language. And it will help for data structures concepts also. This is very useful to the beginners.
Introduction
The term problem solving is used in many disciplines, sometimes with different perspectives and
often with different terminologies. The problem-solving process starts with the problem
specification and end with a correct program.
The steps to follow in the problem-solving process are:
Problem definition
Problem Analysis
Algorithm development
Coding
Testing & Debugging
Documentation & Maintenance
The stages of analysis, design, programming, implementation and maintenance form the life cycle
of the system.
Steps of Learning Programming Language. and much more with and easy way. Like ---
History of C language, What is C, Step by step procedure to learn C language with interview questions.
C, C language ppt, Learn C, Basic C, What is C?, How to learn C, language, programming language ppt, OOPs, POOPs, Learn C ppt, C ppt, C Program, first program, Variable in C, Keyword in C, constant in C ?
C & C++ Training Centre in Ambala! BATRA COMPUTER CENTREjatin batra
Are you in search of C & C++ Training in Ambala? Now your search ends here.. BATRA COMPUTER CENTRE provides best training in:Basics of Computer, HTML,PHP,WebDesigning
Web Development , SEO, SMO and So many other courses are available here.
SULTHAN's - C Programming Language notesSULTHAN BASHA
This book contains programming techniques, learning objectives of C language. And it will help for data structures concepts also. This is very useful to the beginners.
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...bhargavi804095
C++ is a cross-platform language that can be used to create high-performance applications.
C++ was developed by Bjarne Stroustrup, as an extension to the C language.
C++ gives programmers a high level of control over system resources and memory.
For more course tutorials visit
www.newtonhelp.com
Lab 1 of 7: Getting Started (Your First C++ Programs) Lab Overview - Scenario/Summary
Welcome to Programming with C++. The purpose of this three-part lab is to walk you through the following tutorial to become familiar with the actions of compiling and executing a C++ program.
CIS 170 Imagine Your Future/newtonhelp.com bellflower42
For more course tutorials visit
www.newtonhelp.com
Lab 1 of 7: Getting Started (Your First C++ Programs) Lab Overview - Scenario/Summary
Welcome to Programming with C++. The purpose of this three-part lab is to walk you through the following tutorial to become familiar with the actions of compiling and executing a C++ program.
Search and Society: Reimagining Information Access for Radical FuturesBhaskar Mitra
The field of Information retrieval (IR) is currently undergoing a transformative shift, at least partly due to the emerging applications of generative AI to information access. In this talk, we will deliberate on the sociotechnical implications of generative AI for information access. We will argue that there is both a critical necessity and an exciting opportunity for the IR community to re-center our research agendas on societal needs while dismantling the artificial separation between the work on fairness, accountability, transparency, and ethics in IR and the rest of IR research. Instead of adopting a reactionary strategy of trying to mitigate potential social harms from emerging technologies, the community should aim to proactively set the research agenda for the kinds of systems we should build inspired by diverse explicitly stated sociotechnical imaginaries. The sociotechnical imaginaries that underpin the design and development of information access technologies needs to be explicitly articulated, and we need to develop theories of change in context of these diverse perspectives. Our guiding future imaginaries must be informed by other academic fields, such as democratic theory and critical theory, and should be co-developed with social science scholars, legal scholars, civil rights and social justice activists, and artists, among others.
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
Keynote at DIGIT West Expo, Glasgow on 29 May 2024.
Cheryl Hung, ochery.com
Sr Director, Infrastructure Ecosystem, Arm.
The key trends across hardware, cloud and open-source; exploring how these areas are likely to mature and develop over the short and long-term, and then considering how organisations can position themselves to adapt and thrive.
GraphRAG is All You need? LLM & Knowledge GraphGuy Korland
Guy Korland, CEO and Co-founder of FalkorDB, will review two articles on the integration of language models with knowledge graphs.
1. Unifying Large Language Models and Knowledge Graphs: A Roadmap.
https://arxiv.org/abs/2306.08302
2. Microsoft Research's GraphRAG paper and a review paper on various uses of knowledge graphs:
https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/
Accelerate your Kubernetes clusters with Varnish CachingThijs Feryn
A presentation about the usage and availability of Varnish on Kubernetes. This talk explores the capabilities of Varnish caching and shows how to use the Varnish Helm chart to deploy it to Kubernetes.
This presentation was delivered at K8SUG Singapore. See https://feryn.eu/presentations/accelerate-your-kubernetes-clusters-with-varnish-caching-k8sug-singapore-28-2024 for more details.
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf91mobiles
91mobiles recently conducted a Smart TV Buyer Insights Survey in which we asked over 3,000 respondents about the TV they own, aspects they look at on a new TV, and their TV buying preferences.
UiPath Test Automation using UiPath Test Suite series, part 4DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 4. In this session, we will cover Test Manager overview along with SAP heatmap.
The UiPath Test Manager overview with SAP heatmap webinar offers a concise yet comprehensive exploration of the role of a Test Manager within SAP environments, coupled with the utilization of heatmaps for effective testing strategies.
Participants will gain insights into the responsibilities, challenges, and best practices associated with test management in SAP projects. Additionally, the webinar delves into the significance of heatmaps as a visual aid for identifying testing priorities, areas of risk, and resource allocation within SAP landscapes. Through this session, attendees can expect to enhance their understanding of test management principles while learning practical approaches to optimize testing processes in SAP environments using heatmap visualization techniques
What will you get from this session?
1. Insights into SAP testing best practices
2. Heatmap utilization for testing
3. Optimization of testing processes
4. Demo
Topics covered:
Execution from the test manager
Orchestrator execution result
Defect reporting
SAP heatmap example with demo
Speaker:
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
Sidekick Solutions uses Bonterra Impact Management (fka Social Solutions Apricot) and automation solutions to integrate data for business workflows.
We believe integration and automation are essential to user experience and the promise of efficient work through technology. Automation is the critical ingredient to realizing that full vision. We develop integration products and services for Bonterra Case Management software to support the deployment of automations for a variety of use cases.
This video focuses on the notifications, alerts, and approval requests using Slack for Bonterra Impact Management. The solutions covered in this webinar can also be deployed for Microsoft Teams.
Interested in deploying notification automations for Bonterra Impact Management? Contact us at sales@sidekicksolutionsllc.com to discuss next steps.
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
The Art of the Pitch: WordPress Relationships and SalesLaura Byrne
Clients don’t know what they don’t know. What web solutions are right for them? How does WordPress come into the picture? How do you make sure you understand scope and timeline? What do you do if sometime changes?
All these questions and more will be explored as we talk about matching clients’ needs with what your agency offers without pulling teeth or pulling your hair out. Practical tips, and strategies for successful relationship building that leads to closing the deal.
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualityInflectra
In this insightful webinar, Inflectra explores how artificial intelligence (AI) is transforming software development and testing. Discover how AI-powered tools are revolutionizing every stage of the software development lifecycle (SDLC), from design and prototyping to testing, deployment, and monitoring.
Learn about:
• The Future of Testing: How AI is shifting testing towards verification, analysis, and higher-level skills, while reducing repetitive tasks.
• Test Automation: How AI-powered test case generation, optimization, and self-healing tests are making testing more efficient and effective.
• Visual Testing: Explore the emerging capabilities of AI in visual testing and how it's set to revolutionize UI verification.
• Inflectra's AI Solutions: See demonstrations of Inflectra's cutting-edge AI tools like the ChatGPT plugin and Azure Open AI platform, designed to streamline your testing process.
Whether you're a developer, tester, or QA professional, this webinar will give you valuable insights into how AI is shaping the future of software delivery.
Connector Corner: Automate dynamic content and events by pushing a buttonDianaGray10
Here is something new! In our next Connector Corner webinar, we will demonstrate how you can use a single workflow to:
Create a campaign using Mailchimp with merge tags/fields
Send an interactive Slack channel message (using buttons)
Have the message received by managers and peers along with a test email for review
But there’s more:
In a second workflow supporting the same use case, you’ll see:
Your campaign sent to target colleagues for approval
If the “Approve” button is clicked, a Jira/Zendesk ticket is created for the marketing design team
But—if the “Reject” button is pushed, colleagues will be alerted via Slack message
Join us to learn more about this new, human-in-the-loop capability, brought to you by Integration Service connectors.
And...
Speakers:
Akshay Agnihotri, Product Manager
Charlie Greenberg, Host
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Tobias Schneck
As AI technology is pushing into IT I was wondering myself, as an “infrastructure container kubernetes guy”, how get this fancy AI technology get managed from an infrastructure operational view? Is it possible to apply our lovely cloud native principals as well? What benefit’s both technologies could bring to each other?
Let me take this questions and provide you a short journey through existing deployment models and use cases for AI software. On practical examples, we discuss what cloud/on-premise strategy we may need for applying it to our own infrastructure to get it to work from an enterprise perspective. I want to give an overview about infrastructure requirements and technologies, what could be beneficial or limiting your AI use cases in an enterprise environment. An interactive Demo will give you some insides, what approaches I got already working for real.
2. Slide 2
Compilers
The essential tools needed to follow these tutorials
are a computer and a compiler tool chain able to
compile C++ code and build the programs to run on
it.
3. Slide 3
What is a compiler?
Computers understand only one language and that language
consists of sets of instructions made of ones and zeros. This
computer language is appropriately called machine language.
A single instruction to a computer could look like this:
00000 10011110
A particular computer's machine language program that allows a user to input
two numbers, adds the two numbers together, and displays the total could
include these machine code instructions:
00000 10011110
00001 11110100
00010 10011110
00011 11010100
00100 10111111
00101 00000000
Compiler
4. Slide 4
As you can imagine, programming a computer directly in
machine language using only ones and zeros is very tedious
and error prone. To make programming easier, high level
languages have been developed.
• This is a portion of code written in C++ that accomplishes
the exact same purpose:
int a, b, sum;
cin >> a;
cin >> b;
sum = a + b;
cout << sum << endl;
Compiler
5. Slide 5
Console programs are programs that use text to communicate
with the user and the environment, such as printing text to the
screen or reading input from a keyboard.
Console programs
6. Slide 6
What is an algorithm?
An algorithm is a clear, concise, and correct step-
by-step sequence of actions used to solve a
problem or set of problems
8. Slide 8
Example 2 Solution
1. Compare the top two papers of the stack; place the
smaller valued paper on the bottom of the stack and
keep the larger valued paper
2. Grab the next paper off of the top of the stack and
compare it to the paper you kept; place the smaller of
these two on the bottom of the stack and keep the larger
3. Repeat step 2 until you have reached the
(original)bottom of the stack; you should now be holding
the largest valued paper in the stack; set this paper aside
into a new “sorted stack”
4. Repeat steps 1, 2 & 3, placing the paper from step 3 onto
the “sorted stack”, until no more papers remain
9. Slide 9
Applying algorithms to your coding problems
1. Control Flow Charts - Some programmers prefer to
develop drawings showing how information passes
from state to state in a solution.
2. Pseudocode – You may develop your own
pseudocode language containing all the usual coding
constructs of high-level languages and use it to write
algorithms to solve your problem.
10. Slide 10
PROGRAMMING WITH VISUAL C++
WHAT IS THE INTEGRATED DEVELOPMENT ENVIRONMENT?
•The integrated development environment (IDE) that comes with Visual C++
2010 is a completely self - contained environment for creating, compiling,
linking, and testing your C++ programs.
•The fundamental parts of Visual C++, provided as part of the IDE, are the
editor, the compiler, the linker, and the libraries. These are the basic tools
that are essential to writing and executing a C++ program.
11. Slide 11
PROGRAMMING WITH VISUAL C++
The Editor
The editor provides an interactive environment in which to create and edit C++
source code. As well as the usual facilities, such as cut and paste, which you
are certainly already familiar with, the editor also provides color cues to
differentiate between various language elements.
12. Slide 12
PROGRAMMING WITH C++
The Linker
The linker combines the various modules generated by the compiler from source code fi les, adds
required code modules from program libraries supplied as part of C++, and welds everything into
an executable whole.
14. Slide 14
PROGRAMMING WITH C++
Phases of C++ program
Typical C++ program development has 6 phases:
•Phase 1: Creating a Program
•Phase 2: Preprocessing a C++ Program
•Phase 3: Compiling a C++ Program
•Phase 4: Linking
•Phase 5: Loading
•Phase 6: Execution
15. Slide 15
PROGRAMMING WITH C++
Phase 1: Creating a Program
Phase 1 consists of editing a file with an editor program, normally known simply as an editor. You type a C++ program (typically referred to
as source code) using the editor, make any necessary corrections and save the program on a secondary storage device, such as your hard drive.
16. Slide 16
PROGRAMMING WITH C++
Phase 2: Preprocessing a C++ Program
In a C++ system, a preprocessor program executes automatically before the compiler’s translation phase begins. The C++ preprocessor obeys
commands called preprocessor directives, which indicate that certain manipulations are to be performed on the program before compilation.
These manipulations usually include other text files to be compiled, and perform various text replacements.
17. Slide 17
PROGRAMMING WITH C++
Phase 3: Compiling a C++ Program
In Phase 3, the compiler translates the C++ program into machine-language code
18. Slide 18
PROGRAMMING WITH C++
Phase 4: Linking
Phase 4 is called linking. C++ programs typically contain references to functions and data defined elsewhere, such as in the standard libraries
or in the private libraries of groups of programmers working on a particular project. A linker links the object code with the code for the
missing functions to produce an executable program.
19. Slide 19
PROGRAMMING WITH C++
Phase 5: Loading
Before a program can be executed, it must first be placed in memory. This is done by the loader, which takes the
executable image from disk and transfers it to memory.
20. Slide 20
PROGRAMMING WITH C++
Phase 6: Execution
Finally, the computer, under the control of its CPU, executes the program one instruction at a time.
22. Preprocessor Directives
Slide 22
C++ source code is pre-processed before it is compiled into
object Code. A preprocessor directive, which begins with a #
sign (such as #include, #define), tells the preprocessor to
perform a certain action (such as including a header file, or
performing text replacement), before compiling the source
code into object code.
Preprocessor directives are not programming statements,
and therefore should NOT be terminated with a semi-colon.
23. Slide 23
PROGRAMMING WITH VISUAL C++
In almost all of the C++ programs, we use #include <iostream> to
include the input/output stream library header into our program, so as
to use the IO library function to carry out input/output operations (such
as cin and cout).
For example,
24. Slide 24
PROGRAMMING WITH VISUAL C++
Comments
Comments are used to document and explain your codes and program logic.
Comments are not programming statements and are ignored by the compiler,
but they VERY IMPORTANT for providing documentation and explanation for
others to understand your program (and also for yourself three days later).
There are two kinds of comments in C/C++:
1.Multi-line Comment: begins with a /* and ends with a */, and can
span several lines.
2.End-of-line Comment: begins with // and lasts till the end of the
current line.
25. Slide 25
PROGRAMMING WITH VISUAL C++
The mainmain Function
Following the preprocessor directive(s) is the body of the
program characterized by the function main().
• The execution of a C++ program always starts here.
• It is a standardized convention that function main()main() is
declared with an intint preceding it.
• intint is the return value type of the function main()main().
• The parentheses after main indicate that main is a
program building block called a functionfunction.
26. Slide 26
Declaration of variables
Variable Declarations
In C++ before use of any variables you should declare it. This
means Variable Declaration. For example we want to write a
program that add two numbers. In this case we should declare
three variables. The type off variable is important.
For example:
int a;
float mynumber;
27. Declaration of variables
int a, b, c;
Slide 27
If declaring more than one variable of the same type, they can all be
declared in a single statement by separating their identifiers with commas.
For example:
To see what variable declarations look like in action within a program,
let's have a look at the entire C++ code in the next slide:
28. Declaration of variables
Slide 28
// operating with variables
#include <iostream>
using namespace std;
int main ()
{
// declaring variables:
int a, b;
int result;
// process:
a = 5;
b = 2;
a = a + 1;
result = a - b;
// print out the result:
cout << result;
// terminate the program:
return 0;
}
Don't be worried if something else than the variable declarations themselves look a bit strange
to you. Most of it will be explained in more detail in coming chapters.
29. Initialization of variables
Slide 29
When the variables in the example above are declared, they have an
undetermined value until they are assigned a value for the first time. But it is
possible for a variable to have a specific value from the moment it is declared.
This is called the initialization of the variable.
For example, to declare a variable of type int called x and initialize it to a value of
zero from the same moment it is declared, we can write:
int x = 0;
A second method, known as constructor initialization (introduced by the C++
language), encloses the initial value between parentheses (()):
type identifier (initial_value);
For example:
int x (0);
31. Slide 31
All three ways of initializing variables are valid and equivalent in C++.
// initialization of variables
#include <iostream>
using namespace std;
int main ()
{
int a=5; // initial value: 5
int b(3); // initial value: 3
int c{2}; // initial value: 2
int result; // initial value undetermined
a = a + b;
result = a - c;
cout << result;
return 0;
}
32. Type deduction: auto and decltype
Slide 32
When a new variable is initialized, the compiler can figure out what the type of the
variable is automatically by the initializer. For this, it suffices to use auto as the type
specifier for the variable:
int foo = 0;
auto bar = foo; // the same as: int bar = foo;
Here, bar is declared as having an auto type; therefore, the type of bar is the type
of the value used to initialize it: in this case it uses the type of foo, which is int.
Variables that are not initialized can also make use of type deduction with the
decltype specifier:
int foo = 0;
decltype(foo) bar; // the same as: int bar;
34. Slide 34
variables
In the last example we want to use integer numbers so we should to
define them before using in our program.
Simply we consider ‘Number 1’ as first and ‘Number 2’ as second
and ‘Sum’ as third number. So for declaration these number we have:
int number1; // first integer to add
int number2; // second integer to add
int sum; // sum of number1 and number2
35. Slide 35
Naming variables Or Identifier
• Naming variables appropriately is important for writing good,
understandable, and maintainable code.
• Variable names can be alphanumeric, but they cannot start with a
number.
• They cannot contain spaces and cannot contain arithmetic operators
(such as +, –, and so on) within them.
• You can elongate variable names using an underscore.
• Variables names also cannot be reserved keywords. For example, a
variable named return causes compilation failures.
36. Slide 36
1)A variable has a name (or identifier), e.g., radius, area, age, height. The name
is needed to uniquely identify each variable, so as to assign a value to the
variable (e.g., radius=1.2), and retrieve the value stored (e.g., area =
radius*radius*3.1416).
2)A variable has a type. Examples of type are,
1) int: for integers (whole numbers) such as 123 and -456;
2) double: for floating-point or real numbers such as 3.1416, -55.66,
having a decimal point and fractional part.
3)A variable can store a value of that particular type. It is important to take note
that a variable in most programming languages is associated with a type, and
can only store value of the particular type. For example, a int variable can store
an integer value such as 123, but NOT real number such as 12.34, nor texts such
as "Hello".
4)The concept of type was introduced into the early programming languages to
simplify interpretation of data made up of 0s and 1s. The type determines the
size and layout of the data, the range of its values, and the set of operations that
can be applied.
variables
37. Assignment operator (=)
Slide 37
The assignment operator assigns a value to a variable.
x = 5;
This statement assigns the integer value 5 to the variable x. For example, let's have a look at
the following code - I have included the evolution of the content stored in the variables as
comments:
// assignment operator
#include <iostream>
using namespace std;
int main ()
{
int a, b; // a:?, b:?
a = 10; // a:10, b:?
b = 4; // a:10, b:4
a = b; // a:4, b:4
b = 7; // a:4, b:7
cout << "a:";
cout << a;
cout << " b:";
cout << b;
}
38. Arithmetic operators ( +, -, *, /, % )
Slide 38
The five arithmetical operations supported by C++ are:
operator description
+ addition
- subtraction
* multiplication
/ division
% modulo
Operations of addition, subtraction, multiplication and division correspond literally to
their respective mathematical operators. The last one, modulo operator, represented
by a percentage sign (%), gives the remainder of a division of two values. For
example:
x = 11 % 3;
results in variable x containing the value 2, since dividing 11 by 3 results in 3, with a
remainder of 2.
40. Slide 40
and the same for all other compound assignment operators. For example:
// compound assignment operators
#include <iostream>
using namespace std;
int main ()
{
int a, b=3;
a = b;
a+=2; // equivalent to a=a+2
cout << a;
}
41. Increment and decrement (++, --)
Slide 41
Some expression can be shortened even more: the increase operator (++) and the
decrease operator (--) increase or reduce by one the value stored in a variable.
They are equivalent to +=1 and to -=1, respectively. Thus:
++x;
x+=1;
x=x+1;
Example 1 Example 2
x = 3;
y = ++x;
// x contains 4, y contains 4
x = 3;
y = x++;
// x contains 4, y contains 3
42. Slide 42
PROGRAMMING WITH VISUAL C++
An Output Statement
• Every C++ statement must end with a semicolon (also
known as the statement terminator).
43. Slide 43
PROGRAMMING WITH VISUAL C++
The std Namespace
The coutcout is defined in stdstd namespace. When we want to
use the coutcout we should make clear that coutcout is located in
stdstd namespace.
Many programmers find it tedious to repeatedly add the stdstd
namespace specifier to their code when using coutcout and
other such features contained in the same. The using
namespace declaration will help you avoid this repetition.
46. Slide 46
PROGRAMMING WITH VISUAL C++
Returning a Value
Functions in C++ need to return a value unless explicitly specified otherwise.
main()main() is a function, too, and always returns an integer.
48. Slide 48
Another C++ Program: Adding Integers
Another C++ Program: Adding Integers
Our next program uses the input stream object std::cin and the stream extraction operator, >>,
to obtain two integers typed by a user at the keyboard, computes the sum of these values and
outputs the result using std::cout.
49. Introduction to strings
Slide 49
Fundamental types represent the most basic types handled by the machines where
the code may run. But one of the major strengths of the C++ language is its rich set
of compound types, of which the fundamental types are mere building blocks.
An example of compound type is the string class. Variables of this type are able to
store sequences of characters, such as words or sentences.
For use of string type the program needs to include the header where the type is
defined within the standard library (header <string>):
// my first string
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string mystring;
mystring = "This is a string";
cout << mystring;
return 0;
}
50. Introduction to strings
Slide 50
As you can see in the previous example, strings can be initialized with any
valid string literal, just like numerical type variables can be initialized to any
valid numerical literal. As with fundamental types, all initialization formats are
valid with strings:
string mystring = "This is a string";
string mystring ("This is a string");
string mystring {"This is a string"};
51. constant expressions
Slide 51
Sometimes, it is just convenient to give a name to a constant value:
const double pi = 3.1415926;
const char tab = 't';
We can then use these names instead of the literals they were defined to:
#include <iostream>
using namespace std;
const double pi = 3.14159;
const char newline = 'n';
int main ()
{
double r=5.0; // radius
double circle;
circle = 2 * pi * r;
cout << circle;
cout << newline;
}
52. Preprocessor definitions (#define)
Slide 52
Another mechanism to name constant values is the use of preprocessor
definitions. They have the following form:
#define identifier replacement
#include <iostream>
using namespace std;
#define PI 3.14159
#define NEWLINE 'n'
int main ()
{
double r=5.0; // radius
double circle;
circle = 2 * PI * r;
cout << circle;
cout << NEWLINE;
}
Note that the #define lines are preprocessor directives, and as such are single-line instructions
that -unlike C++ statements- do not require semicolons (;) at the end.
53. Explicit type casting operator
Slide 53
Type casting operators allow to convert a value of a given type to another
type. There are several ways to do this in C++. The simplest one, which has
been inherited from the C language, is to precede the expression to be
converted by the new type enclosed between parentheses (()):
int i;
float f = 3.14;
i = (int) f;
The previous code converts the floating-point number 3.14 to an integer
value (3);
Another way to do the same thing in C++ is to use the functional notation
preceding the expression to be converted by the type and enclosing the
expression between parentheses:
i = int (f);
54. sizeof
Slide 54
This operator accepts one parameter, which can be either a type or a variable,
and returns the size in bytes of that type or object:
x = sizeof (char);
55. swap()
Slide 55
Function swap() is a C++ Standard Library function. It exchanges the
values of two variables. The variables should be of same type. See the
following program for illustration.
#include <iostream>
using namespace std;
int main()
{//swap function interchanges the values of same type variables
int x ,y;
cout<<"Write two integers x = ";
cin>>x; cout<<" and y = "; cin>>y;
swap(x,y);
cout <<"After swapping: x = "<<x <<" and y = "<< y<<endl;
return 0;
}