[Tutorial] Beginner's Guide: Single/Two/Multi-dimensional Arrays
#9

Quote:
Originally Posted by Y_Less
View Post
Do you know what this code prints?

pawn Code:
#include <a_samp>

enum E_EG
{
    E_EG_NUM,
    E_EG_STR[10],
}

main()
{
    // Part 1.
    new eg[E_EG] = {42, "hi"};
    printf("1) %s %d", eg[E_EG_STR], sizeof (eg[E_EG_STR]));
    printf("2) %s %d", eg[E_EG_STR][0], sizeof (eg[E_EG_STR]));
    func(eg[E_EG_STR]);
    printf("3) %d", eg[E_EG:2]);
    printf("4) %d", eg[E_EG_STR + E_EG:1]);
    printf("5) %d", _:E_EG_STR);
    // Part 2.
    new eg2[10] = "hi";
    printf("6) %s %d", eg2[0], sizeof (eg2[]));
    func(eg2[0]);
    // Part 3.
    new eg3[10][E_EG];
    printf("7) %s", eg3[0][E_EG_STR]);
    func(eg3[5][E_EG_STR]);
}

func(data[], size = sizeof (data))
{
    printf("F) %s %d", data, size);
}
Sorry about ME answering your question, but wouldn't it return the ascii value of "i" (the second character in the string)? I'm just curious about that since I'm not very good at this.

EDIT: Oh, I see you've edited it. Let me see again.

pawn Code:
#include <a_samp>

enum E_EG
{
    E_EG_NUM,
    E_EG_STR[10] // There was an unneeded comma here, so I removed it
}

main()
{
    // Part 1.
    new eg[E_EG] = {42, "hi"}; // Assigns 42 to the E_EG_NUM var and "hi" to the E_EG_STR var
    printf("1) %s %d", eg[E_EG_STR], sizeof (eg[E_EG_STR])); // Prints the string itself, and the size of the string
    printf("2) %s %d", eg[E_EG_STR][0], sizeof (eg[E_EG_STR])); // Prints the string, starting from position 0 and the size
    func(eg[E_EG_STR]); // Prints the string, and the current size of the string
    printf("3) %d", eg[E_EG:2]); // Prints the ascii value of the second character
    printf("4) %d", eg[E_EG_STR + E_EG:1]); // Prints the same as above
    printf("5) %d", _:E_EG_STR); // No idea what this is though
    // Part 2.
    new eg2[10] = "hi"; // Creates a new char and assigns the value "hi" to it
    printf("6) %s %d", eg2[0], sizeof (eg2[])); // Does exactly what 2) does, but it gets the current size of the variable
    func(eg2[0]); // Does exactly what the previous F) does, but assigns the string to be gotten from a chosen position
    // Part 3.
    new eg3[10][E_EG]; // No idea what this does
    printf("7) %s", eg3[0][E_EG_STR]); // No idea what this does
    func(eg3[0][E_EG_STR]); // No idea what this does
}

func(data[], size = sizeof (data))
{
    printf("F) %s %d", data, size);
}
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)