some questions

hi, here are my questions:
1- what does cout<<setprecision(integer) do exactly
2- what are static variables
3- what are parameters & arguments
4- what are stubs & drivers
5- void main(void) for example the () part is where i can type what is the data types of every variable? and some codes have it empty why?
6- what is wrong with this code:


#include <cstdlib>
#include <iostream>
using namespace std;

void showStatic(int statNum); // Function prototype

int main()
{
for (int count = 0; count < 5; count++)
showStatic(statNum);
system ("PAUSE");
return EXIT_SUCCESS;
}

void showStatic(int statNum)
{
static int statNum;
cout << "statNum is " << statNum << endl;
statNum++;
}
I can help you with 3. At least, the arguments bit.

When declaring a function, you use the following kind of syntax:

<return type> <function name>(<insert parameters here>)
{
//Put the body of the function here
}

For instance, we could have

1
2
3
4
int plusone(int x)
{
          return (x+1);
}


The int x in the parentheses means that we can call it by using plusone(insert integer here), and it will substitute that integer for x in the body of the function. For instance, plusone(1) would be 2.

The return is what the function returns. When we get to a return, the function immediately outputs the result of what's after the return and exits the function.
closed account (zb0S216C)
1) Sets the number of decimal places for the next floating-point number to be printed.
2) Too wide of a question. It depends, because static behaves differently in different contexts.
3) A parameter is a place-holder for an argument. When you create a function, the variables between the parentheses (...) are the parameters. An argument is a piece of data you pass to a function when you invoke (call) it. For instance:

1
2
3
4
void Function(int Parameter) { /*...*/ }

// Call the function:
Function(10); // 10 is an argument. 

4) I've never heard of these :/
5) Yes, that's where you store the arguments. An empty set of parentheses indicates that the function takes no arguments when you invoke it.
6) In showStatic(), the static statNum shadows the parameter statNum. In away, it's ambiguous.

Wazzak
Last edited on
As for point 6 according to the C++ Standard "A parameter name shall not be redeclared in the outermost block of the function definition nor in the outermost block of any handler associated with a function-try-block."

So the compiler shall issue an error.
Topic archived. No new replies allowed.