## Some example questions for the PHYS2020 mid-session exam

```Give concise explanations of what these mean:

'\n'
"\n"
"\\n"

What are the values of i, j, and k after the following statements:

int i = 49/100;
int j = 51/100;
int k = 51/100.0;

How many times will "statement" be executed in this loop:

int i;
for (i = 1; i > -1; i--) {
statement;
}

int i;
for (i = 1; i > -1, --i) {
statement;
}

And this one?

int i;
for (i = 0; i++; i < 10) {
statement;
}

And this one?

unsigned char i;
for (i = 0; i < 256; i++) {
statement;
}

Why does the following produce a compiler error message?

char out[2]="ab";

What output would you expect from the following program fragment, and
why?

int i = 0xf4;
int j = 0x40;
printf ("%x %x %x %x %x %x %x %x\n", i & j, i && j, i | j, i || j,
i < 1, i << 1, j > 1, j >> 1);

How can the following lead to program failure?

char input[80];
scanf("%s", char);

What is the final value of i after the following statements?

int i = 1;

i *= 2;
++i;
i &= 3;

What is wrong with this?

double trouble[] = {1.0, 2.0, 3.0};
double sum = 0.0;

for (i = 1; i < 3; i++) {
sum += trouble[i];
}

Write an integer function that returns 1 if its integer argument is
odd, 0 otherwise.

Write a function that adds two double arrays together, element by element,
and returns the result in the first array. (e.g., if "a" and "b" are
the two arrays, and "nelm" is the number of elements in each, then the function
should do something like "a[0] += b[0];" for each element).
```