Professional Documents
Culture Documents
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);