You are on page 1of 5

A

BIL200 Computer Programming


FINAL EXAM

10.01.2020

Note:
 You are allowed to have only course slides so no book, no notes on the slides, or no other document is
allowed during this examination.
 Total time for this examination is 110 minutes.

A
Name , Surname:

ID:
Section (that appears in your course
registration):
Signature :

Decimal ASCII Chart


Dec Char Dec Char Dec Char Dec Char Dec Char Dec Char Dec Char Dec Char
0 NUL 16 DLE 32 SP 48 0 64 @ 80 P 96 ` 112 p
1 SOH 17 DC1 33 ! 49 1 65 A 81 Q 97 a 113 q
2 STX 18 DC2 34 " 50 2 66 B 82 R 98 b 114 r
3 ETX 19 DC3 35 # 51 3 67 C 83 S 99 c 115 s
4 EOT 20 DC4 36 $ 52 4 68 D 84 T 100 d 116 t
5 ENQ 21 NAK 37 % 53 5 69 E 85 U 101 e 117 u
6 ACK 22 SYN 38 & 54 6 70 F 86 V 102 f 118 v
7 BEL 23 ETB 39 ' 55 7 71 G 87 W 103 g 119 w
8 BS 24 CAN 40 ( 56 8 72 H 88 X 104 h 120 x
9 HT 25 EM 41 ) 57 9 73 I 89 Y 105 i 121 y
10 LF 26 SUB 42 * 58 : 74 J 90 Z 106 j 122 z
11 VT 27 ESC 43 + 59 ; 75 K 91 [ 107 k 123 {
12 FF 28 FS 44 , 60 < 76 L 92 \ 108 l 124 |
13 CR 29 GS 45 - 61 = 77 M 93 ] 109 m 125 }
14 SO 30 RS 46 . 62 > 78 N 94 ^ 110 n 126 ~
15 SI 31 US 47 / 63 ? 79 O 95 _ 111 o 127 DEL

A
A
1) A) Compile error: pointing another pointer is not
allowed
#include<stdio.h> B) 6, 6, 6
int my_func(int *n)
{ C) 5, 5, arbitrary number
return *(++n + 1) + 2; D) 5, 5, memory address
} E) 5, 6, 5
void main(){
int dizi[8] = {7, 5, 3, 6, 1, 2};
printf("%d", my_func(dizi+2)); 5)
}
#include<stdio.h>
What is the output of the above C program? void transform(int *arr, int b);
void main(){
A) 1 int a[6] = {2,5,7,3,1,8};
B) 3 int b=5;
transform(a,b);
C) 4 printf("%d, %d, %d\n",a[1],a[3],a[4]);
D) 6 }
E) 8 void transform(int arr[], int b)
{
int i;
2) What will be the final values of a and c in the following
for(i=0;i<b;i++)
C statement? (Initial values: a = 2, c = 1) arr[i] += arr[b-i];
}
c = (c) ? a = 0 : 2; What is the output of the above C program?

A) a = 0, c = 0; A) 5, 3, 1
B) a = 2, c = 2; B) 1, 7, 5
C) a = 2, c = 0; C) 6, 13, 7
D) a = 0, c = 1; D) 10, 10, 13
E) Syntax error E) No output due to compile time error (errors in
code)
3)
6)
#include<stdio.h>
int my_rec(int n, int a){ #include<stdio.h>
if(n==1) return 1;
void main()
return(n+a+my_rec(n-1,a));
{
}
struct {inta;} deger={7},*p=&deger;
void main(){
printf("%d%d%d",deger.a,p->a,(*p).a);
int n=50, a=10;
}
printf("%d\n", my_rec(n,a));
} What is the output of the above C program?

What is the output of the above C program? A) 777


B) 77garbage value
A) 1775 C) 770
B) 1275 D) 700
C) 1675 E) No output due to compile time error (errors in
D) 1765 code)
E) No output due to compile time error (errors in
code) 7)

#include<stdio.h>
4) main()
{
#include<stdio.h> char *s = "Hello";
main() while(*s != '\0')
{ {
int x = 5, *p=&x, **q=&p; printf("%c", *s++);
++**q; }
printf("%d,%d,%d",x,*p,**q); }
}
What is the output of the above C program?
What is the output of the above C program?
A) Compile error: \0 is not defined

A
A
B) Hello\0 D)
customer *structure_array(int n){
C) Hello customer *custom_arr;
custom_arr=(customer*)malloc(n*sizeof(customer));
D) HIJKL return *custom_arr;
E) Infinite loop }
E)
customer *structure_array(int n){
8) Function fopen() with the mode "r+" tries to open the customer *custom_arr;
custom_arr=(customer*)malloc(n*sizeof(customer));
file for …. return custom_arr;
}

A) reading and writing


B) reading and adding new content
11) Which of the following function call for the above
C) only for reading
function (structure_array) definition is correct?
D) it works only for directories
E) only for overwriting A)
customer p[];
9) Calling a function F with a an array variable arr[3] &p = structure_array(int n);
where arr is an array, is equivalent to B)
customer *p;
A) F(arr[3]) p = structure_array(n);
B) F(*(arr+3)) C)
customer p[n];
C) F(arr[1+2] &p[0] = structure_array(int n);
D) F(3[arr]) D)
E) All of the above customer *p;
p = *structure_array(n);
Use the given definitions in Table-1 for the questions E)
customer *p;
between 10-13.
p = &structure_array(int n);
#include <stdio.h>
#include <stdlib.h>
typedef struct{ 12) After allocating n elements of customer structure
int month; array how can we print 2nd customer’s lastpayment date
int day; using pointer p? Customer structure is defined in Table-
int year; 1.
}date;
typedef struct{ A)
int acct_no; printf("%d.%d.%d",(p+1)->lastpayment.day,
char name[80]; (p+1)->lastpayment.month,
float balance; (p+1)->lastpayment.year);
date lastpayment; B)
}customer; printf("%d.%d.%d",p[2]->lastpayment.day,
p[2]->lastpayment.month,
Table-1: Pre-processing and structure definitions p[2]->lastpayment.year);
C)
10) According the above definitions in Table-1, which of printf("%d.%d.%d",p[1].lastpayment->day,
the following function allocates customer structure array p[1].lastpayment->month,
p[1].lastpayment->year);
with n elements and returns the starting address of the
D)
structure array as output? printf("%d.%d.%d",(p+2).lastpayment.day,
(p+2).lastpayment.month,
A) (p+2).lastpayment.year);
date structure_array(int n){
date date_arr[n]; E)
customer customer_arr[n]; printf("%d.%d.%d",p->lastpayment.day,
return custom_arr; p->lastpayment.month,
}
B)
p->lastpayment.year);
customer structure_array(int n){
customer *custom_arr;
custom_arr=(customer*)malloc(n*sizeof(customer));
return custom_arr; 13) After allocating 100 elements of customer structure
}
C)
array, what will be the total size of this 100 element
customer structure_array(int n){ structure array in memory (in KB)? Customer structure
customer *custom_arr;
date *date_arr; is defined in Table-1.
date_arr=(date*)malloc(n*sizeof(date));
custom_arr=(customer*)malloc(n*sizeof(customer));
return custom_arr; Note that 1 char 8 bits, 1 int 16 bits, 1 float 32 bits and 8
}
bits is 1 byte, 1000 bytes is 1 KB.
A
A
A) 7.36 KB B) 1
B) 6.8 KB C) 5
C) 8.5 KB D) 6
D) 9.2 KB E) 10
E) 10.0 KB
17) fseek() should be preferred over rewind() mainly
14) Which of the following C code can write the values of because
an integer array with length n (int arr[n]) to text file
(“File.txt”). A) rewind() doesn't work for empty files
B) rewind() may fail for large files
A) C) In rewind, there is no way to check if the
FILE *fp; operations completed successfully
fp = fopen("File.txt","rb+");
int i; D) fseek() cannot be used instead of rewind()
for(i=0;i<n;i++) E) All of the above
printf("%d ",arr[i]);
B)
FILE fp;
fp = fopen("File.txt","r"); 18) “fwrite() can be used only with files that are opened in
for(int i=0;i<n;i++)
scanf(fp,"%d ",&arr[i]); binary mode.” Is this statement true or false ?
C)
FILE *fp; A) TRUE
fp = fopen("File.txt","w+"); B) FALSE
int i;
for(i=0;i<n;i++)
fprintf(fp,"%d ",arr[i]);
D) 19)
FILE *fp;
fp = fopen("file.txt","rwb+");
#include <stdio.h>
int i;
int main()
for(i=0;i<n;i++)
{
fprintf(fp,"%d ",*arr[i]);
int a = 10, b = 5, c = 3;
E)
FILE *fp; b != !a;
fp = fopen("file.txt","w+"); c = !!a;
int i; printf("%d %d", b, c);
for(i=0;i<n;i++) }
fscanf(fp,"%d ",&arr[i]);
What is the output of the above C program?

15) Which of the following true about FILE *fp A) Syntax error
B) 03
A) FILE is a keyword in C for representing files and C) 11
fp is a variable of FILE type D) 53
B) FILE is a stream E) 51
C) FILE is a buffered stream
D) FILE is a structure and fp is a pointer to the 20) Choose the right statement for fscanf() and scanf()
structure of FILE type
A) fscanf() can read from standard input whereas
E) FILE is variable and fp is the pointer
scanf() specifies a stream from which to read
16) B) fscanf() can specifies a stream from which to read
whereas scanf() can read only from standard input
#include <stdio.h> C) fscanf() and scanf() has no difference in their
int main()
functions
{
int a = 10, b = 5, c = 5; D) fscanf() and scanf() can read from specified stream
int d; E) All of the above
d = b + c == a;
printf("%d", d);
}
What is the output of the above C program?

A) Syntax error
A
A

21) 24)

#include <stdio.h> #include <stdio.h>


void main() void f(char *k)
{ {
char arr[5][6]= k++;
{"Hi","Hello","Bil200Class"}; k[2] = 'm';
printf("%s", arr[2]); }
} void main()
What is the output of the above C program? {
char s[] = "bil200";
f(s);
A) Hello
printf("%c\n", *s);
B) Hi }
C) Bil200Class What is the output of the above C program?
D) Bil200Clas
E) Bil200 A) b
B) i
22) Choose the statement which is incorrect with respect C) l
to dynamic memory allocation. D) m
E) 2
A) Memory is allocated in a less structured area of
memory, known as heap 25)
B) Used for unpredictable memory requirements
C) Execution of the program is faster than that of #include <stdio.h>
int x = 5;
static memory allocation void mf();
D) Allocated memory can be changed during the run void nf();
time of the program based on the requirement of void main()
{
the program
int x = 3;
E) It is possible to de-allocate the allocated memory mf();
with free function. printf("%d", x);
system("PAUSE");
23) What will be the data type of the following expression? }
void mf()
(Initial data type: a = int, var1 = double, var2 = float) {
x = 8;
(a < 50)? var1 : var2; nf();
}
A) int void nf()
{
B) float
printf("%d", x);
C) double }
D) Cannot be determined What is the output of the above C program?
E) Syntax error
A) 53
B) 85
C) 33
D) 38
E) 83

You might also like