Thread: Seeking some clarifications on these codes.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    102

    Seeking some clarifications on these codes.

    I have the following three short codes with their outputs. I am seeking clarifications as to how the output was come to. Any explanations are welcome. Thanks in advance.

    Code:
    include <iostream>
    using namespace std;
    int main()
    {
    char str[] = "ABKALM!OV";
    for (int m=1; str[m]; m=m+2)
    cout << str[m];
    return 0;
    
    }
    Output: BAMO
    Code:
    include <iostream>
    using namespace std;
    int main()
    {
    int arr[] = {1,2,3,4,5};
    for (int m=4; m; m=m-1)
    arr[m] = arr[m-1] + m;
    for (int m=0; m<5; m=m+1)
    cout << arr[m];
    
    }
    Output: 12468

    Code:
    include <iostream>
    using namespace std;
    int main()
    {
    char arr[]="UND";
    try {
    for (int m=0; arr[m]; m=m+1) {
    cout << arr[m];
    if (arr[m]=='N')
    throw 3;
    cout << arr[m+2];
    }
    }
    catch (…) {
    cout << "HOPPLA";
    }
    cout << arr;
    return 0;
    }
    Output: UDNHOPPLAUND
    Last edited by Dontgiveup; 04-02-2009 at 05:31 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. NewEgg Promo Code(s)
    By golfinguy4 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 05-15-2006, 08:16 PM
  2. Escape Codes
    By renurv in forum C++ Programming
    Replies: 2
    Last Post: 01-01-2006, 02:01 PM
  3. codes
    By IfYouSaySo in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 11-18-2005, 03:09 PM
  4. action replay codes
    By c++.prog.newbie in forum Game Programming
    Replies: 2
    Last Post: 02-28-2004, 08:47 AM