These are sample questions that are very similar to the ones I will ask on the midterm.
#define max(x, y) ((x) > (y) ? (x) : (y))and here is a function:
int max(int a, int b) { return(a > b ? a : b); }In the following code fragment, give the values of a, b, c, d, and e at the end if max is the above macro, and then if max is a function call:
a = -1; b = 0; c = 1; d = max(++a, b); e = max(c++, b);
variable | value if max is macro | value if max is a function |
---|---|---|
a | ||
b | ||
c | ||
d | ||
e |
#include
int main(int argc, char *argv[])
{
int sum = 0;
int i;
for(i = 1; i < argc; i++)
sum += argv[i];
printf("%d\n", sum);
return(0);
}
sum 1 2 3What are the values of argc and the elements of argv? Draw a picture if that would help you indicate what the values are. Please note I want the value of argc, argv, and each element of argv, and so forth, either as a number or character, or as arrows in a picture (for addresses).
int mystery(char a[])
{
register int i;
for(i = 0; a[i]; i++)
if (!isdigit(a[i]))
return(0);
return(1);
}
tr A-Z a-z < /usr/share/dict/words > /tmp/X
grep '^bananna$' /tmp/X > /tmp/Y
wc -l /tmp/Y
char charray[] = "A-DF123";
int n, s = 1;
char *p;
for(n = 0, p = charray; *p; p++){
switch(*p){
case '-':
s = -s;
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
n = n * 10 + (*p - '0');
break;
}
}
n = s * n;
|
ECS 36A, Programming and Problem Solving Version of December 1, 2019 at 11:09PM
|
You can also obtain a PDF version of this. |