GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: Add Line Numbers


pointer stuff by merlin
int main() {
    char letters[5] = {'A','B','C','D','E'};
    char *charptr = &letters[0];

    for (int i = 0; i <= 4; ++i) {
        printf("CHAR: Element %i at %ph is %c\n", i, (charptr+i), *(charptr+i));
    }

    int numbers[5] = {2,4,6,8,10};
    int *intptr = &numbers[0];

    for (int i = 0; i <= 4; ++i) {
        printf("INT: Element %i at %ph is %i\n", i, (intptr+i), *(intptr+i));
    }

    double dblnumbers[5] = {500000.500, 400000.400, 300000.300, 200000.200, 100000.100};
    double *dblptr = &dblnumbers[0];

    for (int i = 0; i <= 4; ++i) {
        printf("DBL: Element %i at %ph is %d\n", i, (dblptr+i), *(dblptr+i));
    }

    system("pause");
}

output:

INT: Element 0 at 0012FEC4h is 2
INT: Element 1 at 0012FEC8h is 4
INT: Element 2 at 0012FECCh is 6
INT: Element 3 at 0012FED0h is 8
INT: Element 4 at 0012FED4h is 10
CHAR: Element 0 at 0012FE9Ch is A
CHAR: Element 1 at 0012FE9Dh is B
CHAR: Element 2 at 0012FE9Eh is C
CHAR: Element 3 at 0012FE9Fh is D
CHAR: Element 4 at 0012FEA0h is E
DBL: Element 0 at 0012FE54h is 0
DBL: Element 1 at 0012FE5Ch is -1717986918
DBL: Element 2 at 0012FE64h is 858993459
DBL: Element 3 at 0012FE6Ch is -1717986918
DBL: Element 4 at 0012FE74h is -1717986918
Press any key to continue . . .