0% found this document useful (0 votes)
26 views

Lab Exercise 8 (Part 1)

The document provides instructions for 4 programming exercises: 1. Write a program to print the addresses of two variables. 2. Write a program to print the values of an array using a pointer and the array name directly. Changing the loop condition from <5 to <6 will result in a runtime error. 3. Write a program using a pointer to test if elements in an integer array are odd or even. 4. Write a function that removes leading blanks from a sentence using a pointer. Test it using the string "All the best in your exam".

Uploaded by

Nia Afiqah
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Lab Exercise 8 (Part 1)

The document provides instructions for 4 programming exercises: 1. Write a program to print the addresses of two variables. 2. Write a program to print the values of an array using a pointer and the array name directly. Changing the loop condition from <5 to <6 will result in a runtime error. 3. Write a program using a pointer to test if elements in an integer array are odd or even. 4. Write a function that removes leading blanks from a sentence using a pointer. Test it using the string "All the best in your exam".

Uploaded by

Nia Afiqah
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Lab exercise 8

1. Write the following declarations in your programs:


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

State your output

2. Write the following declarations in your programs:

#include <stdio.h>

int main ()
{
/* an array with 5 elements */
double balance[5] = {1000.0, 2.0, 3.4, 17.0, 50.0};
double *p;
int i;

p = balance;

/* output each array element's value */


printf( "Array values using pointer\n");
for ( i = 0; i < 5; i++ )
{
printf("*(p + %d) : %f\n", i, *(p + i) );
}
printf( "Array values using balance as address\n");
for ( i = 0; i < 5; i++ )
{
printf("*(balance + %d) : %f\n", i, *(balance + i) );
}
return 0;
}

State your output

Change
for ( i = 0; i < 5; i++ )
is your observation.?

to

for ( i = 0; i < 6; i++ )..Compile. What

3. Write a program using array pointer (example in 2) to test if the array


number contains odd or even number
2

Int num[6]={ 4 ,5 ,6 ,7 ,8 ,9 }
Your program have to display as following for every element in the array:
Index
:0
Number :4
Even number

4. Write a function named trimfrnt() that deletes all leading blanks from a
sentence. Write the function using pointer. Test your function using the
string All the best in your exam
(Hint :string is an array of characters)

You might also like