You are on page 1of 3

School of Computing/Technology/Engineering

Module Name : Intro. to Computer Programming


Tutorial :5

1. Write a single statement for each of the indicated tasks.


(a) Declare two floating-point variables number1 and number2, and initialize number1 to 7.3.
(b) Declare the variable fPtr to be a pointer to an object of type float.
(c) Assign the address of variable number1 to pointer variable fPtr.
(d) Print the value of the object pointed to by fPtr.
(e) Assign the value of the object pointed to by fPtr to variable number2.
(f) Print the value of number2.
(g) Print the address of number1. Use the %p conversion specifier.
(h) Print the address stored in fPtr. Use the %p conversion specifier. Is the value printed the same
as the address of number1?
(i) Declare a constant pointer cPtr and initialize the pointer with the address of variable
number2. What will be constant?

2. A C program contains the following declaration.


static int x[8] = { 10, 20, 30, 40, 50, 60, 70, 80};

(a) What is the meaning of x?


(b) What is the meaning of (x + 2)?
(c) What is the value of *x?
(d) What is the value of (*x + 2)?
(e) What is the value of *(x + 2)?

1
3.
(a) What does this program do?
#include <stdio.h>
void mystery1(char *, const char *);
int main()
{
char string1[80], string2[80];
printf("Enter two strings: ");
scanf("%s%s", string1, string2);
mystery1(string1, string2);
printf("%s\n", string1);
return 0;
}
void mystery1(char *s1, const char *s2)
{
while (*s1 != '\0')
++s1;
for ( ; (*s1 = *s2) != '\0'; s1++, s2++)
; /* empty statement */
}

2
4. Find the error in each of the following program segments. If the error can be corrected, explain
how.
(a)
int * x, y;
x = y;
(b)
float x = 19.34;
float xPtr = &x;
printf("%f\n", xPtr);

(c)
float *realPtr;
long *integerPtr;
integerPtr = realPtr;
(d)
char s[ ] = "this is a character array";
int count;
for ( ; *s != '\0' ; s++)
printf("%c ", *s);

You might also like