?
Solved

A Few Newbie C++, Visual Studio Questions

Posted on 2004-09-14
5
Medium Priority
?
196 Views
Last Modified: 2010-04-24
Hi, thanks in advance for your help. I am new to C++ and have just started using Visual C++ .NET and these are my first initial questions. I appreciate any help you can give on any or all. Thanks again.

1. When I build and there's an error, how can I make sure it tells me details about the errors so I can know what to troubleshoot?
2. I don't fully understand when to use void and when to use int for the main function and in general.
3. Significance of passing by value as opposed to by reference.
 
0
Comment
Question by:frogpad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 6

Accepted Solution

by:
Svetlin_Panayotov earned 1000 total points
ID: 12061530
I'm not quiet sure I got your first question right, so - on the second.You should return int from main if your application is invoked by another app (or batch file or somethig) and the calling app needs to know what happend during the execution - so you can return some error code (or success) from main().
On your 3d question - when you're passing parameter by value your parameter can be modified only inside the method you're calling - and you're not actually modifying the parameter itself, but a copy.When you're passing value by reference you can modify it and no copy is created.
So you can run this simple program and watch the results - when calling by reference or by value:

#include "stdafx.h"
#include <conio.h>

void ByVal(int someInt)
{
      someInt = 5;
}

void ByRef(int* someInt)
{
      *someInt = 10;
}

int _tmain(int argc, _TCHAR* argv[])
{
      int test = 1;
      printf("Initial value of test: %d\n",test);
      ByVal(test);
      printf("Value of test after calling ByVal: %d\n",test);
      ByRef(&test);
      printf("Value of test after calling ByRef: %d\n",test);
      getch();
}
0
 
LVL 16

Assisted Solution

by:nonubik
nonubik earned 1000 total points
ID: 12062628
1. The errors are usually displayed in the 'Output' and 'Task list' windows. You can also have a build log : menu Tools->Options->Projects->VC++ Build->Build Logging select yes.

2.Whether you want or not to return an exit code to the parent process or operating system using a return statement. Although to return an exit code when main or wmain is declared as void, you must use the exit function. Better see http://msdn.microsoft.com/library/en-us/dv_vccelng4/html/ellrfmaincolprogramstartup.asp

3. Svetlin_Panayotov has quite answered to this, I'll just add:

void ByRef(int  &someInt)
{
     someInt = 10;
}

another form of passing by reference
0
 
LVL 6

Expert Comment

by:Svetlin_Panayotov
ID: 12063083
About 1.
If that's your question - nonubik explained it well.Just to add this - if you select an error(or warning) from "Task list" and press F1 - you'll get a detailed explanation, possible reason and maybe a sample - if the guys at MS that write their help were in good mood :)
0
 

Author Comment

by:frogpad
ID: 12076834
great, thanks very much guys, your feedback is much more clear than the text I am reading. Kudos.
0
 
LVL 6

Expert Comment

by:Svetlin_Panayotov
ID: 12078335
You're welcome :)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question