Here's an example of the sort of questions I have asked in the past.
char *x(char *s, char c)
{
char *r = NULL;
do{
while(*s && *s != c) s++;
if (*s) r = s;
} while(*s++);
return(r);
}
char a[27] = "abcdefghijklmnopqrstuvwxyz"; char *b = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char c;Here, the array a begins at memory address 0x1010, the variable b is at address 0x3040, and c is at address 0x4050. Treating each of the following independently (that is, at the beginning of each, the variables are as shown above), and remembering that "illegal assignment" is a valid response, what is ...
Now consider function calls. In a program, we have:
reverse(a);(where a is as above) and later on, we have defined
void reverse(char s[]){ ... }
Assume in the following that reverse does in fact reverse the
contents of the array s.
struct node {
char letter;
struct node *next;
} a, b, c, *ptr;
a.letter = 'A';
b.letter = 'B';
c.letter = 'C';
a.next = &b;
b.next = &c;
c.next = NULL;
ptr = a.next;
while (ptr != NULL) {
printf("%c\n", ptr->letter);
ptr = ptr -> next;
}
void a_again(int acount)
{
++acount;
}
void main(void)
[
register int c;
int counter = 0;
while((c = getchar()) != EOF)
if (c == 'a' || c == 'A')
a_again(counter);
printf("%d\n", counter);
exit(0);
}
int dot(int a[], int b[], int n)
void f(int a, int b)
{
printf("%d %d\n", a, b);
}
main()
{
int i = 5;
f(++i, ++i);
}
for(x = i = 0; i <= 100; i += 2, x += i);
x = i = 0; while( i++ == 100) x += ++i;
for(x = i = 0; i <= 100; i++){
if (!(i % 2))
continue;
x = x + i;
}
x(char *s, char *t)
{
for( ; *s == *t; s++, t++)
if (*s == '\0')
return(0);
return(*s - *t);
}
char c;
char *buf, *p, *q;
p = buf = malloc(sizeof(char) * 100);
while ((c = getchar()) != EOF && c != '\n')
*p++ = tolower(c);
*p = '\0';
printf("first half of string is: ");
for(q = buf; q < (buf + p) / 2; q++)
putchar(*q);
putchar('\n');
Send email to
cs40@csif.cs.ucdavis.edu.
Department of Computer Science
University of California at Davis
Davis, CA 95616-8562