| | |
Is this notation possible?
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
Hello ladies and gents,
There's an exercise, well, more a question that goes like this in Accelerated C++:
If the following code is legal, what can we infer about the return type of f?
What I can gather is that the return type will be a double variable, but, I don't know wether this way of writing is actually correct?
Ive tried to use it, but failed in getting anything to work with this kind of function.
Could someone tell me wether this is a legal piece of code.
Thanks.
There's an exercise, well, more a question that goes like this in Accelerated C++:
If the following code is legal, what can we infer about the return type of f?
C++ Syntax (Toggle Plain Text)
double d = f() [n];
What I can gather is that the return type will be a double variable, but, I don't know wether this way of writing is actually correct?
Ive tried to use it, but failed in getting anything to work with this kind of function.
Could someone tell me wether this is a legal piece of code.
Thanks.
•
•
•
•
Originally Posted by JoBe
If the following code is legal, what can we infer about the return type of f?
C++ Syntax (Toggle Plain Text)
double *f()
C++ Syntax (Toggle Plain Text)
#include <iostream> double *f() { static double value[] = {1,2,3,4,5}; return value; } int main ( void ) { int n = 2; double d = f() [n]; std::cout << "d = " << d << '\n'; return 0; } /* my output d = 3 */
"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
![]() |
Similar Threads
- O-notation (Computer Science)
- Help! C program w/Pointer Notation to Convert Text (C)
- Help with Big-O notation (C++)
- Big -Theta notation (Computer Science)
- O notation (C)
- O-notation (C++)
- Big-theta notation question. (Computer Science)
Other Threads in the C++ Forum
- Previous Thread: assigning a string from a file to a variable
- Next Thread: string: get token from string and compare token from text file
| Thread Tools | Search this Thread |
add api application array arrays beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion convert count data database delete desktop developer directshow dll email encryption error file forms fstream function functions game generator getline graph homeworkhelper iamthwee ifstream image input int integer java lib linux loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive return sorting string strings struct studio template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






It couldn't have been a double.