| | |
Quick Question!
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2007
Posts: 15
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
_ _ _ _ function2(_ _ _ _ _ _ _ _ _ _ _ ); main{ int n[]= {4, 5, 6}; int *kptr ; kptr = function2( n ) ; }
Fill in the blanks and you get:
C++ Syntax (Toggle Plain Text)
int *function2( int array[ ]); or int *function2( int *ptr ); /* parameters names can be omitted */ main{ int n[]= {4, 5, 6}; int *kptr ; kptr = function2( n ) ; }
Can you please tell me why its 'int *' in the function prototype, shudnt it be just 'void'? since its not returning anything? Or shudnt it just be 'int' excluding the '*', ?
Last edited by warpstar; Oct 25th, 2007 at 3:06 pm.
How do you know it doesn't return anything? All you know (or at least have shown us), are the prototypes. I assume it assigns a value to the int pointer 'kptr' and because its type is an int star assignment from a function must return an int star.
Also, I assume this is an assignment? Hmm. Main returns an integer so 'int main()' with a 'return 0;' at the end of its scope is what you should be having. Was the 'blanked' code given by the teacher...
Also, I assume this is an assignment? Hmm. Main returns an integer so 'int main()' with a 'return 0;' at the end of its scope is what you should be having. Was the 'blanked' code given by the teacher...
•
•
Join Date: Oct 2007
Posts: 15
Reputation:
Solved Threads: 0
Thats a question taken from a sample midterm test, so that is what i assuming all you need to know to answer the question. I still dont really understand why the star is beside int in the function prototype.
. Anyways thanks fr the reply.
. Anyways thanks fr the reply.•
•
•
•
How do you know it doesn't return anything? All you know (or at least have shown us), are the prototypes. I assume it assigns a value to the int pointer 'kptr' and because its type is an int star assignment from a function must return an int star.
Also, I assume this is an assignment? Hmm. Main returns an integer so 'int main()' with a 'return 0;' at the end of its scope is what you should be having. Was the 'blanked' code given by the teacher...
>since its not returning anything?
I don't understand. It's clearly returning something because the code that calls the function uses the return value:
You can't use a function like that unless it returns something, and because kptr is declared as a pointer to int, it's a safe bet that function2 should return a pointer to int. The star means it's a pointer.
I don't understand. It's clearly returning something because the code that calls the function uses the return value:
c Syntax (Toggle Plain Text)
kptr = function2( n ) ;
•
•
•
•
C++ Syntax (Toggle Plain Text)
_ _ _ _ function2(_ _ _ _ _ _ _ _ _ _ _ ); main{ int n[]= {4, 5, 6}; int *kptr ; kptr = function2( n ) ; }
Fill in the blanks and you get:
C++ Syntax (Toggle Plain Text)
int *function2( int array[ ]); or int *function2( int *ptr ); /* parameters names can be omitted */ main{ int n[]= {4, 5, 6}; int *kptr ; kptr = function2( n ) ; }
Can you please tell me why its 'int *' in the function prototype, shudnt it be just 'void'? since its not returning anything? Or shudnt it just be 'int' excluding the '*', ?
kptr = function2( n ) ;isn't it? And doesn't it load the value into kptr which is an
int *? The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
![]() |
Similar Threads
- A quick question about "rank" (DaniWeb Community Feedback)
- Quick Question: Is J# the same thing as Java? (Java)
- Quick HijackThis question (Viruses, Spyware and other Nasties)
- A quick question (Game Development)
- quick question (C++)
- quick question (Geeks' Lounge)
- Question about 321Studios (Windows Software)
- AGP support video card question (Monitors, Displays and Video Cards)
- Quick question (Troubleshooting Dead Machines)
- Laptop LCD built into a car? (Monitors, Displays and Video Cards)
Other Threads in the C++ Forum
- Previous Thread: c++beginner I/0 issue
- Next Thread: I'm back...More problems, different program
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library linker list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






