// file: lecture_12/example.cc // // local include files // #include "example.h" // method: main // // main program starts here // int main(int argc, char** argv) { // declare a character string // char str[] = "Alex"; fprintf(stdout, "str = %s\n", str); fprintf(stdout, "str[0] = %c (%d)\n", str[0], str[0]); fprintf(stdout, "str[1] = %c (%d)\n", str[1], str[1]); fprintf(stdout, "str[2] = %c (%d)\n", str[2], str[2]); fprintf(stdout, "str[3] = %c (%d)\n", str[3], str[3]); long N = 3; float x[N]; x[0] = 1.0; x[1] = 2.0; x[2] = 3.0; // float x[] = {1, 2, 3}; fprintf(stdout, "x[0] = %f (%f)\n", x[0], x[0]); fprintf(stdout, "x[1] = %f (%f)\n", x[1], x[1]); fprintf(stdout, "x[2] = %f (%f)\n", x[2], x[2]); // fprintf(stdout, "x[3] = %f (%f)\n", x[3], x[3]); float z[2][9][27][99][35]; z[0][0][0][0][0] = 0.0; z[0][0][0][0][1] = 27.0; z[0][0][0][0][34] = 99.0; fprintf(stdout, "---- pointers ----\n"); float joe = 27.0; float* ptr = &joe; fprintf(stdout, "joe = %f\n", joe); fprintf(stdout, "the memory location for joe is %p (%u)\n", ptr, ptr); fprintf(stdout, "*joe = %f\n", *ptr); *ptr = (float)35.0; fprintf(stdout, "*joe = %f\n", *ptr); // fprintf(stdout, "joe = %f\n", joe); float* y = (float*)z; fprintf(stdout, "y[0] = %f\n", y[0]); fprintf(stdout, "y[1] = %f\n", y[1]); fprintf(stdout, "y[34] = %f\n", y[34]); x[0] = y[3] * (z[0][0][0][0][1]); // x[0] = y[3] * (z[1]); /* float* zzz = x; fprintf(stdout, "x[0] = %f (%f)\n", *zzz, x[0]); fprintf(stdout, "x[1] = %f (%f)\n", *(zzz+1), x[1]); fprintf(stdout, "x[2] = %f (%f)\n", *(zzz+2), x[2]); char* mystr = ((char*)z) + 1; fprintf(stdout, "z[0] second byte is %u (%c)\n", *mystr, *mystr); // void* huh = (void*)z; */ /* float* ppp = zzz; fprintf(stdout, "x[0] = %f (%f)\n", *ppp, x[0]); ppp++; fprintf(stdout, "x[1] = %f (%f)\n", *ppp, x[1]); ppp++; fprintf(stdout, "x[2] = %f (%f)\n", *ppp, x[2]); */ fprintf(stdout, "=====\n"); fprintf(stdout, "argv = %u\n", argv); fprintf(stdout, "argv[0] = %s (%u)\n", argv[0], argv[0]); fprintf(stdout, "argv[1] = %s (%u)\n", argv[1], argv[1]); fprintf(stdout, "argv[2] = %s (%u)\n", argv[2], argv[2]); fprintf(stdout, "=====\n"); fprintf(stdout, "argv[0] = %s\n", argv[0]); fprintf(stdout, "argv[0][0] = %c\n", argv[0][0]); fprintf(stdout, "argv[0][1] = %c\n", argv[0][1]); double sum; double *sum; double* mysum = ∑ /* float* bob; long M = atoi(argv[1]); bob = new float[M]; bob[0] = 35.0; bob[1] = 99.0; fprintf(stdout, "bob[1] = (%u) %f\n", &bob[1], bob[1]); bool status = myfunct(bob, M); */ // exit gracefully // exit(0); } /* bool myfunct(float* x, long M) { fprintf(stdout, "...%f (%d)\n", x[0], M); return true; } */