I've been working with functions in C++ and I dont realy know what really is going on behind them( how the wheels spin :) ). What exactly i wanna know is:  how the parameters of a function get the values? ex:  #include&lt;iostream&gt;  int function(int x) {     x += 10;     return x; }   int main() {     int y;     std::cin &gt;&gt; y;     std::cout&lt;&lt; function(y); }  In reality the function parameter x will get the value y like this:  x=y  ?  Based on the first question, will pass by referenece be done like this &amp;x=y? y will be converted from int to int&amp; ???  #include&lt;iostream&gt;  void function(int&amp; x) {     x += 10;  }   int main() {     int y;     std::cin &gt;&gt; y;     function(y);     cout&lt;&lt;y; }   When we call a function how much memory will be allocated for it?how much will it consume? based on what?  I need to know everything that happens when a function is called , and how the function really work Sorry for my bad english , I'm Romanian. Thank you!
5893
What is the difference between    a parameter passed by reference a parameter passed by value?   Could you give me some examples, please?
6313
What is the best way(s) to fake function overloading in Javascript?   I know it is not possible to overload functions in Javascript as in other languages.  If I needed a function with two uses foo(x) and foo(x,y,z) which is the best / preferred way:   Using different names in the first place Using optional arguments like y = y || 'default' Using number of arguments Checking types of arguments Or how?
78860
The question was about plain  functions, not  static methods, as clarified in comments.  I understand what a static variable is, but what is a static function?  And why is it that if I declare a function, let's say void print_matrix, in let's say a.c (WITHOUT a.h) and include "a.c" -  I get "print_matrix@@....) already defined in a.obj", BUT if I declare it as static void print_matrix then it compiles?  UPDATE Just to clear things up - I know that including .c is bad, as many of you pointed out. I just do it to temporarily clear space in main.c until I have a better idea of how to group all those functions into proper .h and .c files. Just a temporary, quick solution.
93044
What is better: void foo() or void foo(void)? With void it looks ugly and inconsistent, but I've been told that it is good. Is this true?  Edit: I know some old compilers do weird things, but if I'm using just GCC, is void foo() Ok? Will foo(bar); then be accepted?
90106
In PHP, function parameters can be passed by reference by prepending an ampersand to the parameter in the function declaration, like so:  function foo(&amp;$bar) {     // ... }   Now, I am aware that this is not designed to improve performance, but to allow functions to change variables that are normally out of their scope.  Instead, PHP seems to use Copy On Write to avoid copying objects (and maybe also arrays) until they are changed. So, for functions that do not change their parameters, the effect should be the same as if you had passed them by reference.  However, I was wondering if the Copy On Write logic maybe is shortcircuited on pass-by-reference and whether that has any performance impact.  ETA: To be sure, I assume that it's not faster, and I am well aware that this is not what references are for. So I think my own guesses are quite good, I'm just looking for an answer from someone who really knows what's definitely happening under the hood. In five years of PHP development, I've always found it hard to get quality information on PHP internals short from reading the source.
91896
I was tasked with creating a function "transitions" that takes as input a value of type std_logic of arbitrary length. The returned value should be an integer that records the number of transitions (0 → 1, or 1 → 0) as you scan the binary bit pattern from left to right (or right to left). For example, the value 0110010011 would return 5; the value 001 would return 1.  Below is a piece of VHDL code that you can use to test your function. Add your function to the code and simulate to check that your code is giving the correct result. Show your code and the simulation results. In your simulation, display the first 100 ns, with t2, t4, t6 and t8 all shown as either signed or unsigned decimal and data displayed as binary.  library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity test_transitions is end test_transitions;  architecture Behavioral of test_transitions is   signal data: std_logic_vector (7 downto 0):="01111100";   signal t8, t6, t4, t2: integer; begin   tt: process   begin     wait for 10 ns;     data &lt;= data+1;   end process tt;    t8 &lt;= transitions(data);   t6 &lt;= transitions(data(5 downto 0));   t4 &lt;= transitions(data(3 downto 0));   t2 &lt;= transitions(data(1 downto 0));  end Behavioral;   Here's what I coded but keep receiving multiple syntax errors when I perform the Behavioral Check Syntax Test in the Xilinx ISE Design Suite. Any help would be greatly appreciated.  library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL;  entity TransitionFunction is end TransitionFunction;  architecture Behavioral of TransitionFunction is    function transition(signal data: in std_logic) return integer is      variable count: integer;   begin     count:= 0;     for i in data'range loop       if data(i) /= data(i+1) then         count := count + 1;       end if;     end loop;     return count;   end transition;    signal data: std_logic_vector(7 downto 0):="01111100";   signal t8, t6, t4, t2: integer; begin    tt:   process   begin     wait for 10 ns;     data &lt;= data+1;   end process tt;    t8 &lt;= transitions(data);   t6 &lt;= transitions(data(5 downto 0)));   t4 &lt;= transitions(data(3 downto 0)));   t2 &lt;= transitions(data(1 downto 0)));   end Behavioral;   Error messages:
51439
How do you do "inline functions" in C#? I don't think I understand the concept. Are they like anonymous methods? Like lambda functions?  Note: The answers almost entirely deal with the ability to , i.e. "a manual or compiler optimization that replaces a function call site with the body of the callee." If you are interested in , see  or .
44049
Is there a preferred way to return multiple values from a C++ function?  For example, imagine a function that divides two integers and returns both the quotient and the remainder.  One way I commonly see is to use reference parameters:  void divide(int dividend, int divisor, int&amp; quotient, int&amp; remainder);   A variation is to return one value and pass the other through a reference parameter:  int divide(int dividend, int divisor, int&amp; remainder);   Another way would be to declare a struct to contain all of the results and return that:  struct divide_result {     int quotient;     int remainder; };  divide_result divide(int dividend, int divisor);   Is one of these ways generally preferred, or are there other suggestions?  Edit: In the real-world code, there may be more than two results.  They may also be of different types.
29305
What does it mean to extend a function? Can someone please give an example?  Thanks in advance!
81821
In the  library, they are overloading the () operator.  Is this a convention in C++? For callbacks, etc.?  I have seen this in code of a co-worker (who happens to be a big Boost fan). Of all the Boost goodness out there, this has only led to confusion for me.  Any insight as to the reason for this overload?
67728
Is there any way of doing parallel assignment in C++? Currently, the below compiles (with warnings)  #include &lt;iostream&gt;   int main() {    int a = 4;   int b = 5;   a, b = b, a;   std::cout &lt;&lt; "a: " &lt;&lt; a &lt;&lt; endl             &lt;&lt; "b: " &lt;&lt; b &lt;&lt; endl;    return 0; }   and prints:  a: 4 b: 5   What I'd like it to print ... if it weren't obvious, is:  a: 5 b: 4   As in, say, ruby, or python.
7388
Why are pointers such a leading factor of confusion for many new, and even old, college level students in C or C++?  Are there any tools or thought processes that helped you understand how pointers work at the variable, function, and beyond level?  What are some good practice things that can be done to bring somebody to the level of, "Ah-hah, I got it," without getting them bogged down in the overall concept? Basically, drill like scenarios.
63970
Possible Duplicate:          I want to write a function that reverses the given string passed into it. But, I can not. If I supply the doReverse function (see code below) with a character array, my code works well.  I can't figure out why this does not work. I am able to access str[0] in doReverse, but I can't change any value of the array by using a char pointer. Any ideas?  void doReverse(char *str) {     str[0] = 'b'; }  void main(void) {     char *str = "abc";     doReverse(str);     puts(str); }   Update:  I know how to do write a reverse function by passing a character array to it:  void reverse1(char p[]) {     int i, temp, y;      for (i = 0, y = strlen(p); i &lt; y; ++i, --y) {         temp = p[y-1];         p[y-1] = p[i];         p[i] = temp;     } }   But, I want to write another version that gets a char pointer as a parameter.
4613
How can I create or use a global variable in a function?  If I create a global variable in one function, how can I use that global variable in another function? Do I need to store the global variable in a local variable of the function which needs its access?
26025
Is it better in C++ to pass by value or pass by constant reference?  I am wondering which is better practice.  I realize that pass by constant reference should provide for better performance in the program because you are not making a copy of the variable.
29293
Say I have classes Foo and Bar set up like this:  class Foo { public:     int x;      virtual void printStuff()     {         std::cout &lt;&lt; x &lt;&lt; std::endl;     } };  class Bar : public Foo { public:     int y;      void printStuff()     {         // I would like to call Foo.printStuff() here...         std::cout &lt;&lt; y &lt;&lt; std::endl;     } };   As annotated in the code, I'd like to be able to call the base class's function that I'm overriding. In Java there's the super.funcname() syntax. Is this possible in C++?
14089
I'm creating a function where I need to pass an object so that it can be modified by the function. What is the difference between:  public void myFunction(ref MyClass someClass)   and  public void myFunction(out MyClass someClass)   Which should I use and why?