Вы находитесь на странице: 1из 11

Pakistan Institute of Engineering &

Applied Sciences
Department of Computer and Information Sciences
Subject Title

Computing Fundamentals and


Programming

Date

09-Dec-2016

Subject Code

CIS-101

Time

10:30

class

BS(CIS)-1st Semester 2016-2020

Duration

90 min

Student Name

Roll No

Total Time : 90 Minutes Total Marks: 60


Best of Luck

Section-I
Marks-15
Solve on the answer sheet provided with this section
Q1. Which of the two statements is correct?
1. Which of the following statement is correct about second parameter of
scanf(%c,___); correct statement means the one which should not create a
compilation or execution error
a. It can be a variable of type char
b. Itcanbe a string value like c
c. It can be name of a character array
d. It can be a character value like c
2. If max is the name of a character array then which of the following pair of
parameters if passed to printf(___,___) will correctly print the entire array
a. %c and &max
b. %s and max[0]
c. %s, and &max[0]
d. %c, and &max
3. Which of the following statement is correct about the default: statement of a
switch statement
a. Should must be included, it will be executed if no case is matched
b. No default: is an optional statement, however if no case is matched
and default is missing the switch will cause program termination or
abnormal behavior

c. No default: is an optional statement and a missing default will not


cause program termination or abnormal behavior even if no case is
matched
d. Should must be included and it is always executed even if a case is
matched
4. The correct
a. case
b. case
c. case
d. case

method to write a case in a switch statement is


constantValue ;
: constantValue
constantValue:
: constantValue ;

5. If ch is a character variable then the statement ch=29;


a. Will cause an error
b. Will assign ch the character whose integer value is 29
c. Will assign ch 2
d. Will assign ch a zero value
6. Which of the following statement about functions is correct
a. A function can be defined inside another function
b. If a function is defined after main, it is not necessary to declare its
prototype
c. A function can call only those functions that are defined before it
d. If a function has to return two values it should declare its return type to
be int, int i.e. has to write int two times in its return type
7. If
int A[5]={1,2,3};
printf("%d,%d,%d",A[1]+A[2],A[2]+A[3],A[3]+A[4]);

then which of the following is correct output of this printf statement


a. 5,garbage,garbage
b. 5,3,0
c. 5,3,grabage
d. Compilation or Execution Error
8. If int A[10]; is an array of integers, which of the following is the shortest way
to initialize all elements of A to zero
a.
b.
c.
d.

int A[10]=0;
A=0;
int A[10]={0,0,0,0,0,0,0,0,0,0};
int A[10]={0};

9. if
1-int *ptr, A[5]={1,2,3,4,5};
2-ptr=A;
3-ptr[*ptr]=30;
4-printf("%d,%d,%d,%d,%d",A[0], A[1], A[2], A[3],*ptr);
then what will be output of this these statements

a.
b.
c.
d.

Error at line 3, the program will cause compilation or execution error


1,2,3,4,1
30,1,2,3,4
1,30,3,4,1

10.If
int *ptr=2;
printf(%d,*ptr);

then what will be the effect of these two statement


a. cause an error as an integer value cannot be assigned to a pointer
variable as an address
b. second line will print 2 as output
c. second line will print garbage as 2 is considered an address here
d. will print a random memory address
11.Which of the following statement is NOT a correct pointer declaration
a.
b.
c.
d.

int*a;
int*
a;
int *c=&d,d=10;
int b=10,*a=&b;

12.Consider a program in which there are three functions A(),B() and C().
Function A() is declared at the top, B() is declared after A(), and C() is
declared after B().All of the functions are declared before main(). For this
situation which of the following statement is not correct
a.
b.
c.
d.

C()
B()
A()
A()

can
can
can
can

be
be
be
be

called
called
called
called

inside B()
inside A() and C()
inside B() and C()
in main() but not in B() or C()

13.In the following statement


float a, b,c;
a=10/3;
b=10/3.0;
c=10.0/3;
d=10.0/3.0;

what will be values of a,b,c,d after assignments (values are ordered as value of
a,b,c, and d)
a.
b.
c.
d.

3.0,
3,
3,
3,

3.33,
3.33,
3,
3.0,

3.33,
3.33,
3,
3.0,

and
and
and
and

3.33
3.33
3.33
3.33

14.Consider the following program and function , and select which of the option
is correct output of this program
void swap(int *a,int b){
a=&b;
*a=10;
b=20;
}
void main(){
int num1=100,num2=200;
swap(&num1,num2);
printf("%d,%d",num1,num2);
getch();
}

a.
b.
c.
d.

10,100
10,200
10,20
100,200

15.In the following program , how many times x will be printed


int main (){
int index=1;
while(index>0){
printf(x);
if(index%101==0)
index=100-index;
index++;
}
printf("%d",count);
getch();
return 0;
}

a.
b.
c.
d.

1
100
101
Infinite

Bonus Point-02

Is it true that all memory addresses are of same sizes? If your answer is yes then why
pointer variables have a data type (it has to store memory addresses which in your opinion
are of same sizes)? If your answer to the first part of this question is No then explain why
addresses have different sizes?
Ans:

Section-II
Marks 25
Solve on question paper, return solved paper to examiner
Q-2 Write output of the following programs, (The header files are not
included here, you should not consider it as mistake or error)
Marks[5x5=25]
Program-1
#include<stdio.h>
int main(){
int index=0;

Output

for(index=11;index<20;index++){
if(index%2==0)
printf("\n %d",index--);
else if(index%2==1)
index--;
printf("\n %d",index++);
}
return 0;}

Program-02
void main (){
int A[6]={34,21,1,56,23};
int B[]={0,1,2,3,0};
int *ptr;
int i=0;
while(A[i]){
ptr=&A[B[i]];
printf("\n %d",*ptr);
i++;
}
getch();

Program-03
#include<stdio.h>
void main () {
inti;
int A[10]={1,6,3,8,10,2,9};
for(i=0;i<10;i++)
if(A[i]<A[i+1])
printf("%d",A[i]);
}

Output

Program-04

Output

int num=1;
void angry(int n){
staticint num=n+1;
num++;
printf("\n%d",num);
}
void happy(int n){
num=n+1;
printf("\n%d",num);
}
int main (){
int n=num;
printf("\n%d",num++);
angry(num);
n=num;
happy(n);
n=num;
happy(num);
n=num;
angry(n);
getch();
}

program-05
int A(int a){
printf("\n%d",a);
return a*2;
}
int B(int a){
return a+1;
}
int C(int a){
return a-1;
}
int D(int a){
printf("\n%d",a);
return a*a;
}
int main (){
printf("\n%d",A(B(C((D(A(2)+B(3))+C(3)-D(2))))));
getch();
//return 0;
}

Output

Section-III
Time 40 Min, Marks20
Solve on question paper, return solved paper to examiner

Q3. Mark the following statements as correct or incorrect, (In case a


statement in your opinion will cause a compilation or execution
error simply mark it as incorrect)Marks [10]
int A[5]={1,2,3,4,5};

int B[5]={10,20,30,40,50};

int a=1,b=2 ; float c=3.0,d=4.5;


Sr.N
o

1
2
3

int *ptr;

char password[]=pass2016;

Statement

If A is an array *A is value of first element of the array


There should must be a return statement in a recursive
function
Name of the array and a pointer to array both have same
properties

The statement
printf(%s,pass);
will print pass2

The assignment
ptr=A ;
will assign the address of A to ptr, similarly B=A will assign
address of A to B

If size of integer is 4 then sizeof(A) will return 20

A variable that is declared global and static in file 1 cannot be


accessed in file 2 using extern keyword

The statement
*(&a)=20;
will modify the value of variable a to 20

switch(c){
case 3.0:
printf(3);
break;
}
The code above will print 3

(2 zero 1 6)
Correct /
Incorrect

10

When the function realloc is called the contents of previously


allocated block are lost

Answer Sheet Section-I


Subject Title

Computing Fundamentals and


Programming

Date

09-Dec-2016

Subject Code

CIS-101

Time

10:30

Class

BS(CIS)-1st Semester 2016-2020

Duration

90 min

Student Name

Roll No

Sr.No.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

Answer (a, b, c
or d )

____________________
Signature of Student
Q-04 Write a recursive function which is declared below.

Marks[10]

int printArray(int A[],int size)


The function should recursively print all elements of the array starting from index 0, each
element should be printed on a new line. See sample output of the printArray call. Do not
change the name or arguments of the provided function declaration also you do not need to
write main function etc.
Answer:

Sample Output
int A[5]={1,2,3,4,5};
printArray(A,5);
1
2
3
4
5

Вам также может понравиться