My CSC60 final (well, last semester's final). I have the answers, I may post them later if anyone actually attempts the test 
If you're hte guy who said "C is easy if you know C++ and you can learn gcc and make in jsut a minute" I'd love to see you take the test.
I'm going to fail, my final is in an hour.
CSC60 TEST #2
1) Your C program is in program.c. Write a C compiler
command to create an executable file called
program.
2) Write a C preprocessor directive to include (inside
your C program) a header file containing
function prototypes for the functions from the
standard mathematical library.
3) Assume that your program.c uses some of the
functions from the standard mathematical library.
Write a C compiler command to compile program.c.
4) Assume that you have a line #include ?calc.h? in
your program.c. Also assume that calc.h is in the
subdirectory my_include. Write a C compiler command to
compile program.c.
5) Assume that your file stack.c contain functions
that you would like to keep in a static library. Write
commands that will create such a library.
6) Assume you place your library libsafec.a in a
subdirectory my_lib. Write a command line to compile
your program.c that uses functions from that library.
7) You would like to place functions from safecalls.c
in a dynamic shared objects library. Show a
command needed to create an object file safecalls.o
that can be placed in the shared objects library.
8) Assume you have created safecalls.o and
safecalls2.o in a way suitable for being incorporated
in a
dynamic shared objects library. Write a command line
to create a shared objects library
libsafec.so.1.0.0
9) Write a command line that will make gcc compiler
aware that you would like to use version
libsafec.so.1.0.0 of the shared object library when
compiling a source code that uses it.
10) Write a command line that will make linker and
loader aware that you would like to use
libsafec.so.1.0.0 version of the shared object library
when linking and loading an executable code that
uses it.
11) Assume your file program.c calls functions from
libsafec.so.1.0.0. Also assume that
libsafec.so.1.0.0 and the appropriate symbolic links
are placed in the subdirectory lib. Write a
command line that will compile program.c.
12) Assume your executable file program calls
functions from libsafec.so.1.0.0. Also assume that
libsafec.so.1.0.0 and the appropriate symbolic links
are placed in the subdirectory lib. However, you
don?t have the superuser privileges to update the
system?s configuration to make your library available
to everyone on the system. Write a command line that
will run program.
13) Assume your application in program.c called
functions from libsafec.so.1.0.0. You have
redesigned your application (in program.c) to load the
needed functions at the run time. Write a
command line that will compile program.c.
14) Declare a pointer to an array of pointers to
functions returning double and having an int
parameter.
15) Write a function prototype of the Unix system call
signal. signal is a function with two parameters
(the first one is int and the second one is a pointer
to a function having an int parameter and returning
no value) and returning a pointer to a function with
one int parameter and returning no value.
16) Assume ip is defined as a pointer to int (i.e.,
int *ip
. Use a dynamic memory allocation feature of
C to allocate space for 200 integer values and arrange
that ip points to it.
17) Assume the situation from question 16). You are
done with using the dynamically allocated
memory pointed to by ip. Write C code to release that
memory.
18) Write a function prototype of a version of main
function that receives command line input.
19) Assume your system has a programmable 8-bit
register at the absolute address
0xFFFFFFFFC0000000. Define a pointer reg that points
to that location.
20) Assign value 0x45 to the programmable 8-bit
register from question 19).
21) Define a preprocessor macro square(x) that will
compute x*x.
22) Assume that the standard input stream holds an
integer value followed by a string. Also assume
that you have the following declarations: int in; char
string[80]; and assume that your program starts
with #include . Read the integer value into in and the
string into string.
23) Assume FILE *stream; Open file myfile.dat for
writing and assign file pointer to stream.
24) Assume that you have opened the file in question
23). Write to it values from character variable
ch, integer variable in, and floating-point variable
x; in that order.
25) Write a complete system?s call that will replace
your current C program code with the code from
/bin/ls. The /bin/ls command will receive the
following command line arguments: ls -l /etc. (For all
practical purposes it appears as if you executed: ls
?l /etc from shell prompt.)
26) Assume you have the following definition: int pid;
Write a code segment to create a child process
and test if the code is resuming in the child?s
process.
27) Assume int status; Write a system call that allows
the parent process to wait for any child to
terminate.
28) Assume you have written a signal handler with the
following prototype: void sig ( int ); Write a
system call to install your signal handler for signal
number 2, i.e., SIGINT.
29) Type C preprocessor include directive that is
needed in order to use signal system call.
30) Given int fd; open file datafile for low level
input and assign its file descriptor to fd.
31) Assume a file has been opened for low level
reading as in question 30). Read an integer value into
a variable length (declared as int length
. You have
available to you another integer variable
bytes_read to keep track of the actual number of bytes
that were read in.
32) Given int pdes[2]; create a pipe.
33) Assume you have created a pipe (as in question
32)) and used fork( ) to create a child process.
Write string ?Hello? to the writing side of the pipe.
34) Assume you have opened a pipe (as in question 32).
Close the reading end of the pipe.
35) At the beginning of main.c file, before the
function definitions, you have the following array
definition: int arr[100]; In another file, file.c, you
would like to declare the same array as a global
variable. Write that declaration.
36) Assume you have a target run in your makefile.
Type a command to build that target assuming run
is not the default target.
37) Assume you have a run-time error in your code.
Type a command to recompile it in order to use
gdb debugger, assuming your source file is called
program.c.
38) In one of your functions you would like to define
an integer variable count that will be initialized to
1. count will be modified any time the function is
called and will keep its current value after the
function
exits. Write the definition of count.
39) Write a declaration of a data type named number
that can hold either an integer value or a double
precision floating point number.
40) Your program contains an array definition float
data[10]; and a function prototype float
findaverage(int size,float list[ ]); Call findaverage(
) and pass it entire array data.
41) Given this definition: char str[50]; the following
assignment is illegal: str=?Hi?; Write a correct
definition with initialization of character array str.
42) We have the following function prototype: void
swap(int *px, int *py); that swaps values of the
first and second parameter. Also, we have definitions
of two integer variables: int a=3, b=5; Call
function swap( ) to exchange values of a and b.
43) Declare a structure that could be used in creating
a linked list of integer values. The structure?s
name is node, the integer field is called value, and
pointer field is called next.
44) Assume you have a function prototype: void f(int);
and a definition of a pointer to a function: void
(*pf) (int) = f; Use pf to call the function pointed
by it and pass value 10;
45) Write the declaration of an array of pointers to
functions that take one double argument and return
double. The array name is table.
46) Given definitions: float x; int in = 3; and an
assignment statement: x = in / 2; the resulting value
stored in x is 1.0. Rewrite the assignment statement
so you get the correct result for any value of in,
i.e., don?t type x = 1.5;.
47) Given a function definition: void change(int
index, float value, float *list){ ?} write a
statement, that would be a part of the body of this function,
that, when the function is called, assigns second
argument to the slot, passed as the first argument, of
the array that is passed as a third argument.
48) Given definitions: int in=3, j=2; the conditional
statement: if ( in = j ) printf(?in and j are
same\n?);
that was supposed to test for equality of in and j
fails. Write a correct statement.
49) Given int in=3, j=2; the statement if ((in > j) &
j ) printf("true\n"); that was intended to test if in
> j
and j is nonzero fails. Rewrite the statement to yield
the correct result.
50) Assume you have created a shared objects library
libinterceptor.so.1.0.0 that contains new
versions of some of the functions from other shared
objects libraries that your application is using. You
have already set the symbolic link for the library to
libinterceptor.so.1. Set the appropriate environment
variable so that your new library is preloaded.
If you're hte guy who said "C is easy if you know C++ and you can learn gcc and make in jsut a minute" I'd love to see you take the test.
I'm going to fail, my final is in an hour.
CSC60 TEST #2
1) Your C program is in program.c. Write a C compiler
command to create an executable file called
program.
2) Write a C preprocessor directive to include (inside
your C program) a header file containing
function prototypes for the functions from the
standard mathematical library.
3) Assume that your program.c uses some of the
functions from the standard mathematical library.
Write a C compiler command to compile program.c.
4) Assume that you have a line #include ?calc.h? in
your program.c. Also assume that calc.h is in the
subdirectory my_include. Write a C compiler command to
compile program.c.
5) Assume that your file stack.c contain functions
that you would like to keep in a static library. Write
commands that will create such a library.
6) Assume you place your library libsafec.a in a
subdirectory my_lib. Write a command line to compile
your program.c that uses functions from that library.
7) You would like to place functions from safecalls.c
in a dynamic shared objects library. Show a
command needed to create an object file safecalls.o
that can be placed in the shared objects library.
8) Assume you have created safecalls.o and
safecalls2.o in a way suitable for being incorporated
in a
dynamic shared objects library. Write a command line
to create a shared objects library
libsafec.so.1.0.0
9) Write a command line that will make gcc compiler
aware that you would like to use version
libsafec.so.1.0.0 of the shared object library when
compiling a source code that uses it.
10) Write a command line that will make linker and
loader aware that you would like to use
libsafec.so.1.0.0 version of the shared object library
when linking and loading an executable code that
uses it.
11) Assume your file program.c calls functions from
libsafec.so.1.0.0. Also assume that
libsafec.so.1.0.0 and the appropriate symbolic links
are placed in the subdirectory lib. Write a
command line that will compile program.c.
12) Assume your executable file program calls
functions from libsafec.so.1.0.0. Also assume that
libsafec.so.1.0.0 and the appropriate symbolic links
are placed in the subdirectory lib. However, you
don?t have the superuser privileges to update the
system?s configuration to make your library available
to everyone on the system. Write a command line that
will run program.
13) Assume your application in program.c called
functions from libsafec.so.1.0.0. You have
redesigned your application (in program.c) to load the
needed functions at the run time. Write a
command line that will compile program.c.
14) Declare a pointer to an array of pointers to
functions returning double and having an int
parameter.
15) Write a function prototype of the Unix system call
signal. signal is a function with two parameters
(the first one is int and the second one is a pointer
to a function having an int parameter and returning
no value) and returning a pointer to a function with
one int parameter and returning no value.
16) Assume ip is defined as a pointer to int (i.e.,
int *ip
C to allocate space for 200 integer values and arrange
that ip points to it.
17) Assume the situation from question 16). You are
done with using the dynamically allocated
memory pointed to by ip. Write C code to release that
memory.
18) Write a function prototype of a version of main
function that receives command line input.
19) Assume your system has a programmable 8-bit
register at the absolute address
0xFFFFFFFFC0000000. Define a pointer reg that points
to that location.
20) Assign value 0x45 to the programmable 8-bit
register from question 19).
21) Define a preprocessor macro square(x) that will
compute x*x.
22) Assume that the standard input stream holds an
integer value followed by a string. Also assume
that you have the following declarations: int in; char
string[80]; and assume that your program starts
with #include . Read the integer value into in and the
string into string.
23) Assume FILE *stream; Open file myfile.dat for
writing and assign file pointer to stream.
24) Assume that you have opened the file in question
23). Write to it values from character variable
ch, integer variable in, and floating-point variable
x; in that order.
25) Write a complete system?s call that will replace
your current C program code with the code from
/bin/ls. The /bin/ls command will receive the
following command line arguments: ls -l /etc. (For all
practical purposes it appears as if you executed: ls
?l /etc from shell prompt.)
26) Assume you have the following definition: int pid;
Write a code segment to create a child process
and test if the code is resuming in the child?s
process.
27) Assume int status; Write a system call that allows
the parent process to wait for any child to
terminate.
28) Assume you have written a signal handler with the
following prototype: void sig ( int ); Write a
system call to install your signal handler for signal
number 2, i.e., SIGINT.
29) Type C preprocessor include directive that is
needed in order to use signal system call.
30) Given int fd; open file datafile for low level
input and assign its file descriptor to fd.
31) Assume a file has been opened for low level
reading as in question 30). Read an integer value into
a variable length (declared as int length
available to you another integer variable
bytes_read to keep track of the actual number of bytes
that were read in.
32) Given int pdes[2]; create a pipe.
33) Assume you have created a pipe (as in question
32)) and used fork( ) to create a child process.
Write string ?Hello? to the writing side of the pipe.
34) Assume you have opened a pipe (as in question 32).
Close the reading end of the pipe.
35) At the beginning of main.c file, before the
function definitions, you have the following array
definition: int arr[100]; In another file, file.c, you
would like to declare the same array as a global
variable. Write that declaration.
36) Assume you have a target run in your makefile.
Type a command to build that target assuming run
is not the default target.
37) Assume you have a run-time error in your code.
Type a command to recompile it in order to use
gdb debugger, assuming your source file is called
program.c.
38) In one of your functions you would like to define
an integer variable count that will be initialized to
1. count will be modified any time the function is
called and will keep its current value after the
function
exits. Write the definition of count.
39) Write a declaration of a data type named number
that can hold either an integer value or a double
precision floating point number.
40) Your program contains an array definition float
data[10]; and a function prototype float
findaverage(int size,float list[ ]); Call findaverage(
) and pass it entire array data.
41) Given this definition: char str[50]; the following
assignment is illegal: str=?Hi?; Write a correct
definition with initialization of character array str.
42) We have the following function prototype: void
swap(int *px, int *py); that swaps values of the
first and second parameter. Also, we have definitions
of two integer variables: int a=3, b=5; Call
function swap( ) to exchange values of a and b.
43) Declare a structure that could be used in creating
a linked list of integer values. The structure?s
name is node, the integer field is called value, and
pointer field is called next.
44) Assume you have a function prototype: void f(int);
and a definition of a pointer to a function: void
(*pf) (int) = f; Use pf to call the function pointed
by it and pass value 10;
45) Write the declaration of an array of pointers to
functions that take one double argument and return
double. The array name is table.
46) Given definitions: float x; int in = 3; and an
assignment statement: x = in / 2; the resulting value
stored in x is 1.0. Rewrite the assignment statement
so you get the correct result for any value of in,
i.e., don?t type x = 1.5;.
47) Given a function definition: void change(int
index, float value, float *list){ ?} write a
statement, that would be a part of the body of this function,
that, when the function is called, assigns second
argument to the slot, passed as the first argument, of
the array that is passed as a third argument.
48) Given definitions: int in=3, j=2; the conditional
statement: if ( in = j ) printf(?in and j are
same\n?);
that was supposed to test for equality of in and j
fails. Write a correct statement.
49) Given int in=3, j=2; the statement if ((in > j) &
j ) printf("true\n"); that was intended to test if in
> j
and j is nonzero fails. Rewrite the statement to yield
the correct result.
50) Assume you have created a shared objects library
libinterceptor.so.1.0.0 that contains new
versions of some of the functions from other shared
objects libraries that your application is using. You
have already set the symbolic link for the library to
libinterceptor.so.1. Set the appropriate environment
variable so that your new library is preloaded.