INFORMATION TECHNOLOGY STUDENT ASSOCIATION
(ITSA) 2011-12
EVENT: PROGRAMMING AND DEBUGGING
Duration: 30 mins
N0.of questions: 25
1. In a function that receives variable number of arguments the fixed arguments passed to the
function can be at the end of argument list.
A. True B. False C. Maybe D.none
2. What will be the output of the program (sample.c) given below if it is executed from the
command line (turbo c under DOS)?
cmd> sample Good Morning
/* sample.c */
#include<stdio.h>
int main(int argc, char *argv[])
{
printf("%d %s", argc, argv[1]);
return 0;
}
A. 3 Good B. 2 Good C. Good Morning D. 3 Morning
3.Point out the error in the following program.
#include<stdio.h>
#include<stdarg.h>
int main()
{
void display(char *s, int num1, int num2, ...);
display("Hello", 4, 2, 12.5, 13.5, 14.5, 44.0);
return 0;
}
void display(char *s, int num1, int num2, ...)
{
double c;
char s;
va_list ptr;
va_start(ptr, s);
c = va_arg(ptr, double);
printf("%f", c);
}
}
A. Error: invalid arguments in function display() B. Error: too many parameters
C. Error: in va_start(ptr, s); D. No error
4. What will be the output of the program ?
#include<stdio.h>
#include<string.h>
int main()
{
char str[] = "GITAM\0\ITSA\0";
printf("%s\n", str);
return 0;
}
A. ITSA B . GITAM C . GITAM ITSA D. GITAM \0 ITSA
5. Which header file should be included to use functions like malloc() and calloc()?
A. memory.h B. stdlib.h C. string.h D. dos.h
6. What will be the output of the program ?
#include<stdio.h>
int main()
{
int a=250;
printf("%1d\n", a);
return 0;
}
A. 1250 B. 2 C. 50 D. 250
7. What will be the output of the program ?
#include<stdio.h>
int main()
{
printf("%c\n", ~('C'*-1));
return 0;
}
A) A B) B C) C D) D
8. A long double can be used if range of a double is not enough to accommodate a real number.
A. True B. False C. Maybe D. none
9. What will be the output of the program in Turbo C (under DOS)?
#include<stdio.h>
int main()
{
struct emp
{
char *n;
int age;
};
struct emp e1 = {"Dravid", 23};
struct emp e2 = e1;
strupr(e2.n);
printf("%s\n", e1.n);
return 0;
}
A. Error: Invalid structure assignment B. DRAVID
C. Dravid D. No output
10. When we dynamically allocate memory is there any way to free memory during run time?
A. free() B . malloc() C. calloc() D. cannot
11. What will be the output of the program?
#include<stdio.h>
int main()
{
char far *near *ptr1;
char far *far *ptr2;
char far *huge *ptr3;
printf("%d, %d, %d\n", sizeof(ptr1), sizeof(ptr2), sizeof(ptr3));
return 0;
}
A. 4, 4, 8 B. 4, 4, 4 C. 2, 4, 4 D. 2, 4, 8
12. Which statement is true?
A. Memory is reclaimed by calling Runtime.gc().
B. Objects are not collected if they are accessible from live threads.
C. An OutOfMemory error is only thrown if a single block of memory cannot be found that
…………………………is large enough for a particular requirement.
D. Objects that have finalize() methods always have their finalize() methods called before
…………………………the program ends.
13. Which statement is true?
A. Calling Runtime.gc() will cause eligible objects to be garbage collected.
B. The garbage collector uses a mark and sweep algorithm.
C. If an object can be accessed from a live thread, it can't be garbage collected.
D. If object 1 refers to object 2, then object 2 can't be garbage collected.
14. If the depth of a tree is 3 levels, then what is the Size of the Tree?
A. 4 B. 2 C. 8 D. 6
15. If a lot of elements from a matrix have a value of 0 then the matrix is ?
A. Diagonal matrix B. sparse matrix C. Symmetric matrix D. Euclidian Matrix
16. The complexity of bubble sort in best case?
A. O(n) B. log 2 n C . O(n-1) D. O(n2)
17. Depth First search is based on ----------
A. Linked List B. FIFO C. STACK D. Queue
18. What is the value of the local variable x at the end of main?
int x = 5;
int main(int argc, char** argv)
{
int x = x;
return 0;
}
A. 0 B. 5 C. undefined D. compile Time Error
19. What is the value of y at the end of main?
const int x = 5;
int main(int argc, char** argv)
{ int x[x];
int y = sizeof(x) / sizeof(int);
return 0;
}
A . 0 B. 5 C. 20 D. undefined
20. Which of the following variables can be accessed in foo's function try block handler?
void foo(int x) try
{
int y = 2;
throw 1;
}
catch(int e)
{
}
int main(int argc, char** argv)
{
foo(3);
return 0;}
A. x and y and e B. x and e C. y and e D. e
21. Given the assumptions in the comments, what values is printed for x?
int main(int argc, char** argv)
{
// assume result printed is 4
std::cout << sizeof(int) << std::endl;
int x = 0x1000;
x = x << 32;
std::cout << std::hex << x << std::endl;
return 0;
}
A. 0x00000000 B. 0xFFFFFFFF C. implementation defined D. undefined
22. What value gets printed by the program?
#include <iostream>
int main(int argc, char** argv)
{
int x;
x = 1, 2, 3;
std::cout << x << std::endl;
return 0;
}
A . 1 B. 2 C. 3 D. undefined
23. Which of the following statements are true?
1) Conversion functions of class A convert from
class A into another type
2) Conversion functions of class A are used to
convert from another given type into class A
3) Converting constructors must be callable with
a single argument
A. 1 only B. 2 only C. 2 and 3 D. 1 and 3
24. What is the maximum number of implicitly defined constructors that this struct will have?
struct A
{
A(A& a) { }
A(double d) {}
int val; };
A. 0 B. 1 C. 2 D. undefined
25. If you have an array of characters allocated with new. Which of the following is the best way to
modify the size of the array?
A. Use the realloc function from libc
B. Delete the existing array, then allocate a new array and copy the data from the old array to the
……..new array
C. Allocate a new array, copy the data from old array to the new array and then delete the old array
D . It is not possible to do such an operation in C++
ANSWERS :
1. b 11. c 21. d
2 . a 12. b 22. a
3 . c 13. c 23. d
4. b 14. c 24. a
5. b 15. b 25. c
6. d 16. d
7. b 17. c
8 . a 18. c
9 . b 19. b
10 a 20. b