| | |
C++
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2006
Posts: 9
Reputation:
Solved Threads: 0
Hi
I am new to c++ and I have a simple program that I am trying to understand .Here is the program If anyone can put some comments to what the codes mean I would be grateful.//Explain Please what these lines mean.
I am new to c++ and I have a simple program that I am trying to understand .Here is the program If anyone can put some comments to what the codes mean I would be grateful.//Explain Please what these lines mean.
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int sum(int[],int);// int main() { int a[]={11,33,55,77};// int size=sizeof (a)/sizeof(int);// cout << "sum(a,size)="<<sum(a,size)<<endl; } int sum(int a[],int n)// { int sum=0; for (int i=0;i<n;i++) sum+=a[i]; int Avg= sum/4; cout<<"Avg="<<Avg<<endl; return sum; }
Last edited by Dave Sinkula; Aug 9th, 2006 at 12:23 am. Reason: Added [code][/code] tags -- learn to use them yourself.
•
•
•
•
Originally Posted by Sashar400
Explain Please what these lines mean.
But...
#include <iostream> using namespace std; int sum(int[],int);// (1) function declaration or prototype int main() { int a[]={11,33,55,77};// (2) initialization of an array int size=sizeof (a)/sizeof(int);// (3) initialize size with number of elements in a cout << "sum(a,size)="<<sum(a,size)<<endl; } int sum(int a[],int n)// (4) function definition { int sum=0; for ( int i=0;i<n;i++ ) sum+=a[i]; int Avg= sum/4; cout<<"Avg="<<Avg<<endl; return sum; }
- This says, this function will exist and this is how it should be used.
- The size of the array is left to the compiler to figure out based on the number of elements initializing it.
- The number of elements in an array is equal to the total size divided by the size of the first member.
- The definition of the function: "the meat".
Last edited by Dave Sinkula; Aug 9th, 2006 at 12:31 am.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Other Threads in the C++ Forum
- Previous Thread: Choice of DataStructure
- Next Thread: Data From C++ GUI to Excel/Notepad, Application Trouble
| Thread Tools | Search this Thread |
api array arrays based binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






