You are on page 1of 1

Programming Fundamentals Final Term University of Engineering and Technology, KSK Campus Maximum Marks 40

Time Allowed 90 min Name: Reg. # 201 – EE – Answer Sheet # .


CLO 3-Question # 1 (5 marks): Consider the following program, CLO 4-Question # 5 (5 Marks): Write output.
which compiles without warning, but crashes when run. Looking
at the source code, why does the program crash? #include<stdio.h>
int main()
{
#include <stdio.h>
union a
int factorial(int x) {
{
if(x==1) int i;
return 1; char ch[2];
return x * factorial(x-1); };
} union a u;
int main(int argc, char**argv) { u.ch[0]=3;
int n = factorial(0); u.ch[1]=2;
return 0; printf("%d, %d, %d\n", u.ch[0], u.ch[1], u.i);
} return 0;
}

CLO 4-Question # 6 (3 Marks): Which among the following best


CLO 3-Question # 2 (10 Marks): Write a C function which takes describes polymorphism?
array as an input and calculate Maximum Subsequence
a) It is the ability for a message/data to be processed in more than
Sum. i.e if passed 1, 6, -12, 8, 4 then it returns 12 because
one form
8, 4 forms a sequence whose sum is 12 which is maximum.
b) It is the ability for a message/data to be processed in only 1
CLO 3-Question # 3 (10 marks): Write an encryption function form
in C that takes string and key size as an input and return after
flipping first and last x number of characters, where x is key c) It is the ability for many messages/data to be processed in one
size. way

d) It is the ability for undefined message/data to be processed in


CLO 3-Question # 4 (5 Marks): Write output.
at least one way
#include<stdio.h>

int main() CLO 4: Question # 7 (2 Marks): Which type of function among the
{ following shows polymorphism?
static char *s[] = {"black", "white",
"pink", "violet"}; a) Inline function
char **ptr[] = {s+3, s+2, s+1, s}, ***p;
p = ptr; b) Virtual function
++p;
printf("%s\n", **p+1); c) Undefined functions
++p;
printf("%s\n", **p+1); d) Class member functions
printf("%s\n", **p+2);
printf("%s\n", **++p+2);
return 0;
}

You might also like