RESTRICTED USE
LA TROBE UNIVERSITY
CSE1PES/CSE5CES
PRACTICE
EXAM
Reading Time: 15 minutes
Writing Time: 120 minutes
(Note: Actual CSE5CES 2017 exam is 150 minutes writing time with one
extra question. CSE1PES is 120 minutes writing time)
INSTRUCTIONS TO CANDIDATES
1. Total marks = 120
2. Answer all questions.
3. Write your answers in the space provided in the question paper after each question.
2 OVER/
Question 1 [15]
This question has 10 parts. Each part is a multiple choice question. Answer each multiple choice question by placing a
tick mark () in box opposite the co
ect (best) option.
1. Which of the following is a valid variable name:
a) _count
b) total$
c) 2nd_num
d) long
e) third number
2. Which of the following is the hexadecimal representation of the binary number XXXXXXXXXX:
a) 0x8F
b) 0x4A
c) 0xA4
d) 0x23
e) 0xA23
3. Which of the following types is used to store a collection of related data items:
a) int
b) struct
c) double
d) float
e) char
4. To test if two strings (str1, str2) consist of the same characters in C, you should use:
a) if(str1 == str2)
b) if(strcmp(str1, str2) != 0)
c) if(strcmp(str1, str2) == 0)
d) if(str1 != str2)
e) if(strcompare(str1,str2)==0)
3 OVER/
5. Which is the co
ect way to define the macro for N to be replaced by 100
a) #define N = 100
b) #include N =100
c) #define N 100
d) #define N 100;
e) #define N = 100;
6. Which is the co
ect way to declare an a
ay of pointers that point to objects of type int, where the a
ay
is of size 5?
a) int a = 5;
b) int* a;
c) int* a[] = 5;
d) int* a[5];
e) int a[5];
7. Assume we have an executable program in the file called ComplexNumber.
If we enter the following on the command line, what will be the value of argv[2] within our Program?
XXXXXXXXXXComplexNumber 6 + 5i XXXXXXXXXX2i
a) 5
b) 5i
c) 6
d) +
e) 2i
8. In the following call to the C standard I/O li
ary function fprintf
XXXXXXXXXXfprintf(outfile, “%s\n”, word);
The type of the variable outfile must be
a) A string (a NULL terminated a
ay of characters)
b) A pointer to an a
ay of characters
c) A pointer to FILE (FILE *)
d) A pointer to int (int *)
e) int
4 OVER
9. In a C program an unsigned int variable named flag is used to hold a number of single bit flags. In
an if statement of the form
if(expression) {
Code to be executed};
you have to test the condition if the right-most bit (the least significant bit) or the third rightmost bit of
the variable flag is set (has the binary value 1). What is the co
ect expression to test this condition?
a) flag && 0x05
b) flag && 0
c) (flag && 0x05) != 1
d) (flag || 0x05) == 1
e) (flag && 0xFA) == 1
10 What is the value in the variable lock after the following code segment is executed?
unsigned input = 5;
unsigned lock = 0;
lock ^= 1
input;
a) 0x01
b) 0x05
c) 0x20
d) 0x00
e) 0x40
5 OVER/
Question 2 [25]
This question has 10 parts. Answer each part in the space provided.
a) What is the output of the following C code fragment?
#include
int main()
{
int a = 9, b = 4, c;
c = a
;
printf("The result is: %d\n", c);
return 0;
}
Answer:
) What is the output of the following C code fragment?
printf("First:%d, Second:%.1f\n", 18, 4.555);
Answer:
6 OVER/
c) What is the output of the following C code fragment?
int place = 0;
switch(place)
{
case 0:
printf("Gold\n");
eak;
case 1:
printf("Silver\n");
eak;
case 2:
printf("Bronze\n");
eak;
}
printf("End of list");
Answer:
d) What is the value held in the variable result following the execution of this C code fragment?
int result = 1, a = 3, b = 5, c = 4;
if((a < b) || (c == b))
{
result = c;
}
else if(a != c)
{
result = b;
}
else
{
esult = a;
}
Answer:
7 OVER/
e) Given that the user input is as follows:
4, 2.995
What is the output of the following C program?
#include
int main()
{
int a, b;
float c;
scanf("%d,%d%f", &a, &b, &c);
a -= b;
c *= b;
printf("Result:%d, %.4f", a, c);
return 0;
}
Answer:
f) What is the output of the following C code fragment?
int num = 1;
int i, j;
for(i = 0; i < 2; i++)
{
for(j = 0; j < 4; j++)
{
switch(num)
{
XXXXXXXXXXcase 5:
XXXXXXXXXXprintf("* ");
eak;
XXXXXXXXXXcase 2:
XXXXXXXXXXprintf("# ");
eak;
XXXXXXXXXXdefault:
XXXXXXXXXXprintf("%d", num);
}
XXXXXXXXXXnum;
}
printf("\n");
}
Answer:
8 OVER/
g) What is the output of the following C code fragment?
#include
void mult(int num);
int main()
{
int x = 5;
mult(x);
printf("%d", x);
return 0;
}
void mult(int num)
{
num *= 2;
printf("%d\n", num);
}
Answer:
h) What is the output of the following C code fragment?
int y = 8;
int* p = &y;
func(p);
printf("%d", y);
...
void func(int* p)
{
*p = 3;
}
Answer:
9 OVER/
i) What is the output of the following C code fragment?
int x = 1, y = 2, *p = &x, *q = &y;
x = 3;
*p = 5;
*q = x + y;
printf("%d\n", y);
Answer:
j) What is the output of the following C code fragment?
#include
void func(int *p, int n, int *r);
int main()
{
int a
[4] = {1, 6, 3, 5};
int* ptr_position = a
;
int i, n = 4;
float val=0;
for(i=0; i{
val+= *ptr_position;
ptr_position++;
}
printf("%f",val);
}
Answer:
10 OVER/
Question 3 [21]
Consider the code given below:
#include void exam_function(int e, int*