#include <stdio.h>
int main(int argc, char *argv[]) {
double *p;
int *q;
double r;
int y[3][3];
int x[10];
int i,j;
r = 10.0;
p = &r;
*p = 5.0;
printf("Value of r changed to = %f\n",r);
for(i=0;i<10;i++){
x[i] = 2 * (i+1);
}
q = x;
printf("First element in x = %d\n",*q);
printf("4th element in x = %d\n",*(q+3));
printf("4th element of x = %d\n",q[3]);
p = (double *)malloc(sizeof(double)*5);
printf("Values in p: %f %f %f %f %f\n",p[0],p[1],p[2],p[3],p[4]);
q = (int *)malloc(sizeof(int)*10);
q = &(x[1]);
printf("q is shifted by one as you can see:\n");
printf("q's = %d %d %d %d ...\n",q[0],q[1],q[2],q[3]);
printf("x's = %d %d %d %d ...\n",x[0],x[1],x[2],x[3]);
q = x;
printf("q and x are the same: %d = %d , %d = %d \n",q[9],x[9], q[5],x[5]);
for(i=0;i<3;i++) {
for (j=0;j<3;j++){
y[i][j] = 10*(i+1) + j + 1;
}
}
for(i=0;i<3;i++){
printf("y[%d][1],y[%d][2],y[%d][3] = %d %d %d\n",i,i,i,y[i][0], y[i][1], y[i][2]);
}
printf("Y's are stored as:\n");
for(i=0;i<3;i++) {
for (j=0;j<3;j++){
printf(" %d ",*(*(y+j)+i));
}
}
printf("\n");
char *str;
str=(char *)malloc(sizeof(char)*10);
printf("Enter an string:\n");
scanf("%s",str);
printf("You entered: [%s]\n",str);
str="Hi! ";
printf("str changed to: [%s]\n",str);
}