A Few Newbie C++, Visual Studio Questions

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.
 
frogpadAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Svetlin_PanayotovConnect With a Mentor Commented:
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
 
nonubikConnect With a Mentor Commented:
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
 
Svetlin_PanayotovCommented:
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
 
frogpadAuthor Commented:
great, thanks very much guys, your feedback is much more clear than the text I am reading. Kudos.
0
 
Svetlin_PanayotovCommented:
You're welcome :)
0
All Courses

From novice to tech pro — start learning today.