•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,575 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,588 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 411 | Replies: 5
![]() |
•
•
Join Date: Oct 2007
Posts: 15
Reputation:
Rep Power: 2
Solved Threads: 0
_ _ _ _ function2(_ _ _ _ _ _ _ _ _ _ _ );
main{
int n[]= {4, 5, 6};
int *kptr ;
kptr = function2( n ) ;
} Fill in the blanks and you get:
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:
Rep Power: 2
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 ) ;
•
•
•
•
_ _ _ _ function2(_ _ _ _ _ _ _ _ _ _ _ ); main{ int n[]= {4, 5, 6}; int *kptr ; kptr = function2( n ) ; }
Fill in the blanks and you get:
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 '*', ?
It isn't returning anything? Calling the function is accomplished by
kptr = function2( n ) ;isn't it? And doesn't it load the value into kptr which is an
int *? Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
-- Pearl Williams
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
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: xor linked list



Linear Mode