Docsity

Computer science-2nd year course, Quizzes of Computer Science

Toggle sidebar
bg1
Birla Institute of Technology & Science, Pilani
Second Semester 2016-2017, CS F111 Computer Programming
Comprehensive Exam (Open Book) PART A Set X
Suggested time: 60 minutes 08/5/17, 3.00 - 5.00 PM Max. Marks: 44
NOTE: 1. There are 22 questions in Part A. Each question has exactly one answer correct and carry 2M.
2. There is no negative marking. Overwritten answers will not be rechecked.
3. For each question, write the correct option (A, B, C, or D) at the designated place on the back of this sheet.
4. In each question, choose the best option. Assume required header files are included in each given program.
ID
NAME
Q1. How many times
hello will be printed?
int main(void) {
int i,j,k;
for(i=1; i<=4;i++)
for(j=1;j<=i;j++)
for(k=1;k<=j;k++)
printf("hello\n");
return 0;
}
A) 4 B) 10
C) 20 D) 30
Q2. What is the output?
int main(void) {
char arr[][10] = {"Amit",
"Suresh" , "John" , "Smith"};
char *ptr[4]; int i;
for(i=0; i<=3; i++)
ptr[i] = arr[3-i];
printf("%s,%s",ptr[0], arr[0]);
return 0;
}
A) Smith,Amit B) Amit,Amit
C) Smith,Smith D)Runtime error
Q3. What is the output? Assume
arr[] begins at address 65686 and
size of integer is of 4 bytes.
int main(void) {
int arr[] = {12, 14, 15, 23, 45};
printf("%u,%u",arr+1,&arr+1);
return 0;
}
A) 65690,65702
B) 65687,65690
C) 65690,65710
D) 65690,65706
Q4. What is the output ?
void main() {
short int a=5; float b=10; short int *p;
p=&b;
printf("%u\t",p);
p++;
printf("%u",p);
}
A) Compilation error
B) The difference in printed addresses is
sizeof(short int)
C) The difference in printed addresses is
sizeof(float)
D) Segmentation fault run time error.
Q5.What is the output?
void fun(int x) {
if(x>1) {
fun(--x);
printf("%d",x);
fun(--x);
} }
void main() {
fun (4);
}
A) 1231 B) 1321
C) 1234 D) 4321
Q7. What is the output?
void main(void) {
int i = 0;
for(printf("A");printf("B");printf("C"))
{
for(printf("D");printf("E");printf("F"))
break;
if (i--) break;
}
} A) ABDECBFE B) ABDECBDE
C) ADCBD D) Infinite Loop
Q8 What is the output?
int main() {
union temp { int a, b;};
union temp t;
t.a=100;
t.b=200;
printf("%d",t.a);
return 0;
}
A) Compilation error B) 100
C) Run time error D) 200
Q9. Consider the given program:
If the given program is required to print the size
of array arr[], which of the following two statements
can be substituted in place of LINE1.
S1: int temp = (char*) ptr2 - (char*) ptr1;
S2: int temp = (ptr2 - ptr1) * sizeof(stu);
A) Only S1
B) Only S2
C) Any one of S1 or S2
D) Neither S1, nor S2
typedef struct {
int age;
float marks;
} stu;
int main() {
stu arr[5];
stu *ptr1 = arr;
stu *ptr2 = ptr1 + 5;
LINE1
printf ("%d",temp);
}
Q10. Which of the following doesn’t require traversal
of elements in a linked list, given a pointer to the first
node of the list?
A) Deleting an element at the end of a singly linked list
B) Deleting an element from the end of a linear doubly
linked list.
C) Inserting an element after the last element in a
circular doubly linked list.
D) Inserting an element at the end of a linear singly
linked list.
Q11. In C language, if
precedence of +
operator is higher than
* operator; and
operator + is right
associative, the value
of following expression
is:
E: 5 * 4 + 7 * 8 + 9
A) 225 B) 449
C) 85 D) 935
Q12. The decimal equivalent for the following IEEE
floating point number is:
1 10000000 10110000000000000000000
A) -1.175 B) -3.375 C) -1.6875
D) None of the above
Q14. Assuming 2's complement representation, if
X = (A3FD)16 and Y = (9CE)16, then (X+Y) in base 16
is:
A) F8DCB B) 8DCB C) DCB
D) None of the above
Q13. What is the output?
int main (void) {
enum tak {_2 , _3 , _4, _1};
enum cak {_5,_6,_7 };
float b;
int a;
a = _3*6/_7%(_1-1);
b = 2*(_3+_5);
printf ("a=%d b=%d\n",a,b);
}
A) a = 0 b = 1
B) a = 1 b = 0
C) Compile time error
D) None of the above
pf2

Partial preview of the text

Download Computer science-2nd year course and more Quizzes Computer Science in PDF only on Docsity!

Birla Institute of Technology & Science, Pilani

Second Semester 2016-2017, CS F111 Computer Programming

Comprehensive Exam (Open Book) PART A Set X

Suggested time: 60 minutes 08/5/17, 3.00 - 5.00 PM Max. Marks: 44

NOTE: 1. There are 22 questions in Part A. Each question has exactly one answer correct and carry 2M.

2. There is no negative marking. Overwritten answers will not be rechecked.

3. For each question, write the correct option (A, B, C, or D) at the designated place on the back of this sheet.

4. In each question, choose the best option. Assume required header files are included in each given program.

ID NAME

Q1. How many times hello will be printed? int main(void) { int i,j,k; for(i=1; i<=4;i++) for(j=1;j<=i;j++) for(k=1;k<=j;k++) printf("hello\n"); return 0; } A) 4 B) 10 C) 20 D) 30 Q2. What is the output? int main(void) { char arr[][10] = {"Amit", "Suresh" , "John" , "Smith"}; char *ptr[4]; int i; for(i=0; i<=3; i++) ptr[i] = arr[3-i]; printf("%s,%s",ptr[0], arr[0]); return 0; } A) Smith,Amit B) Amit,Amit C) Smith,Smith D)Runtime error

Q3. What is the output? Assume

arr[] begins at address 65686 and size of integer is of 4 bytes. int main(void) { int arr[] = {12, 14, 15, 23, 45}; printf("%u,%u",arr+1,&arr+1); return 0; } A) 65690, B) 65687, C) 65690 , D) 65690, Q4. What is the output? void main() { short int a=5; float b=10; short int p; p=&b; printf("%u\t",p); p++; printf("%u",p); } A) Compilation error B) The difference in printed addresses is sizeof(short int) C) The difference in printed addresses is sizeof(float) D) Segmentation fault run time error. Q5.What is the output? void fun(int x) { if(x>1) { fun(--x); printf("%d",x); fun(--x); } } void main() { fun (4); } A) 1231 B) 1321 C) 1234 D) 4321 Q6. What is the output? int main (void) { char c[] = "KATEWINCE"; char p =c; printf("%s", p+p[3]-p[1]) ; return (0); } A) INCE B) EWINCE C) WINCE D) None of the above Q7. What is the output? void main(void) { int i = 0; for(printf("A");printf("B");printf("C")) { for(printf("D");printf("E");printf("F")) break; if (i--) break; } } A) ABDECBFE B) ABDECBDE C) ADCBD D) Infinite Loop Q8 What is the output? int main() { union temp { int a, b;}; union temp t; t.a=100; t.b=200; printf("%d",t.a); return 0; } A) Compilation error B) 100 C) Run time error D) 200 Q 9. Consider the given program: If the given program is required to print the size of array arr[], which of the following two statements can be substituted in place of LINE1. S1: int temp = (char) ptr2 - (char) ptr1; S2: int temp = (ptr2 - ptr1) * sizeof(stu); A) Only S B) Only S C) Any one of S1 or S D) Neither S1, nor S typedef struct { int age; float marks; } stu; int main() { stu arr[5]; stu ptr1 = arr; stu ptr2 = ptr1 + 5; LINE printf ("%d",temp); } Q 10. Which of the following doesn’t require traversal** of elements in a linked list, given a pointer to the first node of the list? A) Deleting an element at the end of a singly linked list B) Deleting an element from the end of a linear doubly linked list. C) Inserting an element after the last element in a circular doubly linked list. D) Inserting an element at the end of a linear singly linked list. Q11. In C language, if precedence of + operator is higher than

  • operator; and operator + is right associative, the value of following expression is: E: 5 * 4 + 7 * 8 + 9 A) 225 B) 449 C) 85 D) 935 Q12. The decimal equivalent for the following IEEE floating point number is: 1 10000000 10110000000000000000000 A) - 1.175 B) - 3.375 C) - 1. D) None of the above Q1 4. Assuming 2's complement representation, if X = (A3FD) 16 and Y = (9CE) 16 , then (X+Y) in base 16 is: A) F8DCB B) 8DCB C) DCB D) None of the above Q1 3. What is the output? int main (void) { enum tak {_2 , _3 , _4, _1}; enum cak {_5,_6,_7 }; float b; int a; a = _36/_7%(_1-1); b = 2(_3+_5); printf ("a=%d b=%d\n",a,b); } A) a = 0 b = 1 B) a = 1 b = 0 C) Compile time error D) None of the above

Q. No. 1 2 3 4 5 6 7 8 9 10

Correct

Option

Q. No. 12 13 14 15 16 17 18 19 20 21

Correct

Option

Total Correct Answers: x 2 =

Q1 5. What is the output? void main() { char *str = "BITS Pilani"; char *str1 = "BITS PILANI"; if (strcmp(str, str1)<0) printf("LOWER"); else printf("UPPER"); } A) Nothing is printed B) UPPER C) LOWER D) Compilation error

Total Marks

Q19. What is the output? int a, b, c = 0; void foo (void); void main () { static int a = 1; foo(); a += 1; foo(); printf ( "%d %d ", a,b) ; } (A) 3 1 4 1 4 2 (B) 4 2 6 1 6 1 (C) 4 2 6 2 2 0 (D) 3 1 5 2 5 2

PART A Set X

ANSWER AREA (OPEN BOOK)

Write your answers legibly in the space

provided below.

RECHECK:

Q1 6. What is the output? char writeBackward(char s[], int n) { if (n == 0) return '\0'; writeBackward(s, n--); printf ("%c",s[n]); } void main() { writeBackward("BITS PILANI",11); } A) BITS PILANI B) Compile time error C) INALIP STIB D) Run time error Q1 7. What is the output? int main() { int i,j,k; for(i=1;i<=3;i++) { if(i%2==0) k=2; else k=1; for(j=1;j<=i;j++,k+=2) printf("%d", k); } return 0; }

A) 213

B) 124135

C) 124

D) None of the above. Q1 8. Convert the following from base 6 to base 8: (524) 6 = (?) 8 A) 304 B) 104 C) 404 D) None of the above Q2 1. The following program intends to find the median (in variable t) of n sorted elements stored in array arr. What should be replaced in place of C and S to achieve the task? void main() { int n, i; float t; scanf("%d",&n); int arr[n]; //assume arr[] is initialized here. if (C) S else t = arr[n/2]; printf ("Median = %f",t); } A) C: n%2== S: t = (arr[n/2] + arr[n/2+1])/2.0; B) C: (2n)%2 == 0 S: t = (arr[n/2] + arr[n/2+1])/2.0; C) C: n%2== S: t = (arr[n/2] + arr[n/2-1])/2.0; D) C: (2n)%2 == 0 S: t = (arr[n/2] + arr[n/2-1])/2.0; Q 20. Select the correct choice. void main() { typedef struct { int age; char name; } stu; stu amit; amit.age = 18; //LIN strcpy (amit.name, "amit"); //LIN printf ("%s %d",amit.name,amit.age); } A) Program prints amit 18 B) If amit 18 if to be printed, replace LIN 2 with: amit.name = "amit"; C) If amit 18 is to be printed, insert the following after LIN1 and before LIN2: amit.name= (char)malloc(5*sizeof(char)); D) Both (B) and (C) above. void foo (void) { static int a = 2; int b = 1; a += ++b; printf ("%d %d ", a,b); }

Q22. Which of the geometric patterns can be

best associated with the output of the following program. void main() { int i, j, rows; scanf("%d", &rows); for(i=1; i<=rows; i++) { for(j=1; j<=rows; j++) { if(i==1 || i==rows || j==1 || j==rows) printf("*"); else printf(" "); } //inner for loop printf("\n"); }//outer for loop } A) two vertical parallel lines B) two horizontal parallel lines C) hollow square D) hollow triangle