Attention on-line class: This is just a sample exam. The final for on-line class will be
May 8, 1999 @ 2:00 p.m. in room 207. Study loops, arrays, pointers, files, redirection, and command-line
Arguments, etc.
UNIVERSITY OF HOUSTON
COLLEGE OF TECHNOLOGY
ELET 2300
Sample exam
I. For the following questions, answer "true" or "false" (please DO NOT write "T" or "F").(26 pts)
____ 1. The expression array[4][2] references the fourth row, second
Column of a two dimensional array.
____ 2. You cannot return more than one value at one time from a
function.
____ 3. In order to guarantee a function goes back to the function that calls it, you must have a key word return at the end of
your function.
____ 4. The declaration of char string[4]={'H','W','#','4'} is valid
and creates a string equivalent to "HI".
____ 5. By default all elements of an array is initialized to zero
or null.
____ 6. Function prototyping is not required as long as you have only
2 functions or less.
____ 7. C warns you when an array subscript exceeds the size of the
array declared in the declaration segment.
____ 8. The notation *(*(A+3))+2 is the same as A[3][2].
____ 9. Passing variables to a function by using pointer creates an
exact new copy of the variables being passed.
____10. If A is declared as double A, the only way you can pass to a
function called f1(int *C) is by using notation f1(&(int)A).
____11. Macro generates more codes but executes slower.
____12. Function prototyping is used by the compiler for checking
during the linking time.
____13. Only one file can be redirected at a given time.
II. Identify the cause of the error(s) and write the correct form.(18 pts)
1) #include <stdio.h>
void main (void)
{
char ch;
getchar(ch);
printf("\nit is :%c", ch);
fflush(stdin);
gets(ch);
printf("\nIt is :%s", ch);
}
2) #include <stdio.h>
void main(void)
{
char ch;
int lc=vc=0;
while (ch=getchar()!='\n')
{
if (ch>='a' && ch<='z')
lc++;
else if(!(ch < 'A')|| !(ch> 'Z')
vc ++;
printf(%d lowercase, %d uppercase, lc,uc);
}
}
3) #include <stdio.h>
void f1(int*, int*);
void main (void)
{ int A, *B;
int b=5;
B = b;
f1(A, B);
printf("The value of A is:%d", A);
}
void f1(int *A, int *B)
{
A = 5 + *B;
}
III. Trace and find for output of the following program. (Assume you have included all necessary header files).(19 pts)
1) #include <stdio.h>
#define ODD 7
#define EVEN 2
#define OTHR 3
#define MAX 15
#define MIN 4
void main (void)
{
int index;
for(index=0; index<20; index++) {
switch(index) {
case MIN: if(index%4 == 0)
printf("No remainder\n");
else
printf("%d is not divisible\n", index);
break;
case MAX: if(index = 20)
printf("done\n");
else
printf("continue\n");
break;
case ODD: printf("index = %d\n", index);
break;
case EVEN: printf("index = %d\n", index);
case OTHR: printf("other value is : %d\n", index+1);
break;
}
}
}
2) #include <stdio.h>
void main (void)
{ int A;
int b = 5;
int *B;
B = &b;
for (A=0; A<10; A++);
{ b++;
A = *B + A;
printf("Value of A: %d, value of *B: %d\n", A, *B);
}
}
3) #include <stdio.h>
void main (void)
{
int A;
for (A=0; ++A<=5; A++)
{
if (A<5)
printf("\n@@@value of A %d", A);
if (A=5)
printf("\n***value of A %d", A);
if (A>5)
printf("\n$$$value of A %d", A);
}
printf("\n&&&value of A %d", A);
}
IV Answer the following questions.(8 pts)
Find the numerical value of each of the following expressions.
value
(a) !'A' && !'B' _______
(b) 0||3 && !'A'||'A' _______
(c) 3>4*3 <= 2/3 && 3/2 _______
(d) 'E'<'F' || 'B'&&'C' _______
V Write a complete program to display the following format.(You need to use loop structure).(12 pts)
A
AB
ABC
ABCD
ABCDE
V. Please READ CAREFULLY the following problem. Please use the attached sheet.(15 pts)
Write a complete C program to solve the following problem.
Prompt the user to enter how many names he has. From this number, set a loop to read all the names. Once you have these names, you need to call and define a user define function which has a prototype as follow:
reverse_name(char **names, int *item);
It is in this function you need to print all names in reverse (first name entered becomes last one to be printed, and vice versa)
Remember: you must use pointer throughout this program. The only array notation you can use is for the arrays declaration.