List of all available Websheets
Viewing cpp/pointers/cmdargs_ptr_ex2 by redekopp@usc.edu. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
Property | Value |
---|---|
Description html markup shown to student | Predict what will be output if the program is run as: <pre><b>$</b> ./cmdargs_ptr_ex part2: return of the cmd line args</pre> |
Public permissions | |
Remarks Comments, history, license, etc. | Copied from problem cpp/pointers/cmdargs_ptr_ex (author: redekopp@usc.edu) Copied from problem cpp/pointers/hello (author: daveagp@gmail.com) |
Engine | |
Template / Reference solution |
using namespace std; // main should accept command-line arguments int main(int argc, char* argv[]) { \[ // Predict the kind of thing that will print // a.) a string b.) an address c.) a single char cout << "argv = " << argv << endl; cout << "&argv[1] = " << &argv[1] << endl; cout << "*(argv+2) = " << *(argv+2) << endl; cout << "*argv[4] = " << *argv[4] << endl; // Determine what will be printed by the following lines cout << "argc = " << argc << endl; cout << "&argv[2][3] = " << &argv[2][3] << endl; cout << "(*(argv+1))[4] = " << (*(argv+1))[4] << endl; cout << "*(*(argv+1)+2) = " << *(*(argv+1)+2) << endl; \show: // Predict the kind of thing that will print // a.) a string b.) an address c.) a single char cout << "argv = " << argv << endl; cout << "&argv[1] = " << &argv[1] << endl; cout << "*(argv+2) = " << *(argv+2) << endl; cout << "*argv[4] = " << *argv[4] << endl; // Determine what will be printed by the following lines cout << "argc = " << argc << endl; cout << "&argv[2][3] = " << &argv[2][3] << endl; cout << "(*(argv+1))[4] = " << (*(argv+1))[4] << endl; cout << "*(*(argv+1)+2) = " << *(*(argv+1)+2) << endl; ]\ return 0; } |
C++ test suite json list of stdin/args tests e.g. [{"stdin":"hi", "args":["4", "5"]}, {"stdin":"noargs"}] to just run once with no input use [{}] | [ {"args": ["part2:", "return", "of", "the","cmd","line","args"]} ] |
Solution visibility | |
Is example? i.e., just a demo |
Note: problems are open-source by default (see 'Public permissions'). Assumed license for open problems is Creative Commons 4.0 Attribution-ShareAlike unless specified in 'Remarks'.