473,387 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

need explanation for its output

(a) Find and write the output of the following C++ program code:Note: Assume all required header files are already included in the program.
void Revert(int &Num, int Last=2)
{
Last = (Last%2==0)?Last+1: Last-1;
for(int C=1; C<=Last; C++)
Num+=C;
}
void main()
{
int A=20, B=4;
Revert(A,B);
cout<<A<<”&”<<B<<endl;
B--;
Revert(A,B);
cout<<A<<”#”<<B<<endl;
Revert(B);
cout<<A<<”#”<<B<<endl;
}

ans:
35&4
38#3
38#9
Nov 8 '18 #1
3 1419
weaknessforcats
9,208 Expert Mod 8TB
What is your question exactly?

Usually where you need to see how code works is to compile and link the code to get an executable and then step through the code with a debugger. This will show your outputs and the state of all of your variables.

Short of that write down on paper the path of execution.
Nov 9 '18 #2
i am getting a different answer while substituting the values for the var. when i compiled the pgm this is the ans which i got is
35&4
38#3
38#9. so can any one help me with an explanation for tht
Nov 9 '18 #3
weaknessforcats
9,208 Expert Mod 8TB
I compiled the code and ran it and got the same answer as in your Post #1.

Since you can compile the code and run it, you should be able to step through the code using your debugger. You will be able to see exactly how Revert functions.

If you don't know how to use your debugger, this is an excellent opportunity to learn how. Your debugger is your best friend.
Nov 9 '18 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Kaladhaur Palaniappa | last post by:
These are informix/4GL lines. I am writing equivalent perl code Can anyone explain me what this code performs sdate be any date ------------------ let mnth = month(sdate) let yr =...
2
by: Ken Varn | last post by:
I want to create a custom collection class that is similar to something like the System.Windows.Forms.Control.ControlCollection. I notice that this collection implements IList, ICollection,...
1
by: Avi | last post by:
I thought that this code means that <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="ArlDbAccess"...
2
by: jain_tj | last post by:
Could anyone please help me with the following problem My xml file is ============== <fig id="F0000001"> <caption>Caption text</caption> <image id="I0000001" image.class="halftone"...
5
by: Daniel Vukadinovic | last post by:
Can anyone explain me these things in C++? 1.What is :: used for like in the next case: if(.... { ... ::one;
4
by: rh1200la | last post by:
Hey all. I need to output an image via an .aspx page and hope someone here can help. I would like to display an image like this: <img src="displayImage.aspx?categoryID=1"> The .aspx page...
1
by: empaleador | last post by:
Hi I m reading a file that ends with a blank line and when i do the output it repeats the line before the blank 2 times. I am using ifstream infile; infile.open...
4
by: dismantle | last post by:
Hi all, this is my 3rd week in studying VB codes and i came across with this codes from a online tutorial about classes. Public Function MiddleInitial() As String MiddleInitial =...
1
by: shammika | last post by:
Hello everyone, I need to konw in detail what is pre fix & the post fix in java.
15
by: Pranav | last post by:
#include<stdio.h> #include<conio.h> int main() { const int i=6; int k = 9; int a, *c = a, *v = a ; a = 9; *c++ = *v++; // ( 1 ) This line does not generate any exception /
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.