0% found this document useful (0 votes)
160 views

CS F111 Part A Solution

This document contains a comprehensive exam for a computer programming course. It includes 22 multiple choice questions covering topics like C programming, data structures, file I/O, and more. Students are instructed to choose the single best answer for each question and mark it on the answer sheet provided. The questions test concepts like output of code snippets, accessing array elements, function calls, and manipulating files.

Uploaded by

AJay
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
160 views

CS F111 Part A Solution

This document contains a comprehensive exam for a computer programming course. It includes 22 multiple choice questions covering topics like C programming, data structures, file I/O, and more. Students are instructed to choose the single best answer for each question and mark it on the answer sheet provided. The questions test concepts like output of code snippets, accessing array elements, function calls, and manipulating files.

Uploaded by

AJay
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Birla Institute of Technology & Science, Pilani

Second Semester 2015-2016, CS F111 Computer Programming


Comprehensive Exam (Open Book) PART A Set X
Suggested time: 60 minutes 08/5/16, 2.00 - 4.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.

ID NAM
E
Q1. What is the Q2. What is the output Q3. What is the output of
output of the of the following? the following program Q4. Choose the best option w.r.t.
following? union myunion{ void main () { the following program:
void pass (int a) { int age; int a[5] = { 5, 1, 15, void main() {
a = 20; char initial; 20, 25 }; enum day {A=6,
} }; int i, j, k = 1, m; G=7,M,C,I=11,F=3,K};
void main() { void main() { i = ++a[1]; enum day d1 = A;
int *n; union myunion u; j = a[1]++; printf ("%d",strcmp
*n = 10; u.age = 8; m = a[i++]; (d1,"A")); //Line 1
pass (*n); u.initial = 'R'; printf ("%d %d %d\n", int b = A + F * I / C % M;
printf ("%d",*n); printf("%d", i, j, m); printf ("%d",b); //Line 2
} u.age); } }
(A) 10 } (A) 2 2 1 (A) Line 1 prints 1 and Line 2
(B) 20 (A) 114 (B) 82 (B) 3 2 15 prints 9
(C) 2010 (C) 81 (C) 6 7 20 (B) Line 1 has an error and Line 2
Q5. What is the Q6. Given: Q8. What is the output?
output of the int arr[4][4]; Q7. The output of which int main(){
following? int *ptr = arr; statement (SA and/or SB) is int i;
void main() { What value should 50? for (i = 0; i < 10; ++i)
int ary[4] = {1, 2, be added to ptr to void main() { if ((i % 2) == 0)
3, 4}; reach the array int a[]={10, 20, 30, 40, printf("A");
int *p = ary + 3; location arr[2][2]. 50}; else if ((i % 3) == 0)
printf("%d\n", p[- Assume that integer char *p; printf("B");
2]); require 4 bytes. p= (char*) a; else printf("C");
} (A) 10 (B) 40 }
(A) 1 (C) 11 (D) 44 printf("%d",*((int*)p+4));// (A) AABCACABAC (B)
Q9.What
(B) 2 is the ABCABCABCB
SA
output?
(C) compilation errorQ10 Consider the Q11What is the Q12 What is the output?
struct rectangle following output? void main() {
{ int main() { char ch[] = "Jaipur";
declarations:
int len; int i = 0, j = 0, ch[0]='K';
struct test {
int wid; k=0; printf("%s, ", ch);
int num;
}; for (;k<1;k++) strcpy(ch,"Kanpur");
float j;
void call_me for (i; i < 2; i+ printf("%s", ch+1);
};
(struct rectangle +){ }
struct test
rect) { for (j = 0; j <
rect.len = 30; arr[5];
3; j++){ (A) Kaipur, Kanpur
rect.wid = 40; Which of the (B) Jaipur, Kanpur
} following four (C) Kaipur, anpur
printf("1");
int main() { statements (S1 to S4) break; (D) There is a syntax error.
struct rectangle is correct to access }
*ptr, r; element num in printf("2");
ptr = &r; Q13 What is the output if it is executed from the command line
arr[2]? }
r.len = 10; as follows? Assume myOutput is the output file.
(A) myOutput Mon Tues
S1: arr[2].num
r.wid = 20; cmd> myOutput Mon Tues Wed Wed (B)
S2: (arr+2).num
call_me (*ptr); void main(int argc, char *argv[]) { myOutput Mon Tues
S3: (arr+2) -> num
printf ("%d,%d", S4: *(arr + 6/3).num while(argc) (C) Wed Tues Mon
(*ptr).len, printf("%s", argv[--argc]); myOutput
(A) S1, S2
(*ptr).wid); } (D) Wed Tues Mon
(B) S1, S3
Q14. What is the Q15. What is the output, Q16. The desired Q17. What is the output?
output when recurse if user enters strings output of the
is called from "one", "two", and "three" following program is void main() {
main() ? ? 1cpe. Which is int i=0;
void recurse() { int main() { correct if-condition if(i==0) {
static int n = char *a[4]; int i = 0; for it? i=((5,(i=3)),i=1);
987654321; while(i < 3) { void main() { printf("%d",i);
if (n == 0) char b[50]; char c[4][4] = }
return; scanf(" %s", b); {{'c','s','f','1'}, else
printf ("%d",n a[i++] = b; {'1','1','c','o'}, printf("equal");
%10); } {'m','p','r','e'}, }
n /= 100; i = 0; {'e','x', 'a', 'm'}};
int a = n; while(i < 3) int i, j; (A) 1
recurse(); printf(" %s ", a[i+ for(i = 0; i < 4; i+ (B) 3
if (a!=0) +]); +) (C) 5
printf ("%d",a } for(j = 4-i; j >= (D) equal
%10); (A) one two three 0; j--)
} (B) ott if(---------)
(A) 135799753 (C) three three three
(B)
Q18. 1357913579 (D) one
Consider a non-empty one one Q19. Assuming file
singly Q20. What is the output?
linked list with odd number of nodes. small.text contains Bits void main() { /* Assume 2 byte
Node of the list contains integer (in Pilani, choose the correct integer*/
variable data) and address of next option. unsigned int i = 65536;
node (in variable next). What does the int main(){ while(i != 0)
following function do if head is the char ch; printf("%d,",++i);
address of the first node of the list? FILE *fp1,*fp2; }
void fun1(struct node* head) { fp1=fopen("small.text", (A) Infinite loop (B) 0 1
if(head->next == NULL) { "r"); 2 ... 65535
printf("%d ", head->data); fp2=fopen("big.text"," (C) 0, 1, 2, ... 32767, 32766, 32765,
Q21.Which statement match the
return; w"); below code?
} while((ch=fgetc(fp1)) ! void main() {
fun1(head->next->next); =EOF) int input; char output;
printf("%d ", head->data); fputc(toupper(ch),fp2); scanf("%d", &input);
} return 0; output = ((input % 3) == 0) +
(A)Prints data field of all nodes in } '0';
forward direction. printf("%c", output); }
(B)Prints data field of all nodes in (A) BITS PILANI will be (A) Prints 1 if the input number is
reverse order copied to file big.text file. divisible by 3
(C)Prints data field of alternate nodes (B) Runtime Error Otherwise prints nothing.
in forward direction. (C) Compiler Error (B) Prints 1 if the input number is
(D)Prints data field of alternate nodes (D) bITS pILANI will be divisible by 3
in reverse
Q22. Which oforder
the statements (S1 - S3) arecopied
correcttoabout
file big.text
the file. Otherwise prints 0
below declarations? PART A Set X
char *q = "James"; char p[] = "James"; ANSWER AREA (OPEN BOOK)
S1. There is no difference in the declarations and both Write your answers legibly in the space
serve the same purpose.
provided below.
S2. The base address of q can be changed, whereas of p
cannot be changed.

Q. No. 1 2 3 4 5 6 7 8 9 10 11
Correct D B B B B A B D A D B
Option

Q. No. 12 13 14 15 16 17 18 19 20 21 22
Correct C C A C B A D A D B D
Option

Total Correct Answers: x2 = RECHECK:


Total Marks

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy