You are on page 1of 13

Activity 6:

/* Activity 6 */

#include <stdio.h>
int main ()
{
int Nike1;
char Nike2[10];
printf("Address of nike variable: %x\n", &Nike1 );
printf("Address of converse variable: %x\n", &Nike2);
return 0;
}
Activity 7:

/* Activity 7 */

#include <stdio.h>
int main ()
{
int nike = 20; /* actual variable declaration */
int *fila; /* pointer variable declaration */
fila = &nike; /* store address of nike in pointer variable*/
printf("Address of nike variable: %x\n", &nike );
/* address stored in pointer variable */
printf("Address stored in fila variable: %x\n", fila );
/* access the value using the pointer */
printf("Value of *fila variable: %d\n", *fila );
return 0;
}
Activity 8:

/* Activity 8 */

#include <stdio.h>
int main ()
{
int *nike = NULL;
printf("The value of nike is : %x\n", &nike );
return 0;
}
Activity 9:

/* Activity 9 */

#include <stdio.h>
const int JULIE = 3;
int main ()
{
int nike[] = {10, 100, 200};
int fila, *converse;
/* let us have array address in pointer */
converse = nike;
for ( fila = 0; fila < JULIE; fila++)
{
printf("Address of nike[%d] = %x\n", fila, converse );
printf("Value of nike[%d] = %d\n", fila, *converse );
/* move to the next location */
converse++;
}
return 0;
}
Activity 10:

/* Activity 10 */

#include <stdio.h>
const int JULIE = 3;
int main ()
{
int nike[] = {10, 100, 200};
int fila, *converse;
/* let us have array address in pointer */
converse = &nike[JULIE-1];
for ( fila = JULIE; fila > 0; fila--)
{
printf("Address of nike[%d] = %x\n", fila, converse );
printf("Value of nike[%d] = %d\n", fila, *converse );
/* move to the previous location */
converse--;
}
return 0;
}
Activity 11:

/* Activity 11 */

#include <stdio.h>
const int JULIE = 3;
int main ()
{
int nike[] = {10, 100, 200};
int fila, *converse;
/* let us have address of the first element in pointer */
converse = nike;
fila = 0;
while ( converse <= &nike[JULIE - 1] )
{
printf("Address of nike[%d] = %x\n", fila, converse );
printf("Value of nike[%d] = %d\n", fila, *converse );
/* point to the previous location */
converse++;
fila++;
}
return 0;
}
Activity 12:

/* Activity 12 */

#include <stdio.h>
const int JULIE = 3;
int main ()
{
int nike[] = {10, 100, 200};
int fila;
for (fila = 0; fila < JULIE; fila++)
{
printf("Value of nike[%d] = %d\n", fila, nike[fila] );
}
return 0;
}
Activity 13:

/* Activity 13 */

#include <stdio.h>
const int JULIE = 3;
int main ()
{
int nike[] = {10, 100, 200};
int fila, *converse[JULIE];
for ( fila = 0; fila < JULIE; fila++)
{
converse[fila] = &nike[fila]; /* assign the address of integer. */
}
for ( fila = 0; fila < JULIE; fila++)
{
printf("Value of nike[%d] = %d\n", fila, *converse[fila] );
}
return 0;
}
Activity 14:

/* Activity 14 */

#include <stdio.h>
const int JULIE = 4;
int main ()
{
char *names[] = {
"Julie Ann Inciong",
"Ivy Sancha",
"Reymark Perez",
"Jim Floyd Sallan",
};
int fila = 0;
for ( fila = 0; fila < JULIE; fila++)
{
printf("Value of names[%d] = %s\n", fila, names[fila] );
}
return 0;
}
Activity 15:

/* Activity 15 */

#include <stdio.h>
int main ()
{
int nike;
int *converse;
int **gucci;
nike = 3000;
/* take the address of nike */
converse = &nike;
/* take the address of ptr using address of operator & */
gucci = &converse;
/* take the value using gucci */
printf("Value of nike = %d\n", nike );
printf("Value available at *converse = %d\n", *converse );
printf("Value available at **gucci = %d\n", **gucci);
return 0;
}
Activity 16:

/* Activity 16 */

#include <stdio.h>
#include <time.h>
void getSeconds(unsigned long *nike);
int main ()
{
unsigned long sec;
getSeconds( &sec );
/* print the actual value */
printf("Number of seconds: %ld\n", sec );
return 0;
}
void getSeconds(unsigned long *nike)
{
/* get the current number of seconds */
*nike = time( NULL );
return;
}
Activity 17:

/* Activity 17 */

#include <stdio.h>
/* function declaration */
double getAverage(int *nike, int gucci);
int main ()
{
/* an int array with 5 elements */
int balance[5] = {1000, 2, 3, 17, 50};
double avg;
/* pass pointer to the array as an argument */
avg = getAverage( balance, 5 ) ;
/* output the returned value */
printf("Average value is: %f\n", avg );
return 0;
}
double getAverage(int *nike, int gucci)
{
int fila, sum = 0;
double avg;
for (fila = 0; fila < gucci; ++fila)
{
sum += nike[fila];
}
avg = (double)sum / gucci;
return avg;
}
Activity 18:

/* Activity 18 */

#include <stdio.h>
#include <time.h>
/* function to generate and retrun random numbers. */
int * getRandom( )
{
static int nike[10];
int fila;
/* set the seed */
srand( (unsigned)time( NULL ) );
for ( fila = 0; fila < 10; ++fila)
{
nike[fila] = rand();
printf("%d\n", nike[fila] );
}
return nike;
}
/* main function to call above defined function */
int main ()
{
/* a pointer to an int */
int *p;
int fila;
p = getRandom();
for ( fila = 0; fila < 10; fila++ )
{
printf("*(p + [%d]) : %d\n", fila, *(p + fila) );
}
return 0;
}

You might also like