Can anyone help me in C++ about call by reference?
116146
By using "Call by Reference", we can modify values that passsed to a function. If we use "Call by Value", we can not modify value of parameters, because actually we just modify values that stored in stack, not in the memory.\n\nHere is the example. In the main program, we pass a variabel contains number 1, and functions try to change it. Excuse me, my English is bad.\n\nvoid test_one(int a) {\n  a = 2;\n};\n\nvoid test_two(int *a) {\n  *a = 2;\n};\n\n// C++\nvoid test_three(int &a) {\n  a = 2;\n};\n\nvoid main(void) {\n  int a;\n\n  a = 1;\n  test_one(a);\n  printf("%d&#92;n", a);  // Result: 1;\n\n  a = 1;\n  test_two(&a);\n  printf("%d&#92;n", a);  // Result: 2;\n\n  a = 1;\n  test_three(a);\n  printf("%d&#92;n", a);  // Result: 2;\n};\n\n"&" sign means: Address of this variable in memory.\n"*" sign means: Address that pointed by this memory address.\n\nThe best way to understand this, is by examine the Assembly Code of this program. You can use Turbo Debugger or just DEBUG.COM.\n\nIf you think my answer is the best answer, would you please do rate mine? Thank you.\n\nGreetings from Tangerang, Indonesia.
83035
#define __TEST__\n\n#include <stdio.h>\n\n#ifdef __TEST__\n#include <conio.h>\n#include <stdlib.h>\n#endif\n#define STACKSIZE 64\n\n\nint stack[STACKSIZE];\nstatic int stack_ptr=0;\n\nvoid overflow_test( int pos )\n{\nif( pos >= STACKSIZE )\n{\nputs( "Stack overflow!&#92;n" );\nexit(1);\n}\n}\n\nvoid underflow_test( int pos )\n{\nif( pos < 0 )\n{\nputs( "Stack underflow!&#92;n" );\nexit(1);\n}\n}\n\nvoid push( int value )\n{\noverflow_test( stack_ptr+1 );\nstack[stack_ptr++] = value;\n}\n\nint pop( void )\n{\nunderflow_test( --stack_ptr );\nreturn stack[stack_ptr];\n}\n\n#ifdef __TEST__\n\nvoid wait4keypress( void )\n{\nwhile( !kbhit())\n;\n}\n\nint main( void )\n{\natexit(wait4keypress); \npush(1);\npush(2);\npush(3);\nprintf( "%d&#92;n", pop());\nprintf( "%d&#92;n", pop());\nprintf( "%d&#92;n", pop());\n/* must cause stack underflow */\nprintf( "%d&#92;n", pop());\nreturn 0;\n}\n\n#endif  /* __TEST__ */
440282
in c main can return void but not in c++\nin c++ it alsways return an int
575599
#include<iostream.h>\n\n  int main()\n {\n   int n = 5;\n   for(int i=1;i<=n;i++)\n   {\n    for(int j=n;j<0;j--)\n      cout << * ;\n    }\n }
530460
in c, it is not needed to return anything. So you can call a void main.\nIn c++, you need to return an int from main. The convention is to return 1 for suceess and 0 for a failure.\nC today also supports an int main()
1178612
Well.... That's too Hard to find... i'm poor at C++...... So can't help.. have good day! Search in Google
614947
#include <iostream.h>\n#include <conio.h>\n#include <process.h>\n\nmain()\n\n{\n\nchar c;\n\nclrscr();\ncout<<"Press 0 to exit&#92;n";\n\ndo\n{\n\n c=getch();\n\n switch(c)\n {\n   case '0': exit(0);\n   case '1': cout<<"I";break;\n   case '2': cout<<"L";break;\n   case '3': cout<<"o";break;\n   case '4': cout<<"v";break;\n   case '5': cout<<"e";break;\n   case '6': cout<<"U";break;\n }\n\n} while (1);\nreturn 0;\n}
155011
I'm supposing you are talking about C++.\nIn C++ Constructor is called when you are constructing it using new operator. You can pass parameter then.\nObjectpointer=new Object(param1, pram2,....)
186666
#include <time.h>\n#include <stdlib.h>\n\n#include <iostream.h>\n#include <algo.h>\n\ntypedef double T;\n\nvoid test(int N)\n{\n  if(N < 1)\n  {\n    cerr << "Input value " << N << " too small." << endl;\n    return;\n  }\n\n  T* data = new T[N];\n  if(!data)\n  {\n    cerr << "Could not allocate data - " << N*sizeof(T) << " bytes." << endl;\n    return;\n  }\n  for(int i=0; i<N; ++i)\n    data[i] = rand();\n\n  time_t begin = clock();\n  sort(data, data+N);\n  time_t end = clock();\n  double time_elapsed = double(end-begin)/CLOCKS_PER_SEC;\n\n  cout << time_elapsed << endl;\n  delete[] data;\n}\n\nint main(int argc, char* argv[])\n{\n  if(argc != 2)\n    cerr << "Usage: " << argv[0] << "<array-size>" << endl;\n  else\n  {\n    for(int i=0; i<10; ++i)\n      test(atoi(argv[1]));\n  }\n  return 0;\n}
653205
It lets the linker help the compiler piece together code that is in other files/libraries - for instance, if you do:\n\n#include <iostream>\n\nYou're going to be able to use the functions within the iostream library - otherwise, it wouldn't know where to go to get those function definitions.
557543
#include<iostream>\nusing namespace std;\nint main ()\n\n\n    {\nint number;\nint answer;\n    cout<<"Please enter number: ";\n    cin>>number;\n    \n    cout<<number<<"! = ";\n    answer = number;\n    while (number>1)\n\n\n        {\n        answer=answer*(number-1);\n        number--; \n    } \n\n    cout<<answer; \n    return 0; \n}
331457
It usually should have called the constructor A() if you are making the object in maner "A a1;" in the main function. But also you have overloaded the operator "()". SO, it makes a confusion and actually none of the output from the above constructors are called. Another thing, its not a good thing to inital values in parameters. I've often faced these problems when I overloaded the "()" operator. For any further questions you can contact me.
1158232
#include <iostream>\nusing namespace std;\n\nvoid main ()\n{\nint countDown= 0;\n\ncout <<"Enter the number you want to start from: ";\ncin >>countDown;\n\nfor ( countDown; countDown >= 0; countDown--)\n      cout <<countDown<<", ";\n}\n\nAny other question, just ask, eoroxter@gmail.com\nGood Luck,
983919
Here you go\nhttp://www.thefreecountry.com/compilers/cpp.shtml\n///
837959
for understanding c++ from the basics try this site\n\nwww.geocities.com/sstutor\n\ntrust me its the best c++  tutorial site on the net\n\nfor source codes check out these links..\n\nhttp://www.planet-source-code.com/vb/default.asp?lngWId=3#categories\nhttp://www.vyomworld.com/source/LanguageHome.asp?LangId=2\n\nhappy learning
333931
I don't think the error is in iostream.h it's an old library\nthat exist since the invention of c++, you probably have something wrong with ur code.. try to publish the error msg it might help
138457
Assuming this is in C, this is an impossible problem given the main program you provided, because you're passing in the parameters by value rather than by reference.  So any changes you make to those values inside the function will disappear once you return to the main context.\n\nIf you're allowed to change the main program to use pointers, you could do this:\n\nvoid sort2 (int *a, int *b) {\n  int tmp;\n\n  if (*a > *b) {\n   tmp = *a;\n   *a = *b;\n   *b = tmp;\n  }\n}\n\nGiven your main program, you'd call it like this:\n  sort2(&u, &v);\n\nBut it may be that this assignment was given to you specifically to demonstrate that you can't change the value of variables that you pass in by value).