Beruflich Dokumente
Kultur Dokumente
2
Data Structures
Aptitude
Data Structures Aptitude
1. What is data structure?
A data structure is a way of organizing data that considers not only the items
stored, but also their relationship to each other. Advance knowledge about the
relationship between data items allows designing of efficient algorithms for the
manipulation of data.
2. List out the areas in which data structures are applied extensively?
Compiler Design,
Operating System,
Database Management System,
Statistical analysis package,
Numerical Analysis,
Graphics,
Artificial Intelligence,
Simulation
3. What are the major data structures used in the following areas : RDBMS, Network
data model & Hierarchical data model.
RDBMS – Array (i.e. Array of structures)
Network data model – Graph
Hierarchical data model – Trees
4. If you are using C language to implement the heterogeneous linked list, what pointer
type will you use?
The heterogeneous linked list contains different data types in its nodes and we
need a link, pointer to connect them. It is not possible to use ordinary pointers for this. So
we go for void pointer. Void pointer is capable of storing pointer to any type as it is a
generic pointer type.
7. What are the notations used in Evaluation of Arithmetic Expressions using prefix and
postfix forms?
Polish and Reverse Polish notations.
(d) Deletion.
Using insertion we can perform insertion sort, using selection we can perform
selection sort, using exchange we can perform the bubble sort (and other similar sorting
methods). But no sorting method can be done just using deletion.
Null Branches
i ii iii iv v
In general:
If there are n nodes, there exist 2n-n different trees.
14. List out few of the applications that make use of Multilinked Structures?
Sparse matrix,
Index generation.
16. What is the type of the algorithm used in solving the 8 Queens problem?
Backtracking
18. What is the bucket size, when the overlapping and collision occur at same time?
One. If there is only one entry possible in the bucket, when the collision occurs,
there is no way to accommodate the colliding value. This results in the overlapping of
values.
19. Traverse the given tree using Inorder, Preorder and Postorder traversals.
5
Given tree:
A
B C
D E F G
H I J
Inorder : D H B E A F C I G J
Preorder: A B D H E C F G I J
Postorder: H D E B F I J G C A
20. There are 8, 15, 13, 14 nodes were there in 4 different trees. Which of them could
have formed a full binary tree?
15.
In general:
There are 2n-1 nodes in a full binary tree.
By the method of elimination:
Full binary trees contain odd number of nodes. So there cannot be full
binary trees with 8 or 14 nodes, so rejected. With 13 nodes you can form a complete
binary tree but not a full binary tree. So the correct answer is 15.
Note:
Full and Complete binary trees are different. All full binary trees are complete
binary trees but not vice versa.
21. In the given binary tree, using array you can store the node 4 at which location?
2 3
6 5
At location 6
1 2 3 - - 4 - - 5
where LCn means Left Child of node n and RCn means Right Child of node n
65 70 75 80 85 60 55 50 45
Sorting takes place from the pivot value, which is the first value of the given
elements, this is marked bold. The values at the left pointer and right pointer are indicated
using L and R respectively.
65 70L 75 80 85 60 55 50 45R
Since pivot is not yet changed the same process is continued after interchanging the
values at L and R positions
65 45 75 L 80 85 60 55 50 R 70
65 45 50 80 L 85 60 55 R 75 70
65 45 50 55 85 L 60 R 80 75 70
65 45 50 55 60 R 85 L 80 75 70
When the L and R pointers cross each other the pivot value is interchanged with the value
at right pointer. If the pivot is changed it means that the pivot has occupied its original
position in the sorted order (shown in bold italics) and hence two different arrays are
formed, one from start of the original array to the pivot position-1 and the other from
pivot position+1 to end.
60 L 45 50 55 R 65 85 L 80 75 70 R
55 L 45 50 R 60 65 70 R 80 L 75 85
50 L 45 R 55 60 65 70 80 L 75 R 85
7
In the next pass we get the sorted form of the array.
45 50 55 60 65 70 75 80 85
23. For the given graph, draw the DFS and BFS?
BFS: AXGHPEMYJ
DFS: AXHPEYMJG
24. Classify the Hashing Functions based on the various methods by which the key value
is found.
Direct method,
Subtraction method,
Modulo-Division method,
Digit-Extraction method,
Mid-Square method,
Folding method,
Pseudo-random method.
25. What are the types of Collision Resolution Techniques and the methods used in each
of the type?
Open addressing (closed hashing),
The methods used include:
Overflow block,
Closed addressing (open hashing)
The methods used include:
Linked list,
Binary tree…
26. In RDBMS, what is the efficient data structure used in the internal storage
representation?
8
B+ tree. Because in B+ tree, all the data is stored only in leaf nodes, that makes
searching easier. This corresponds to the records that shall be stored in leaf nodes.
27. Draw the B-tree of order 3 created by inserting the following data arriving in
sequence – 92 24 6 7 11 8 22 4 5 16 19 20 78
11 -
5 7 19 24
4 - 6 - 8 - 16 - 20 22 78 92
28.Of the following tree structure, which is, efficient considering space and
time complexities?
(a) Incomplete Binary Tree
(b) Complete Binary Tree
(c) Full Binary Tree
30. Does the minimum spanning tree of a graph give the shortest distance between any 2
specified nodes?
No.
Minimal spanning tree assures that the total weight of the tree is kept at its
minimum. But it doesn’t mean that the distance between any two nodes involved in the
minimum-spanning tree is minimum.
31. Convert the given graph with weighted edges to minimal spanning tree.
9
600
1 3 200
612
410 310
2985 5
400
2 4
1421
1 3
200
410 612 310
2 4 5
(a) Sequential
A * B - (C + D) * (P / Q)
* *
A B + /
10
C D P Q
35. For the following COBOL code, draw the Binary tree?
01 STUDENT_REC.
02 NAME.
03 FIRST_NAME PIC X(10).
03 LAST_NAME PIC X(10).
02 YEAR_OF_STUDY.
03 FIRST_SEM PIC XX.
03 SECOND_SEM PIC XX.
01
STUDENT_REC
02 02
NAME YEAR_OF_STUDY
03 03 03 03
FIRST_NAME LAST_NAME FIRST_SEM SECOND_SEM
11
C Aptitude
C Aptitude
Note : All the programs are tested under Turbo C/C++ compilers.
It is assumed that,
Programs run under DOS environment,
The underlying machine is an x86 system,
Program is compiled using Turbo C/C++ compiler.
The program output may depend on the information based on this assumptions
(for example sizeof(int) == 2 may be assumed).
1. void main()
{
int const * p=5;
printf("%d",++(*p));
}
Answer:
Compiler error: Cannot modify a constant value.
Explanation:
p is a pointer to a "constant integer". But we tried to change the value of
the "constant integer".
2. main()
{
char s[ ]="man";
int i;
for(i=0;s[ i ];i++)
printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);
}
Answer:
mmmm
aaaa
nnnn
Explanation:
s[i], *(i+s), *(s+i), i[s] are all different ways of expressing the same idea.
Generally array name is the base address for that array. Here s is the base address. i is the
12
index number/displacement from the base address. So, indirecting it with * is same as
s[i]. i[s] may be surprising. But in the case of C it is same as s[i].
3. main()
{
float me = 1.1;
double you = 1.1;
if(me==you)
printf("I love U");
else
printf("I hate U");
}
Answer:
I hate U
Explanation:
For floating point numbers (float, double, long double) the values cannot
be predicted exactly. Depending on the number of bytes, the precession with of the value
represented varies. Float takes 4 bytes and long double takes 10 bytes. So float stores 0.9
with less precision than long double.
Rule of Thumb:
Never compare or at-least be cautious when using floating point numbers
with relational operators (== , >, <, <=, >=,!= ) .
4. main()
{
static int var = 5;
printf("%d ",var--);
if(var)
main();
}
Answer:
54321
Explanation:
When static storage class is given, it is initialized once. The change in the
value of a static variable is retained even between the function calls. Main is also treated
like any other ordinary function, which can be called recursively.
5. main()
{
int c[ ]={2.8,3.4,4,6.7,5};
int j,*p=c,*q=c;
for(j=0;j<5;j++) {
printf(" %d ",*c);
++q; }
for(j=0;j<5;j++){
printf(" %d ",*p);
++p; }
13
}
Answer:
2222223465
Explanation:
Initially pointer c is assigned to both p and q. In the first loop, since only
q is incremented and not c , the value 2 will be printed 5 times. In second loop p itself is
incremented. So the values 2 3 4 6 5 will be printed.
6. main()
{
extern int i;
i=20;
printf("%d",i);
}
Answer:
Linker Error : Undefined symbol '_i'
Explanation:
extern storage class in the following declaration,
extern int i;
specifies to the compiler that the memory for i is allocated in some other program and
that address will be given to the current program at the time of linking. But linker finds
that no other variable of name i is available in any other program with memory space
allocated for it. Hence a linker error has occurred .
7. main()
{
int i=-1,j=-1,k=0,l=2,m;
m=i++&&j++&&k++||l++;
printf("%d %d %d %d %d",i,j,k,l,m);
}
Answer:
00131
Explanation :
Logical operations always give a result of 1 or 0 . And also the logical
AND (&&) operator has higher priority over the logical OR (||) operator. So the
expression ‘i++ && j++ && k++’ is executed first. The result of this expression is 0
(-1 && -1 && 0 = 0). Now the expression is 0 || 2 which evaluates to 1 (because OR
operator always gives 1 except for ‘0 || 0’ combination- for which it gives 0). So the value
of m is 1. The values of other variables are also incremented by 1.
8. main()
{
char *p;
printf("%d %d ",sizeof(*p),sizeof(p));
14
}
Answer:
12
Explanation:
The sizeof() operator gives the number of bytes taken by its operand. P is a
character pointer, which needs one byte for storing its value (a character). Hence
sizeof(*p) gives a value of 1. Since it needs two bytes to store the address of the character
pointer sizeof(p) gives 2.
9. main()
{
int i=3;
switch(i)
{
default:printf("zero");
case 1: printf("one");
break;
case 2:printf("two");
break;
case 3: printf("three");
break;
}
}
Answer :
three
Explanation :
The default case can be placed anywhere inside the loop. It is executed
only when all other cases doesn't match.
10. main()
{
printf("%x",-1<<4);
}
Answer:
fff0
Explanation :
-1 is internally represented as all 1's. When left shifted four times the least
significant 4 bits are filled with 0's.The %x format specifier specifies that the integer
value be printed as a hexadecimal value.
11. main()
{
char string[]="Hello World";
display(string);
}
15
void display(char *string)
{
printf("%s",string);
}
Answer:
Compiler Error : Type mismatch in redeclaration of function display
Explanation :
In third line, when the function display is encountered, the compiler
doesn't know anything about the function display. It assumes the arguments and return
types to be integers, (which is the default type). When it sees the actual function display,
the arguments and type contradicts with what it has assumed previously. Hence a compile
time error occurs.
12. main()
{
int c=- -2;
printf("c=%d",c);
}
Answer:
c=2;
Explanation:
Here unary minus (or negation) operator is used twice. Same maths rules
applies, ie. minus * minus= plus.
Note:
However you cannot give like --2. Because -- operator can only be
applied to variables as a decrement operator (eg., i--). 2 is a constant and not a variable.
14. main()
{
int i=10;
i=!i>14;
Printf ("i=%d",i);
}
Answer:
i=0
16
Explanation:
In the expression !i>14 , NOT (!) operator has more precedence than ‘ >’
symbol. ! is a unary logical operator. !i (!10) is 0 (not of true is false). 0>14 is false
(zero).
15. #include<stdio.h>
main()
{
char s[]={'a','b','c','\n','c','\0'};
char *p,*str,*str1;
p=&s[3];
str=p;
str1=s;
printf("%d",++*p + ++*str1-32);
}
Answer:
77
Explanation:
p is pointing to character '\n'. str1 is pointing to character 'a' ++*p. "p is pointing
to '\n' and that is incremented by one." the ASCII value of '\n' is 10, which is then
incremented to 11. The value of ++*p is 11. ++*str1, str1 is pointing to 'a' that is
incremented by 1 and it becomes 'b'. ASCII value of 'b' is 98.
Now performing (11 + 98 – 32), we get 77("M");
So we get the output 77 :: "M" (Ascii is 77).
16. #include<stdio.h>
main()
{
int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} };
int *p,*q;
p=&a[2][2][2];
*q=***a;
printf("%d----%d",*p,*q);
}
Answer:
SomeGarbageValue---1
Explanation:
p=&a[2][2][2] you declare only two 2D arrays, but you are trying to
access the third 2D(which you are not declared) it will print garbage values. *q=***a
starting address of a is assigned integer pointer. Now q is pointing to starting address of a.
If you print *q, it will print first element of 3D array.
17. #include<stdio.h>
main()
17
{
struct xx
{
int x=3;
char name[]="hello";
};
struct xx *s;
printf("%d",s->x);
printf("%s",s->name);
}
Answer:
Compiler Error
Explanation:
You should not initialize variables in declaration
18. #include<stdio.h>
main()
{
struct xx
{
int x;
struct yy
{
char s;
struct xx *p;
};
struct yy *q;
};
}
Answer:
Compiler Error
Explanation:
The structure yy is nested within structure xx. Hence, the elements are of
yy are to be accessed through the instance of structure xx, which needs an instance of yy
to be known. If the instance is created after defining the structure the compiler will not
know about the instance relative to xx. Hence for nested structure yy you have to declare
member.
19. main()
{
printf("\nab");
printf("\bsi");
printf("\rha");
}
Answer:
hai
18
Explanation:
\n - newline
\b - backspace
\r - linefeed
20. main()
{
int i=5;
printf("%d%d%d%d%d%d",i++,i--,++i,--i,i);
}
Answer:
45545
Explanation:
The arguments in a function call are pushed into the stack from left to
right. The evaluation is by popping out from the stack. and the evaluation is from right to
left, hence the result.
22. main()
{
char *p="hai friends",*p1;
p1=p;
while(*p!='\0') ++*p++;
printf("%s %s",p,p1);
}
Answer:
ibj!gsjfoet
Explanation:
++*p++ will be parse in the given order
*p that is value at the location currently pointed by p will be taken
++*p the retrieved value will be incremented
when ; is encountered the location will be incremented that is p++ will be executed
19
Hence, in the while loop initial value pointed by p is ‘h’, which is changed to ‘i’ by
executing ++*p and pointer moves to point, ‘a’ which is similarly changed to ‘b’ and so
on. Similarly blank space is converted to ‘!’. Thus, we obtain value in p becomes
“ibj!gsjfoet” and since p reaches ‘\0’ and p1 points to p thus p1doesnot print anything.
25. main()
{
printf("%p",main);
}
Answer:
Some address will be printed.
Explanation:
20
Function names are just addresses (just like array names are addresses).
main() is also a function. So the address of function main will be printed. %p in printf
specifies that the argument is an address. They are printed as hexadecimal numbers.
27) main()
{
clrscr();
}
clrscr();
Answer:
No output/error
Explanation:
The first clrscr() occurs inside a function. So it becomes a function call. In
the second clrscr(); is a function declaration (because it is not inside any
function).
printf("%d..%d..%d",BLACK,BLUE,GREEN);
return(1);
}
Answer:
0..1..2
Explanation:
enum assigns numbers starting from 0, if not explicitly defined.
printf("%d..%d",sizeof(farther),sizeof(farthest));
}
Answer:
4..2
Explanation:
the second pointer is of char type and not a far pointer
30) main()
{
int i=400,j=300;
printf("%d..%d");
21
}
Answer:
400..300
Explanation:
printf takes the values of the first two assignments of the program. Any
number of printf's may be given. All of them take only the first two values.
If more number of assignments given in the program,then printf will take
garbage values.
31) main()
{
char *p;
p="Hello";
printf("%c\n",*&*p);
}
Answer:
H
Explanation:
* is a dereference operator & is a reference operator. They can be
applied any number of times provided it is meaningful. Here p points to
the first character in the string "Hello". *p dereferences it and so its value
is H. Again & references it to an address and * dereferences it to the value
H.
32) main()
{
int i=1;
while (i<=5)
{
printf("%d",i);
if (i>2)
goto here;
i++;
}
}
fun()
{
here:
printf("PP");
}
Answer:
Compiler error: Undefined label 'here' in function main
Explanation:
Labels have functions scope, in other words The scope of the labels is
limited to functions . The label 'here' is available in function fun() Hence it
is not visible in function main.
22
33) main()
{
static char names[5][20]={"pascal","ada","cobol","fortran","perl"};
int i;
char *t;
t=names[3];
names[3]=names[4];
names[4]=t;
for (i=0;i<=4;i++)
printf("%s",names[i]);
}
Answer:
Compiler error: Lvalue required in function main
Explanation:
Array names are pointer constants. So it cannot be modified.
36) #include<stdio.h>
main()
{
int i=1,j=2;
switch(i)
{
case 1: printf("GOOD");
break;
23
case j: printf("BAD");
break;
}
}
Answer:
Compiler Error: Constant expression required in function main.
Explanation:
The case statement can have only constant expressions (this implies that
we cannot use variable names directly so an error).
Note:
Enumerated types can be used in case statements.
37) main()
{
int i;
printf("%d",scanf("%d",&i)); // value 10 is given as input here
}
Answer:
1
Explanation:
Scanf returns number of items successfully read and not 1/0. Here 10 is
given as input which should have been scanned successfully. So number of
items read is 1.
39) main()
{
int i=0;
for(;i++;printf("%d",i)) ;
printf("%d",i);
}
Answer:
1
Explanation:
before entering into the for loop the checking condition is "evaluated".
Here it evaluates to 0 (false) and comes out of the loop, and i is
incremented (note the semicolon after the for loop).
24
40) #include<stdio.h>
main()
{
char s[]={'a','b','c','\n','c','\0'};
char *p,*str,*str1;
p=&s[3];
str=p;
str1=s;
printf("%d",++*p + ++*str1-32);
}
Answer:
M
Explanation:
p is pointing to character '\n'.str1 is pointing to character 'a' ++*p
meAnswer:"p is pointing to '\n' and that is incremented by one." the ASCII
value of '\n' is 10. then it is incremented to 11. the value of ++*p is 11.
++*str1 meAnswer:"str1 is pointing to 'a' that is incremented by 1 and it
becomes 'b'. ASCII value of 'b' is 98. both 11 and 98 is added and result is
subtracted from 32.
i.e. (11+98-32)=77("M");
41) #include<stdio.h>
main()
{
struct xx
{
int x=3;
char name[]="hello";
};
struct xx *s=malloc(sizeof(struct xx));
printf("%d",s->x);
printf("%s",s->name);
}
Answer:
Compiler Error
Explanation:
Initialization should not be done for structure members inside the structure
declaration
42) #include<stdio.h>
main()
{
struct xx
{
int x;
25
struct yy
{
char s;
struct xx *p;
};
struct yy *q;
};
}
Answer:
Compiler Error
Explanation:
in the end of nested structure yy a member have to be declared.
43) main()
{
extern int i;
i=20;
printf("%d",sizeof(i));
}
Answer:
Linker error: undefined symbol '_i'.
Explanation:
extern declaration specifies that the variable i is defined somewhere else.
The compiler passes the external variable to be resolved by the linker. So
compiler doesn't find an error. During linking the linker searches for the
definition of i. Since it is not found the linker flags an error.
44) main()
{
printf("%d", out);
}
int out=100;
Answer:
Compiler error: undefined symbol out in function main.
Explanation:
The rule is that a variable is available for use from the point of declaration.
Even though a is a global variable, it is not available for main. Hence an
error.
45) main()
{
extern out;
printf("%d", out);
}
int out=100;
Answer:
26
100
Explanation:
This is the correct way of writing the previous program.
46) main()
{
show();
}
void show()
{
printf("I'm the greatest");
}
Answer:
Compier error: Type mismatch in redeclaration of show.
Explanation:
When the compiler sees the function show it doesn't know anything about
it. So the default return type (ie, int) is assumed. But when compiler sees
the actual definition of show mismatch occurs since it is declared as void.
Hence the error.
The solutions are as follows:
1. declare void show() in main() .
2. define show() before main().
3. declare extern void show() before the use of show().
47) main( )
{
int a[2][3][2] = {{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}};
printf(“%u %u %u %d \n”,a,*a,**a,***a);
printf(“%u %u %u %d \n”,a+1,*a+1,**a+1,***a+1);
}
Answer:
100, 100, 100, 2
114, 104, 102, 3
Explanation:
The given array is a 3-D one. It can also be viewed as a 1-D array.
2 4 7 8 3 4 2 2 2 3 3 4
100 102 104 106 108 110 112 114 116 118 120 122
thus, for the first printf statement a, *a, **a give address of first element .
since the indirection ***a gives the value. Hence, the first line of the
output.
for the second printf a+1 increases in the third dimension thus points to
value at 114, *a+1 increments in second dimension thus points to 104, **a
27
+1 increments the first dimension thus points to 102 and ***a+1 first gets
the value at first location and then increments it by 1. Hence, the output.
48) main( )
{
int a[ ] = {10,20,30,40,50},j,*p;
for(j=0; j<5; j++)
{
printf(“%d” ,*a);
a++;
}
p = a;
for(j=0; j<5; j++)
{
printf(“%d ” ,*p);
p++;
}
}
Answer:
Compiler error: lvalue required.
Explanation:
Error is in line with statement a++. The operand must be an lvalue and
may be of any of scalar type for the any operator, array name only when
subscripted is an lvalue. Simply array name is a non-modifiable lvalue.
49) main( )
{
static int a[ ] = {0,1,2,3,4};
int *p[ ] = {a,a+1,a+2,a+3,a+4};
int **ptr = p;
ptr++;
printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr);
*ptr++;
printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr);
*++ptr;
printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr);
++*ptr;
printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr);
}
Answer:
111
222
333
344
Explanation:
28
Let us consider the array and the two pointers with some address
a
0 1 2 3 4
100 102 104 106 108
p
100 102 104 106 108
1000 1002 1004 1006 1008
ptr
1000
2000
After execution of the instruction ptr++ value in ptr becomes 1002, if
scaling factor for integer is 2 bytes. Now ptr – p is value in ptr – starting
location of array p, (1002 – 1000) / (scaling factor) = 1, *ptr – a = value at
address pointed by ptr – starting value of array a, 1002 has a value 102 so
the value is (102 – 100)/(scaling factor) = 1, **ptr is the value stored in
the location pointed by the pointer of ptr = value pointed by value pointed
by 1002 = value pointed by 102 = 1. Hence the output of the firs printf is
1, 1, 1.
After execution of *ptr++ increments value of the value in ptr by scaling
factor, so it becomes1004. Hence, the outputs for the second printf are ptr
– p = 2, *ptr – a = 2, **ptr = 2.
After execution of *++ptr increments value of the value in ptr by scaling
factor, so it becomes1004. Hence, the outputs for the third printf are ptr –
p = 3, *ptr – a = 3, **ptr = 3.
After execution of ++*ptr value in ptr remains the same, the value pointed
by the value is incremented by the scaling factor. So the value in array p at
location 1006 changes from 106 10 108,. Hence, the outputs for the fourth
printf are ptr – p = 1006 – 1000 = 3, *ptr – a = 108 – 100 = 4, **ptr = 4.
50) main( )
{
char *q;
int j;
for (j=0; j<3; j++) scanf(“%s” ,(q+j));
for (j=0; j<3; j++) printf(“%c” ,*(q+j));
for (j=0; j<3; j++) printf(“%s” ,(q+j));
}
Explanation:
Here we have only one pointer to type char and since we take input in the
same pointer thus we keep writing over in the same location, each time
shifting the pointer value by 1. Suppose the inputs are MOUSE, TRACK
and VIRTUAL. Then for the first input suppose the pointer starts at
location 100 then the input one is stored as
M O U S E \0
When the second input is given the pointer is incremented as j value
becomes 1, so the input is filled in memory starting from 101.
29
M T R A C K \0
The third input starts filling from the location 102
M T V I R T U A L \0
This is the final value stored .
The first printf prints the values at the position q, q+1 and q+2 = M T V
The second printf prints three strings starting from locations q, q+1, q+2
i.e MTVIRTUAL, TVIRTUAL and VIRTUAL.
51) main( )
{
void *vp;
char ch = ‘g’, *cp = “goofy”;
int j = 20;
vp = &ch;
printf(“%c”, *(char *)vp);
vp = &j;
printf(“%d”,*(int *)vp);
vp = cp;
printf(“%s”,(char *)vp + 3);
}
Answer:
g20fy
Explanation:
Since a void pointer is used it can be type casted to any other type pointer.
vp = &ch stores address of char ch and the next statement prints the value
stored in vp after type casting it to the proper data type pointer. the output
is ‘g’. Similarly the output from second printf is ‘20’. The third printf
statement type casts it to print the string from the 4 th value hence the
output is ‘fy’.
52) main ( )
{
static char *s[ ] = {“black”, “white”, “yellow”, “violet”};
char **ptr[ ] = {s+3, s+2, s+1, s}, ***p;
p = ptr;
**++p;
printf(“%s”,*--*++p + 3);
}
Answer:
ck
Explanation:
In this problem we have an array of char pointers pointing to start of 4
strings. Then we have ptr which is a pointer to a pointer of type char and a
variable p which is a pointer to a pointer to a pointer of type char. p hold
the initial value of ptr, i.e. p = s+3. The next statement increment value in
p by 1 , thus now value of p = s+2. In the printf statement the expression
30
is evaluated *++p causes gets value s+1 then the pre decrement is
executed and we get s+1 – 1 = s . the indirection operator now gets the
value from the array of s and adds 3 to the starting address. The string is
printed starting from this position. Thus, the output is ‘ck’.
53) main()
{
int i, n;
char *x = “girl”;
n = strlen(x);
*x = x[n];
for(i=0; i<n; ++i)
{
printf(“%s\n”,x);
x++;
}
}
Answer:
(blank space)
irl
rl
l
Explanation:
Here a string (a pointer to char) is initialized with a value “girl”. The
strlen function returns the length of the string, thus n has a value 4. The
next statement assigns value at the nth location (‘\0’) to the first location.
Now the string becomes “\0irl” . Now the printf statement prints the string
after each iteration it increments it starting position. Loop starts from 0 to
4. The first time x[0] = ‘\0’ hence it prints nothing and pointer value is
incremented. The second time it prints from x[1] i.e “irl” and the third
time it prints “rl” and the last time it prints “l” and the loop terminates.
54) int i,j;
for(i=0;i<=10;i++)
{
j+=5;
assert(i<5);
}
Answer:
Runtime error: Abnormal program termination.
assert failed (i<5), <file name>,<line number>
Explanation:
asserts are used during debugging to make sure that certain conditions are
satisfied. If assertion fails, the program will terminate reporting the same.
After debugging use,
#undef NDEBUG
31
and this will disable all the assertions from the source code. Assertion
is a good debugging tool to make use of.
55) main()
{
int i=-1;
+i;
printf("i = %d, +i = %d \n",i,+i);
}
Answer:
i = -1, +i = -1
Explanation:
Unary + is the only dummy operator in C. Where-ever it comes you can
just ignore it just because it has no effect in the expressions (hence the
name dummy operator).
56) What are the files which are automatically opened when a C file is executed?
Answer:
stdin, stdout, stderr (standard input,standard output,standard error).
Answer :
a: The SEEK_SET sets the file position marker to the starting of the file.
b: The SEEK_CUR sets the file position marker to the current position
of the file.
58) main()
{
char name[10],s[12];
scanf(" \"%[^\"]\"",s);
}
How scanf will execute?
Answer:
First it checks for the leading white space and discards it.Then it matches
with a quotation mark and then it reads all character upto another
quotation mark.
32
60) main()
{
main();
}
Answer:
Runtime error : Stack overflow.
Explanation:
main function calls itself again and again. Each time the function is called
its return address is stored in the call stack. Since there is no condition to
terminate the function call, the call stack overflows at runtime. So it
terminates the program and results in an error.
61) main()
{
char *cptr,c;
void *vptr,v;
c=10; v=0;
cptr=&c; vptr=&v;
printf("%c%v",c,v);
}
Answer:
Compiler error (at line number 4): size of v is Unknown.
Explanation:
You can create a variable of type void * but not of type void, since void is
an empty type. In the second line you are creating variable vptr of type
void * and v of type void hence an error.
62) main()
{
char *str1="abcd";
char str2[]="abcd";
printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd"));
}
Answer:
255
Explanation:
In first sizeof, str1 is a character pointer so it gives you the size of the
pointer variable. In second sizeof the name str2 indicates the name of the
array whose size is 5 (including the '\0' termination character). The third
sizeof is similar to the second one.
63) main()
{
char not;
not=!2;
33
printf("%d",not);
}
Answer:
0
Explanation:
! is a logical operator. In C the value 0 is considered to be the boolean
value FALSE, and any non-zero value is considered to be the boolean
value TRUE. Here 2 is a non-zero value so TRUE. !TRUE is FALSE (0)
so it prints 0.
65) main()
{
int k=1;
printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE");
}
Answer:
1==1 is TRUE
Explanation:
34
When two strings are placed together (or separated by white-space) they
are concatenated (this is called as "stringization" operation). So the string
is as if it is given as "%d==1 is %s". The conditional operator( ?: )
evaluates to "TRUE".
66) main()
{
int y;
scanf("%d",&y); // input given is 2000
if( (y%4==0 && y%100 != 0) || y%100 == 0 )
printf("%d is a leap year");
else
printf("%d is not a leap year");
}
Answer:
2000 is a leap year
Explanation:
An ordinary program to check if leap year or not.
35
printf("%d",i);
}
printf("%d",i);
}
printf("%d",i);
}
Answer:
30,20,10
Explanation:
'{' introduces new block and thus new scope. In the innermost block i is
declared as,
const volatile unsigned
which is a valid declaration. i is assumed of type int. So printf prints 30. In
the next block, i has value 20 and so printf prints 20. In the outermost
block, i is declared as extern, so no storage space is allocated for it. After
compilation is over the linker resolves it to global variable i (since it is the
only variable visible there). So it prints i's value as 10.
69) main()
{
int *j;
{
int i=10;
j=&i;
}
printf("%d",*j);
}
Answer:
10
Explanation:
The variable i is a block level variable and the visibility is inside that
block only. But the lifetime of i is lifetime of the function so it lives upto
the exit of main function. Since the i is still allocated space, *j prints the
value stored in i since j points i.
70) main()
{
int i=-1;
-i;
printf("i = %d, -i = %d \n",i,-i);
}
Answer:
i = -1, -i = 1
Explanation:
36
-i is executed and this execution doesn't affect the value of i. In printf first
you just print the value of i. After that the value of the expression -i = -(-1)
is printed.
71) #include<stdio.h>
main()
{
const int i=4;
float j;
j = ++i;
printf("%d %f", i,++j);
}
Answer:
Compiler error
Explanation:
i is a constant. you cannot change the value of constant
72) #include<stdio.h>
main()
{
int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} };
int *p,*q;
p=&a[2][2][2];
*q=***a;
printf("%d..%d",*p,*q);
}
Answer:
garbagevalue..1
Explanation:
p=&a[2][2][2] you declare only two 2D arrays. but you are trying to
access the third 2D(which you are not declared) it will print garbage
values. *q=***a starting address of a is assigned integer pointer. now q is
pointing to starting address of a.if you print *q meAnswer:it will print first
element of 3D array.
73) #include<stdio.h>
main()
{
register i=5;
char j[]= "hello";
printf("%s %d",j,i);
}
Answer:
hello 5
Explanation:
37
if you declare i as register compiler will treat it as ordinary integer and it
will take integer value. i value may be stored either in register or in
memory.
74) main()
{
int i=5,j=6,z;
printf("%d",i+++j);
}
Answer:
11
Explanation:
the expression i+++j is treated as (i++ + j)
38
{
pp=&origin;
printf("origin is(%d%d)\n",(*pp).x,(*pp).y);
printf("origin is (%d%d)\n",pp->x,pp->y);
}
Answer:
origin is(0,0)
origin is(0,0)
Explanation:
pp is a pointer to structure. we can access the elements of the structure
either with arrow mark or with indirection operator.
Note:
Since structure point is globally declared x & y are initialized as zeroes
78) main()
{
int i=_l_abc(10);
printf("%d\n",--i);
}
int _l_abc(int i)
{
return(i++);
}
Answer:
9
Explanation:
return(i++) it will first return i and then increments. i.e. 10 will be
returned.
79) main()
{
char *p;
int *q;
long *r;
p=q=r=0;
p++;
q++;
r++;
printf("%p...%p...%p",p,q,r);
}
Answer:
0001...0002...0004
Explanation:
++ operator when applied to pointers increments address according to
their corresponding data-types.
39
80) main()
{
char c=' ',x,convert(z);
getc(c);
if((c>='a') && (c<='z'))
x=convert(c);
printf("%c",x);
}
convert(z)
{
return z-32;
}
Answer:
Compiler error
Explanation:
declaration of convert and format of getc() are wrong.
40
Explanation:
ptr pointer is pointing to out of the array range of one_d.
83) # include<stdio.h>
aaa() {
printf("hi");
}
bbb(){
printf("hello");
}
ccc(){
printf("bye");
}
main()
{
int (*ptr[3])();
ptr[0]=aaa;
ptr[1]=bbb;
ptr[2]=ccc;
ptr[2]();
}
Answer:
bye
Explanation:
ptr is array of pointers to functions of return type int.ptr[0] is assigned to
address of the function aaa. Similarly ptr[1] and ptr[2] for bbb and ccc
respectively. ptr[2]() is in effect of writing ccc(), since ptr[2] points to ccc.
85) #include<stdio.h>
main()
{
FILE *ptr;
char i;
ptr=fopen("zzz.c","r");
while((i=fgetch(ptr))!=EOF)
printf("%c",i);
}
Answer:
contents of zzz.c followed by an infinite loop
Explanation:
The condition is checked against EOF, it should be checked against
NULL.
86) main()
{
int i =0;j=0;
41
if(i && j++)
printf("%d..%d",i++,j);
printf("%d..%d,i,j);
}
Answer:
0..0
Explanation:
The value of i is 0. Since this information is enough to determine the truth
value of the boolean expression. So the statement following the if
statement is not executed. The values of i and j remain unchanged and get
printed.
87) main()
{
int i;
i = abc();
printf("%d",i);
}
abc()
{
_AX = 1000;
}
Answer:
1000
Explanation:
Normally the return value from the function is through the information
from the accumulator. Here _AH is the pseudo global variable denoting
the accumulator. Hence, the value of the accumulator is set 1000 so the
function returns value 1000.
88) int i;
main(){
int t;
for ( t=4;scanf("%d",&i)-t;printf("%d\n",i))
printf("%d--",t--);
}
// If the inputs are 0,1,2,3 find the o/p
Answer:
4--0
3--1
2--2
Explanation:
Let us assume some x= scanf("%d",&i)-t the values during execution
will be,
t i x
4 0 -4
42
3 1 -2
2 2 0
89) main(){
int a= 0;int b = 20;char x =1;char y =10;
if(a,b,x,y)
printf("hello");
}
Answer:
hello
Explanation:
The comma operator has associativity from left to right. Only the
rightmost value is returned and the other values are evaluated and ignored.
Thus the value of last variable y is returned to check in if. Since it is a non
zero value if becomes true so, "hello" will be printed.
90) main(){
unsigned int i;
for(i=1;i>-2;i--)
printf("c aptitude");
}
Explanation:
i is an unsigned integer. It is compared with a signed value. Since the both
types doesn't match, signed is promoted to unsigned value. The unsigned
equivalent of -2 is a huge value so condition becomes false and control
comes out of the loop.
91) In the following pgm add a stmt in the function fun such that the address of
'a' gets stored in 'j'.
main(){
int * j;
void fun(int **);
fun(&j);
}
void fun(int **k) {
int a =0;
/* add a stmt here*/
}
Answer:
*k = &a
Explanation:
The argument of the function is a pointer to a pointer.
92) What are the following notations of defining functions known as?
i. int abc(int a,float b)
{
43
/* some code */
}
ii. int abc(a,b)
int a; float b;
{
/* some code*/
}
Answer:
i. ANSI C notation
ii. Kernighan & Ritche notation
93) main()
{
char *p;
p="%d\n";
p++;
p++;
printf(p-2,300);
}
Answer:
300
Explanation:
The pointer points to % since it is incremented twice and again
decremented by 2, it points to '%d\n' and 300 is printed.
94) main(){
char a[100];
a[0]='a';a[1]]='b';a[2]='c';a[4]='d';
abc(a);
}
abc(char a[]){
a++;
printf("%c",*a);
a++;
printf("%c",*a);
}
Explanation:
The base address is modified only in function and as a result a points to 'b'
then after incrementing to 'c' so bc will be printed.
95) func(a,b)
int a,b;
{
return( a= (a==b) );
}
main()
44
{
int process(),func();
printf("The value of process is %d !\n ",process(func,3,6));
}
process(pf,val1,val2)
int (*pf) ();
int val1,val2;
{
return((*pf) (val1,val2));
}
Answer:
The value if process is 0 !
Explanation:
The function 'process' has 3 parameters - 1, a pointer to another function 2
and 3, integers. When this function is invoked from main, the following
substitutions for formal parameters take place: func for pf, 3 for val1 and 6
for val2. This function returns the result of the operation performed by the
function 'func'. The function func has two integer parameters. The formal
parameters are substituted as 3 for a and 6 for b. since 3 is not equal to 6,
a==b returns 0. therefore the function returns 0 which in turn is returned
by the function 'process'.
45
return(ret);
}
Answer:
Here value is 7
Explanation:
The int ret(int ret), ie., the function name and the argument name can be
the same.
Firstly, the function ret() is called in which the sizeof(float) ie., 4 is
passed, after the first expression the value in ret will be 6, as ret is integer hence
the value stored in ret will have implicit type conversion from float to int. The ret
is returned in main() it is printed after and preincrement.
46
Ok here
Explanation:
Printf will return how many characters does it print. Hence printing
a null character returns 1 which makes the if statement true, thus
"Ok here" is printed.
47
Explanation:
Since static variables are initialized to zero by default.
104) main()
{
unsigned int i=10;
while(i-->=0)
printf("%u ",i);
}
Answer:
10 9 8 7 6 5 4 3 2 1 0 65535 65534…..
Explanation:
Since i is an unsigned integer it can never become negative. So the
expression i-- >=0 will always be true, leading to an infinite loop.
105) #include<conio.h>
main()
{
int x,y=2,z,a;
if(x=y%2) z=2;
a=2;
printf("%d %d ",z,x);
}
Answer:
Garbage-value 0
Explanation:
The value of y%2 is 0. This value is assigned to x. The condition reduces
to if (x) or in other words if(0) and so z goes uninitialized.
48
Thumb Rule: Check all control paths to write bug free code.
106) main()
{
int a[10];
printf("%d",*a+1-*a+3);
}
Answer:
4
Explanation:
*a and -*a cancels out. The result is as simple as 1 + 3 = 4 !
108) main()
{
unsigned int i=65000;
while(i++!=0);
printf("%d",i);
}
Answer:
1
Explanation:
Note the semicolon after the while statement. When the value of i becomes
0 it comes out of while loop. Due to post-increment on i the value of i
while printing is 1.
109) main()
{
int i=0;
while(+(+i--)!=0)
i-=i++;
printf("%d",i);
}
Answer:
-1
49
Explanation:
Unary + is the only dummy operator in C. So it has no effect on the
expression and now the while loop is, while(i--!=0) which is false
and so breaks out of while loop. The value –1 is printed due to the post-
decrement operator.
113) main()
{
float f=5,g=10;
enum{i=10,j=20,k=50};
printf("%d\n",++k);
printf("%f\n",f<<2);
printf("%lf\n",f%g);
printf("%lf\n",fmod(f,g));
}
Answer:
Line no 5: Error: Lvalue required
Line no 6: Cannot apply leftshift to float
Line no 7: Cannot apply mod to float
Explanation:
Enumeration constants cannot be modified, so you cannot apply ++.
Bit-wise operators and % operators cannot be applied on float values.
fmod() is to find the modulus values for floats as % operator is for ints.
110) main()
{
int i=10;
void pascal f(int,int,int);
f(i++,i++,i++);
printf(" %d",i);
}
void pascal f(integer :i,integer:j,integer :k)
{
write(i,j,k);
}
Answer:
Compiler error: unknown type integer
Compiler error: undeclared function write
Explanation:
Pascal keyword doesn’t mean that pascal code can be used. It means that
the function follows Pascal argument passing mechanism in calling the functions.
50
void cdecl f(int i,int j,int k)
{
printf(“%d %d %d”,i, j, k);
}
main()
{
int i=10;
f(i++,i++,i++);
printf(" %d\n",i);
i=10;
f(i++,i++,i++);
printf(" %d",i);
}
Answer:
10 11 12 13
12 11 10 13
Explanation:
Pascal argument passing mechanism forces the arguments to be called
from left to right. cdecl is the normal C argument passing mechanism where the
arguments are passed from right to left.
main()
{
signed char i=0;
for(;i>=0;i++) ;
printf("%d\n",i);
}
Answer
-128
Explanation
Notice the semicolon at the end of the for loop. THe initial value of
the i is set to 0. The inner loop executes to increment the value
from 0 to 127 (the positive range of char) and then it rotates to the
negative value of -128. The condition in the for loop fails and so
comes out of the for loop. It prints the current value of i that is
-128.
113) main()
{
unsigned char i=0;
for(;i>=0;i++) ;
printf("%d\n",i);
}
Answer
51
infinite loop
Explanation
The difference between the previous question and this one is that the char
is declared to be unsigned. So the i++ can never yield negative value and i>=0
never becomes false so that it can come out of the for loop.
114) main()
{
char i=0;
for(;i>=0;i++) ;
printf("%d\n",i);
}
Answer:
Behavior is implementation dependent.
Explanation:
The detail if the char is signed/unsigned by default is
implementation dependent. If the implementation treats the char to be
signed by default the program will print –128 and terminate. On the other
hand if it considers char to be unsigned by default, it goes to infinite loop.
Rule:
You can write programs that have implementation dependent
behavior. But dont write programs that depend on such behavior.
52
The name error is used in the two meanings. One means that it is a
enumerator constant with value 1. The another use is that it is a type name
(due to typedef) for enum errorType. Given a situation the compiler cannot
distinguish the meaning of error to know in what sense the error is used:
error g1;
g1=error;
// which error it refers in each case?
When the compiler can distinguish between usages then it will not
issue error (in pure technical terms, names can only be overloaded in
different namespaces).
Note: the extra comma in the declaration,
enum errorType{warning, error, exception,}
is not an error. An extra comma is valid and is provided just for
programmer’s convenience.
Answer
1
Explanation
The three usages of name errors can be distinguishable by the compiler at
any instance, so valid (they are in different namespaces).
Typedef struct error{int warning, error, exception;}error;
This error can be used only by preceding the error by struct kayword as in:
struct error someError;
typedef struct error{int warning, error, exception;}error;
This can be used only after . (dot) or -> (arrow) operator preceded by the variable
name as in :
g1.error =1;
printf("%d",g1.error);
typedef struct error{int warning, error, exception;}error;
This can be used to define variables without using the preceding struct keyword
as in:
error g1;
Since the compiler can perfectly distinguish between these three usages, it is
perfectly legal and valid.
Note
53
This code is given here to just explain the concept behind. In real
programming don’t use such overloading of names. It reduces the readability of
the code. Possible doesn’t mean that we should use it!
main()
{
int thing = 0;
printf("%d %d\n", some ,thing);
}
Answer:
Compiler error : undefined symbol some
Explanation:
This is a very simple example for conditional compilation. The
name something is not already known to the compiler making the
declaration
int some = 0;
effectively removed from the source code.
main()
{
int thing = 0;
printf("%d %d\n", some ,thing);
}
Answer
00
Explanation
This code is to show that preprocessor expressions are not the
same as the ordinary expressions. If a name is not known the
preprocessor treats it to be equal to zero.
main()
{
int arr2D[3][3];
printf("%d\n", ((arr2D==* arr2D)&&(* arr2D == arr2D[0])) );
54
}
Answer
1
Explanation
This is due to the close relation between the arrays and pointers. N
dimensional arrays are made up of (N-1) dimensional arrays.
The name arr2D refers to the beginning of all the 3 arrays. *arr2D
refers to the start of the first 1D array (of 3 integers) that is the
same address as arr2D. So the expression (arr2D == *arr2D) is true
(1).
Similarly, *arr2D is nothing but *(arr2D + 0), adding a zero
doesn’t change the value/meaning. Again arr2D[0] is the another
way of telling *(arr2D + 0). So the expression (*(arr2D + 0) ==
arr2D[0]) is true (1).
Since both parts of the expression evaluates to true the result is
true(1) and the same is printed.
55
{
int x=10,y=20;
swap(&x,&y);
printf("x= %d y = %d\n",x,y);
}
Answer
x = 20 y = 10
Explanation
This is one way of swapping two values. Simple checking will help
understand this.
123) main()
{
char *p = “ayqm”;
printf(“%c”,++*(p++));
}
Answer:
b
124) main()
{
int i=5;
printf("%d",++i++);
}
Answer:
Compiler error: Lvalue required in function main
Explanation:
++i yields an rvalue. For postfix ++ to operate an lvalue is
required.
125) main()
{
char *p = “ayqm”;
char c;
c = ++*p++;
printf(“%c”,c);
}
Answer:
b
Explanation:
There is no difference between the expression ++*(p++) and
++*p++. Parenthesis just works as a visual clue for the reader to
see which expression is first evaluated.
126)
int aaa() {printf(“Hi”);}
56
int bbb(){printf(“hello”);}
iny ccc(){printf(“bye”);}
main()
{
int ( * ptr[3]) ();
ptr[0] = aaa;
ptr[1] = bbb;
ptr[2] =ccc;
ptr[2]();
}
Answer:
bye
Explanation:
int (* ptr[3])() says that ptr is an array of pointers to functions that takes
no arguments and returns the type int. By the assignment ptr[0] = aaa; it
means that the first function pointer in the array is initialized with the
address of the function aaa. Similarly, the other two array elements also
get initialized with the addresses of the functions bbb and ccc. Since ptr[2]
contains the address of the function ccc, the call to the function ptr[2]() is
same as calling ccc(). So it results in printing "bye".
127)
main()
{
int i=5;
printf(“%d”,i=++i ==6);
}
Answer:
1
Explanation:
The expression can be treated as i = (++i==6), because == is of higher
precedence than = operator. In the inner expression, ++i is equal to 6
yielding true(1). Hence the result.
128) main()
{
char p[ ]="%d\n";
p[1] = 'c';
printf(p,65);
}
Answer:
A
Explanation:
57
Due to the assignment p[1] = ‘c’ the string becomes, “%c\n”. Since this
string becomes the format string for printf and ASCII value of 65 is ‘A’,
the same gets printed.
Answer::
abc is a ptr to a function which takes 2 parameters .(a). an integer
variable.(b). a ptrto a funtion which returns void. the return type of the
function is void.
Explanation:
Apply the clock-wise rule to find the result.
130) main()
{
while (strcmp(“some”,”some\0”))
printf(“Strings are not equal\n”);
}
Answer:
No output
Explanation:
Ending the string constant with \0 explicitly makes no difference. So
“some” and “some\0” are equivalent. So, strcmp returns 0 (false) hence
breaking out of the while loop.
131) main()
{
char str1[] = {‘s’,’o’,’m’,’e’};
char str2[] = {‘s’,’o’,’m’,’e’,’\0’};
while (strcmp(str1,str2))
printf(“Strings are not equal\n”);
}
Answer:
“Strings are not equal”
“Strings are not equal”
….
Explanation:
If a string constant is initialized explicitly with characters, ‘\0’ is not
appended automatically to the string. Since str1 doesn’t have null
termination, it treats whatever the values that are in the following positions
as part of the string until it randomly reaches a ‘\0’. So str1 and str2 are
not the same, hence the result.
132) main()
{
58
int i = 3;
for (;i++=0;) printf(“%d”,i);
}
Answer:
Compiler Error: Lvalue required.
Explanation:
As we know that increment operators return rvalues and hence it
cannot appear on the left hand side of an assignment operation.
135) main()
{
int i=10,j=20;
j = i, j?(i,j)?i:j:j;
printf("%d %d",i,j);
}
59
Answer:
10 10
Explanation:
The Ternary operator ( ? : ) is equivalent for if-then-else statement. So the
question can be written as:
if(i,j)
{
if(i,j)
j = i;
else
j = j;
}
else
j = j;
Answer:
1. 'const' applies to char * rather than 'a' ( pointer to a constant char )
*a='F' : illegal
a="Hi" : legal
3. Same as 1.
137) main()
{
int i=5,j=10;
i=i&=j&&10;
printf("%d %d",i,j);
}
Answer:
1 10
Explanation:
The expression can be written as i=(i&=(j&&10)); The inner expression
(j&&10) evaluates to 1 because j==10. i is 5. i = 5&1 is 1. Hence the
result.
60
138) main()
{
int i=4,j=7;
j = j || i++ && printf("YOU CAN");
printf("%d %d", i, j);
}
Answer:
41
Explanation:
The boolean expression needs to be evaluated only till the truth value of
the expression is not known. j is not equal to zero itself means that the
expression’s truth value is 1. Because it is followed by || and true ||
(anything) => true where (anything) will not be evaluated. So the
remaining expression is not evaluated and so the value of i remains the
same.
Similarly when && operator is involved in an expression, when any of the
operands become false, the whole expression’s truth value becomes false
and hence the remaining expression will not be evaluated.
false && (anything) => false where (anything) will not be evaluated.
139) main()
{
register int a=2;
printf("Address of a = %d",&a);
printf("Value of a = %d",a);
}
Answer:
Compier Error: '&' on register variable
Rule to Remember:
& (address of ) operator cannot be applied on register variables.
140) main()
{
float i=1.5;
switch(i)
{
case 1: printf("1");
case 2: printf("2");
default : printf("0");
}
}
Answer:
Compiler Error: switch expression not integral
Explanation:
61
Switch statements can be applied only to integral types.
141) main()
{
extern i;
printf("%d\n",i);
{
int i=20;
printf("%d\n",i);
}
}
Answer:
Linker Error : Unresolved external symbol i
Explanation:
The identifier i is available in the inner block and so using extern has no
use in resolving it.
142) main()
{
int a=2,*f1,*f2;
f1=f2=&a;
*f2+=*f2+=a+=2.5;
printf("\n%d %d %d",a,*f1,*f2);
}
Answer:
16 16 16
Explanation:
f1 and f2 both refer to the same memory location a. So changes through f1
and f2 ultimately affects only the value of a.
143) main()
{
char *p="GOOD";
char a[ ]="GOOD";
printf("\n sizeof(p) = %d, sizeof(*p) = %d, strlen(p) = %d", sizeof(p),
sizeof(*p), strlen(p));
printf("\n sizeof(a) = %d, strlen(a) = %d", sizeof(a), strlen(a));
}
Answer:
sizeof(p) = 2, sizeof(*p) = 1, strlen(p) = 4
sizeof(a) = 5, strlen(a) = 4
Explanation:
sizeof(p) => sizeof(char*) => 2
sizeof(*p) => sizeof(char) => 1
Similarly,
sizeof(a) => size of the character array => 5
62
When sizeof operator is applied to an array it returns the sizeof the array
and it is not the same as the sizeof the pointer variable. Here the sizeof(a)
where a is the character array and the size of the array is 5 because the
space necessary for the terminating NULL character should also be taken
into account.
146) main()
{
static int a[3][3]={1,2,3,4,5,6,7,8,9};
int i,j;
static *p[]={a,a+1,a+2};
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
printf("%d\t%d\t%d\t%d\n",*(*(p+i)+j),
63
*(*(j+p)+i),*(*(i+p)+j),*(*(p+j)+i));
}
}
Answer:
1 1 1 1
2 4 2 4
3 7 3 7
4 2 4 2
5 5 5 5
6 8 6 8
7 3 7 3
8 6 8 6
9 9 9 9
Explanation:
*(*(p+i)+j) is equivalent to p[i][j].
147) main()
{
void swap();
int x=10,y=8;
swap(&x,&y);
printf("x=%d y=%d",x,y);
}
void swap(int *a, int *b)
{
*a ^= *b, *b ^= *a, *a ^= *b;
}
Answer:
x=10 y=8
Explanation:
Using ^ like this is a way to swap two variables without using a temporary
variable and that too in a single statement.
Inside main(), void swap(); means that swap is a function that may take
any number of arguments (not no arguments) and returns nothing. So this
doesn’t issue a compiler error by the call swap(&x,&y); that has two
arguments.
This convention is historically due to pre-ANSI style (referred to as
Kernighan and Ritchie style) style of function declaration. In that style, the
swap function will be defined as follows,
void swap()
int *a, int *b
{
*a ^= *b, *b ^= *a, *a ^= *b;
}
64
where the arguments follow the (). So naturally the declaration for swap
will look like, void swap() which means the swap can take any number of
arguments.
148) main()
{
int i = 257;
int *iPtr = &i;
printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) );
}
Answer:
11
Explanation:
The integer value 257 is stored in the memory as, 00000001 00000001, so
the individual bytes are taken by casting it to char * and get printed.
149) main()
{
int i = 258;
int *iPtr = &i;
printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) );
}
Answer:
21
Explanation:
The integer value 257 can be represented in binary as, 00000001
00000001. Remember that the INTEL machines are ‘small-endian’
machines. Small-endian means that the lower order bytes are stored in the
higher memory addresses and the higher order bytes are stored in lower
addresses. The integer value 258 is stored in memory as: 00000001
00000010.
150) main()
{
int i=300;
char *ptr = &i;
*++ptr=2;
printf("%d",i);
}
Answer:
556
Explanation:
The integer value 300 in binary notation is: 00000001 00101100. It is
stored in memory (small-endian) as: 00101100 00000001. Result of the
expression *++ptr = 2 makes the memory representation as: 00101100
65
00000010. So the integer corresponding to it is 00000010 00101100 =>
556.
153) main()
{
struct student
{
char name[30];
struct date dob;
}stud;
struct date
{
int day,month,year;
};
scanf("%s%d%d%d", stud.rollno, &student.dob.day,
&student.dob.month, &student.dob.year);
}
Answer:
Compiler Error: Undefined structure date
Explanation:
Inside the struct definition of ‘student’ the member of type struct date is
given. The compiler doesn’t have the definition of date structure (forward
reference is not allowed in C in this case) so it issues an error.
66
154) main()
{
struct date;
struct student
{
char name[30];
struct date dob;
}stud;
struct date
{
int day,month,year;
};
scanf("%s%d%d%d", stud.rollno, &student.dob.day, &student.dob.month,
&student.dob.year);
}
Answer:
Compiler Error: Undefined structure date
Explanation:
Only declaration of struct date is available inside the structure definition
of ‘student’ but to have a variable of type struct date the definition of the
structure is required.
155) There were 10 records stored in “somefile.dat” but the following program printed
11 names. What went wrong?
void main()
{
struct student
{
char name[30], rollno[6];
}stud;
FILE *fp = fopen(“somefile.dat”,”r”);
while(!feof(fp))
{
fread(&stud, sizeof(stud), 1 , fp);
puts(stud.name);
}
}
Explanation:
fread reads 10 records and prints the names successfully. It will
return EOF only when fread tries to read another record and fails
reading EOF (and returning EOF). So it prints the last record
again. After this only the condition feof(fp) becomes false, hence
comes out of the while loop.
67
2. int foo(int *arr[2])
Answer:
No
Explanation:
Functions can only pass pointers and not arrays. The numbers that are
allowed inside the [] is just for more readability. So there is no difference
between the two declarations.
68
160) void main()
{
int *i = 0x400; // i points to the address 400
*i = 0; // set the value of memory location pointed by i;
}
Answer:
Undefined behavior
Explanation:
The second statement results in undefined behavior because it points to
some location whose value may not be available for modification. This
type of pointer in which the non-availability of the implementation of the
referenced location is known as 'incomplete type'.
void main()
{
int i = 10;
if(i==0)
assert(i < 100);
else
printf("This statement becomes else for if in assert macro");
}
Answer:
No output
Explanation:
The else part in which the printf is there becomes the else for if in the assert
macro. Hence nothing is printed.
The solution is to use conditional operator instead of if statement,
#define assert(cond) ((cond)?(0): (fprintf (stderr, "assertion failed: \ %s, file %s,
line %d \n",#cond, __FILE__,__LINE__), abort()))
Note:
However this problem of “matching with nearest else” cannot be solved
by the usual method of placing the if statement inside a block like this,
#define assert(cond) { \
if(!(cond)) \
(fprintf(stderr, "assertion failed: %s, file %s, line %d \n",#cond,\
__FILE__,__LINE__), abort()) \
}
69
{
int x;
struct a b;
}
Answer:
No
Explanation:
Is it not legal for a structure to contain a member that is of the same
type as in this case. Because this will cause the structure declaration to be
recursive without end.
70
Explanation:
The typename aType is known at the point of declaring the structure,
because it is already typedefined.
71
the charactes will be written past the input string. When fgets is used with
stdin performs the same operation as gets but is safe.
72
ptr = (int *) 0x400;
Answer:
Yes
Explanation:
The pointer ptr will point at the integer in the memory location 0x400.
173) main()
{
char a[4]="HELLO";
printf("%s",a);
}
Answer:
Compiler error: Too many initializers
Explanation:
The array a is of size 4 but the string constant requires 6 bytes to get
stored.
174) main()
{
char a[4]="HELL";
printf("%s",a);
}
Answer:
HELL%@!~@!@???@~~!
Explanation:
The character array has the memory just enough to hold the string
“HELL” and doesnt have enough space to store the terminating null
character. So it prints the HELL correctly and continues to print garbage
values till it accidentally comes across a NULL character.
175) main()
{
int a=10,*j;
void *k;
j=k=&a;
j++;
k++;
printf("\n %u %u ",j,k);
}
Answer:
Compiler error: Cannot increment a void pointer
Explanation:
Void pointers are generic pointers and they can be used only when the type
is not known and as an intermediate address storage type. No pointer
arithmetic can be done on it and you cannot apply indirection operator (*)
on void pointers.
73
176) main()
{
extern int i;
{ int i=20;
{
const volatile unsigned i=30; printf("%d",i);
}
printf("%d",i);
}
printf("%d",i);
}
int i;
74
puts(someFun2());
}
Answer:
Garbage values.
Explanation:
Both the functions suffer from the problem of dangling pointers. In someFun1()
temp is a character array and so the space for it is allocated in heap and is initialized with
character string “string”. This is created dynamically as the function is called, so is also
deleted dynamically on exiting the function so the string data is not available in the
calling function main() leading to print some garbage values. The function someFun2()
also suffers from the same problem but the problem can be easily identified in this case.
75
C++ Aptitude
and OOPS
1) class Sample
{
public:
int *ptr;
Sample(int i)
{
ptr = new int(i);
}
~Sample()
{
delete ptr;
}
void PrintVal()
{
cout << "The value is " << *ptr;
}
};
void SomeFunc(Sample x)
{
cout << "Say i am in someFunc " << endl;
}
int main()
{
Sample s1= 10;
SomeFunc(s1);
s1.PrintVal();
}
Answer:
76
Say i am in someFunc
Null pointer assignment(Run-time error)
Explanation:
As the object is passed by value to SomeFunc the destructor of the object is
called when the control returns from the function. So when PrintVal is called it meets up
with ptr that has been freed.The solution is to pass the Sample object by reference to
SomeFunc:
2) Which is the parameter that is added to every non-static member function when it is
called?
Answer:
‘this’ pointer
3) class base
{
public:
int bval;
base(){ bval=0;}
};
int main()
{
base BaseArr[5];
SomeFunc(BaseArr,5);
deri DeriArr[5];
SomeFunc(DeriArr,5);
77
}
Answer:
00000
01010
Explanation:
The function SomeFunc expects two arguments.The first one is a pointer to an
array of base class objects and the second one is the sizeof the array.The first call of
someFunc calls it with an array of bae objects, so it works correctly and prints the bval of
all the objects. When Somefunc is called the second time the argument passed is the
pointeer to an array of derived class objects and not the array of base class objects. But
that is what the function expects to be sent. So the derived class pointer is promoted to
base class pointer and the address is sent to the function. SomeFunc() knows nothing
about this and just treats the pointer as an array of base class objects. So when arr++ is
met, the size of base class object is taken into consideration and is incremented by
sizeof(int) bytes for bval (the deri class objects have bval and dval as members and so is
of size >= sizeof(int)+sizeof(int) ).
4) class base
{
public:
void baseFun(){ cout<<"from base"<<endl;}
};
class deri:public base
{
public:
void baseFun(){ cout<< "from derived"<<endl;}
};
void SomeFunc(base *baseObj)
{
baseObj->baseFun();
}
int main()
{
base baseObject;
SomeFunc(&baseObject);
deri deriObject;
SomeFunc(&deriObject);
}
Answer:
from base
from base
Explanation:
As we have seen in the previous case, SomeFunc expects a pointer to a base class.
Since a pointer to a derived class object is passed, it treats the argument only as a base
class pointer and the corresponding base function is called.
78
5) class base
{
public:
virtual void baseFun(){ cout<<"from base"<<endl;}
};
class deri:public base
{
public:
void baseFun(){ cout<< "from derived"<<endl;}
};
void SomeFunc(base *baseObj)
{
baseObj->baseFun();
}
int main()
{
base baseObject;
SomeFunc(&baseObject);
deri deriObject;
SomeFunc(&deriObject);
}
Answer:
from base
from derived
Explanation:
Remember that baseFunc is a virtual function. That means that it supports run-
time polymorphism. So the function corresponding to the derived class object is called.
void main()
{
int a, *pa, &ra;
pa = &a;
ra = a;
cout <<"a="<<a <<"*pa="<<*pa <<"ra"<<ra ;
}
/*
Answer :
Compiler Error: 'ra',reference must be initialized
Explanation :
Pointers are different from references. One of the main
differences is that the pointers can be both initialized and assigned,
whereas references can only be initialized. So this code issues an error.
*/
79
const int size = 5;
void print(int *ptr)
{
cout<<ptr[0];
}
void main()
{
int a[size] = {1,2,3,4,5};
int *b = new int(size);
print(a);
print(b);
}
/*
Answer:
Compiler Error : function 'void print(int *)' already has a body
Explanation:
Arrays cannot be passed to functions, only pointers (for arrays, base addresses)
can be passed. So the arguments int *ptr and int prt[size] have no difference
as function arguments. In other words, both the functoins have the same signature and
so cannot be overloaded.
*/
class some{
public:
~some()
{
cout<<"some's destructor"<<endl;
}
};
void main()
{
some s;
s.~some();
}
/*
Answer:
some's destructor
some's destructor
80
Explanation:
Destructors can be called explicitly. Here 's.~some()' explicitly calls the
destructor of 's'. When main() returns, destructor of s is called again,
hence the result.
*/
#include <iostream.h>
class fig2d
{
int dim1;
int dim2;
public:
fig2d() { dim1=5; dim2=6;}
void main()
{
fig2d obj1;
// fig3d obj2;
81
/*
Answer :
56
Explanation:
In this program, the << operator is overloaded with ostream as argument.
This enables the 'cout' to be present at the right-hand-side. Normally, 'cout'
is implemented as global function, but it doesn't mean that 'cout' is not possible
to be overloaded as member function.
Overloading << as virtual member function becomes handy when the class in which
it is overloaded is inherited, and this becomes available to be overrided. This is as
opposed
to global friend functions, where friend's are not inherited.
*/
class opOverload{
public:
bool operator==(opOverload temp);
};
void main(){
opOverload a1, a2;
a1= =a2;
}
Answer :
Runtime Error: Stack Overflow
Explanation :
Just like normal functions, operator functions can be called recursively. This
program just illustrates that point, by calling the operator == function recursively, leading
to an infinite loop.
class complex{
double re;
double im;
82
public:
complex() : re(1),im(0.5) {}
bool operator==(complex &rhs);
operator int(){}
};
int main(){
complex c1;
cout<< c1;
}
Explanation:
The programmer wishes to print the complex object using output
re-direction operator,which he has not defined for his lass.But the compiler instead of
giving an error sees the conversion function
and converts the user defined object to standard object and prints
some garbage value.
class complex{
double re;
double im;
public:
complex() : re(0),im(0) {}
complex(double n) { re=n,im=n;};
complex(int m,int n) { re=m,im=n;}
void print() { cout<<re; cout<<im;}
};
void main(){
complex c3;
double i=5;
c3 = i;
c3.print();
}
Answer:
83
5,5
Explanation:
Though no operator= function taking complex, double is defined, the double on
the rhs is converted into a temporary object using the single argument constructor taking
double and assigned to the lvalue.
void main()
{
int a, *pa, &ra;
pa = &a;
ra = a;
cout <<"a="<<a <<"*pa="<<*pa <<"ra"<<ra ;
}
Answer :
Compiler Error: 'ra',reference must be initialized
Explanation :
Pointers are different from references. One of the main
differences is that the pointers can be both initialized and assigned,
whereas references can only be initialized. So this code issues an error.
Try it Yourself
84
2) Justify the use of virtual constructors and destructors in C++.
3) Each C++ object possesses the 4 member fns,(which can be declared by the
programmer explicitly or by the implementation if they are not available). What are
those 4 functions?
7) Which is the only operator in C++ which can be overloaded but NOT inherited.
85
1. What is a modifier?
Answer:
A modifier, also called a modifying function is a member function that changes the
value of at least one data member. In other words, an operation that modifies the state of
an object. Modifiers are also known as ‘mutators’.
2. What is an accessor?
Answer:
An accessor is a class operation that does not modify the state of an object. The
accessor functions need to be declared as const operations
5. Define namespace.
Answer:
It is a feature in c++ to minimize name collisions in the global name space. This
namespace keyword assigns a distinct name to a library that allows other libraries to use
the same identifier names without creating any name collisions. Furthermore, the
compiler uses the namespace signature for differentiating the definitions.
86
forward iterators,
bidirectional iterators,
random access.
An iterator is an entity that gives access to the contents of a container object
without violating encapsulation constraints. Access to the contents is granted on a one-at-
a-time basis in order. The order can be storage order (as in lists and queues) or some
arbitrary order (as in array indices) or according to some ordering relation (as in an
ordered binary tree). The iterator is a construct, which provides an interface that, when
called, yields either the next element in the container, or some value denoting the fact that
there are no more elements to examine. Iterators hide the details of access to and update
of the elements of a container class.
The simplest and safest iterators are those that permit read-only access to the
contents of a container class. The following code fragment shows how an iterator might
appear in code:
cont_iter:=new cont_iterator();
x:=cont_iter.next();
while x/=none do
...
s(x);
...
x:=cont_iter.next();
end;
In this example, cont_iter is the name of the iterator. It is created on the first line by
instantiation of cont_iterator class, an iterator class defined to iterate over some container
class, cont. Succesive elements from the container are carried to x. The loop terminates
when x is bound to some empty value. (Here, none)In the middle of the loop, there is s(x)
an operation on x, the current element from the container. The next element of the
container is obtained at the bottom of the loop.
88
particular all class invariants are both preconditions and post-conditions for all operations
or member functions of the class.
Post-condition:
A post-condition is a condition that must be true on exit from a member function
if the precondition was valid on entry to that function. A class is implemented correctly if
post-conditions are never false.
For example, after pushing an element on the stack, we know that isempty() must
necessarily hold. This is a post-condition of the push operation.
19. What are the conditions that have to be met for a condition to be an invariant of the
class?
Answer:
The condition should hold at the end of every constructor.
The condition should hold at the end of every mutator(non-const) operation.
89
Array1D operator[] (int index);
const Array1D operator[] (int index) const;
...
};
Here data[3] yields an Array1D object and the operator [] invocation on that
object yields the float in position(3,6) of the original two dimensional array. Clients of the
Array2D class need not be aware of the presence of the Array1D class. Objects of this
latter class stand for one-dimensional array objects that, conceptually, do not exist for
clients of Array2D. Such clients program as if they were using real, live, two-dimensional
arrays. Each Array1D object stands for a one-dimensional array that is absent from a
conceptual model used by the clients of Array2D. In the above example, Array1D is a
proxy class. Its instances stand for one-dimensional arrays that, conceptually, do not
exist.
25. What is a container class? What are the types of container classes?
Answer:
A container class is a class that is used to hold objects in memory or external
storage. A container class acts as a generic holder. A container class has a predefined
behavior and a well-known interface. A container class is a supporting class whose
purpose is to hide the topology used for maintaining the list of objects in memory. When
a container class contains a group of mixed objects, the container is called a
heterogeneous container; when the container is holding a group of objects that are all the
same, the container is called a homogeneous container.
92
{
case 0: return 0;
case 1: abort();
case 2: current_operation.redo( );return 1;
}
};
A user of the Action class will be completely isolated from any knowledge of
derived classes such as write_file and error_message.
31. When can you tell that a memory leak will occur?
Answer:
A memory leak occurs when a program loses the ability to free a block of
dynamically allocated memory.
93
If the object has any pointers a deep copy needs to be executed. With the deep
copy of an object, memory is allocated for the object in free store and the elements
pointed to are copied. A deep copy is used for objects that are returned from a function.
X& operator *( );
const X& operator*( ) const;
X* operator->() const;
96
41. What is cloning?
Answer:
An object can carry out copying in two ways i.e. it can set itself to be a copy of
another object, or it can return a copy of itself. The latter process is called cloning.
43. Will the inline function be compiled as the inline function always? Justify.
Answer:
An inline function is a request and not a command. Hence it won't be compiled as
an inline function always.
Explanation:
Inline-expansion could fail if the inline function contains loops, the address of an
inline function is used, or an inline function is called in a complex expression. The rules
for inlining are compiler dependent.
44. Define a way other than using the keyword inline to make a function inline.
Answer:
The function must be defined inside the class.
OOAD
Diagram:
client server
(Active) (Passive)
99
Association: Its' just a semantic connection two classes.
e.g.:
uses
class A class B
Aggregation: Its' the relationship between two classes which are related in the fashion
that master and slave. The master takes full rights than the slave. Since the slave
works under the master. It is represented as line with diamond in the master area.
ex:
car contains wheels, etc.
car
car wheels
Containment: This relationship is applied when the part contained with in the whole
part, dies when the whole part dies.
It is represented as darked diamond at the whole part.
example:
class A{
//some code
};
class B
{
A aa; // an object of class A;
// some code for class B;
};
In the above example we see that an object of class A is instantiated with in the
class B. so the object class A dies when the object class B dies.we can represnt it in
diagram like this.
class A class B
class B class C
15. Whether unified method and unified modeling language are same or different?
Unified method is convergence of the Rumbaugh and Booch.
Unified modeling lang. is the fusion of Rumbaugh, Booch and Jacobson as well
as Betrand Meyer (whose contribution is "sequence diagram"). Its' the superset of all the
methodologies.
16. Who were the three famous amigos and what was their contribution to the object
community?
101
The Three amigos namely,
James Rumbaugh (OMT): A veteran in analysis who came up with an idea about the
objects and their Relationships (in particular Associations).
Grady Booch: A veteran in design who came up with an idea about partitioning of
systems into subsystems.
Ivar Jacobson (Objectory): The father of USECASES, who described about the user
and system interaction.
Booch: In this method classes are represented as "Clouds" which are not very easy
to draw as for as the developer's view is concern.
Diagram:
102
20. What is guard condition?
Guard condition is one, which acts as a firewall. The access from a particular
object can be made only when the particular condition is met.
For Example,
customer check customer number ATM.
Here the object on the customer accesses the ATM facility only when the guard condition
is met.
In the above representation I, obj1 sends message to obj2. But in the case of II the
data is transferred from obj1 to obj2.
22. USECASE is an implementation independent notation. How will the designer give the
implementation details of a particular USECASE to the programmer?
This can be accomplished by specifying the relationship called "refinement”
which talks about the two different abstraction of the same thing.
Or example,
23. Suppose a class acts an Actor in the problem domain, how to represent it in the static
model?
In this scenario you can use “stereotype”. Since stereotype is just a string that
gives extra semantic to the particular entity/model element. It is given with in the << >>.
class A
<< Actor>>
attributes
methods.
103
ex:
class person
{
public:
char getsex();
void setsex(char);
void setsex(int);
};
In the above example we see that there is a function setsex() with same name but
with different signature.
104
Quantitative
Aptitude
Quantitative Aptitude
Exercise 1
Solve the following and check with the answers given at the end.
1. It was calculated that 75 men could complete a piece of work in 20 days. When
work was scheduled to commence, it was found necessary to send 25 men to
another project. How much longer will it take to complete the work?
3. A dishonest shopkeeper professes to sell pulses at the cost price, but he uses a
false weight of 950gm. for a kg. His gain is …%.
4. A software engineer has the capability of thinking 100 lines of code in five
minutes and can type 100 lines of code in 10 minutes. He takes a break for five
minutes after every ten minutes. How many lines of codes will he complete typing
after an hour?
5. A man was engaged on a job for 30 days on the condition that he would get a
wage of Rs. 10 for the day he works, but he have to pay a fine of Rs. 2 for each
day of his absence. If he gets Rs. 216 at the end, he was absent for work for ...
days.
8. A man bought a horse and a cart. If he sold the horse at 10 % loss and the cart at
20 % gain, he would not lose anything; but if he sold the horse at 5% loss and the
cart at 5% gain, he would lose Rs. 10 in the bargain. The amount paid by him was
Rs._______ for the horse and Rs.________ for the cart.
105
9. A tennis marker is trying to put together a team of four players for a tennis
tournament out of seven available. males - a, b and c; females – m, n, o and p. All
players are of equal ability and there must be at least two males in the team. For a
team of four, all players must be able to play with each other under the following
restrictions:
b should not play with m,
c should not play with p, and
a should not play with o.
Which of the following statements must be false?
1. b and p cannot be selected together
2. c and o cannot be selected together
3. c and n cannot be selected together.
10-12. The following figure depicts three views of a cube. Based on this, answer
questions 10-12.
6 5 4
1 22 3 6
2 2 3
10. The number on the face opposite to the face carrying 1 is _______ .
11. The number on the faces adjacent to the face marked 5 are _______ .
12. Which of the following pairs does not correctly give the numbers on the opposite
faces.
(1) 6,5 (2) 4,1 (3) 1,3 (4) 4,2
13. Five farmers have 7, 9, 11, 13 & 14 apple trees, respectively in their orchards.
Last year, each of them discovered that every tree in their own orchard bore
exactly the same number of apples. Further, if the third farmer gives one apple to
the first, and the fifth gives three to each of the second and the fourth, they would
all have exactly the same number of apples. What were the yields per tree in the
orchards of the third and fourth farmers?
14. Five boys were climbing a hill. J was following H. R was just ahead of G. K was
between G & H. They were climbing up in a column. Who was the second?
15-18 John is undecided which of the four novels to buy. He is considering a spy
thriller, a Murder mystery, a Gothic romance and a science fiction novel. The
books are written by Rothko, Gorky, Burchfield and Hopper, not necessary in that
order, and published by Heron, Piegon, Blueja and sparrow, not necessary in that
order.
106
1 (1) The book by Rothko is published by Sparrow.
2 (2) The Spy thriller is published by Heron.
(3) The science fiction novel is by Burchfield and is not published by Blueja.
3 (4)The Gothic romance is by Hopper.
4
15. Pigeon publishes ____________.
17. John purchases books by the authors whose names come first and third in
alphabetical order. He does not buy the books ______.
18. On the basis of the first paragraph and statement (2), (3) and (4) only, it is
possible to deduce that
1. Rothko wrote the murder mystery or the spy thriller
2. Sparrow published the murder mystery or the spy thriller
3. The book by Burchfield is published by Sparrow.
19. If a light flashes every 6 seconds, how many times will it flash in ¾ of an hour?
20. If point P is on line segment AB, then which of the following is always true?
(1) AP = PB (2) AP > PB (3) PB > AP (4) AB > AP (5) AB > AP + PB
21. All men are vertebrates. Some mammals are vertebrates. Which of the following
conclusions drawn from the above statement is correct.
All men are mammals
All mammals are men
Some vertebrates are mammals.
None
22. Which of the following statements drawn from the given statements are correct?
Given:
All watches sold in that shop are of high standard. Some of the HMT watches are
sold in that shop.
a) All watches of high standard were manufactured by HMT.
b) Some of the HMT watches are of high standard.
c) None of the HMT watches is of high standard.
d) Some of the HMT watches of high standard are sold in that shop.
23-27.
1. Ashland is north of East Liverpool and west of Coshocton.
2. Bowling green is north of Ashland and west of Fredericktown.
3. Dover is south and east of Ashland.
4. East Liverpool is north of Fredericktown and east of Dover.
5. Fredericktown is north of Dover and west of Ashland.
6. Coshocton is south of Fredericktown and west of Dover.
107
23. Which of the towns mentioned is furthest of the north – west
(a) Ashland (b) Bowling green (c) Coshocton
(d) East Liverpool (e) Fredericktown
24. Which of the following must be both north and east of Fredericktown?
(a) Ashland (b) Coshocton (c) East Liverpool
I a only II b only III c only IV a & b Va&c
25. Which of the following towns must be situated both south and west of at least one
other town?
A. Ashland only
B. Ashland and Fredericktown
C. Dover and Fredericktown
D. Dover, Coshocton and Fredericktown
E. Coshocton, Dover and East Liverpool.
26. Which of the following statements, if true, would make the information in the
numbered statements more specific?
(a) Coshocton is north of Dover.
(b) East Liverpool is north of Dover
(c) Ashland is east of Bowling green.
(d) Coshocton is east of Fredericktown
(e) Bowling green is north of Fredericktown
27. Which of the numbered statements gives information that can be deduced from
one or more of the other statements?
(A) 1 (B) 2 (C) 3 (D) 4 (E) 6
28. Eight friends Harsha, Fakis, Balaji, Eswar, Dhinesh, Chandra, Geetha, and Ahmed
are sitting in a circle facing the center. Balaji is sitting between Geetha and
Dhinesh. Harsha is third to the left of Balaji and second to the right of Ahmed.
Chandra is sitting between Ahmed and Geetha and Balaji and Eshwar are not
sitting opposite to each other. Who is third to the left of Dhinesh?
29. If every alternative letter starting from B of the English alphabet is written in
small letter, rest all are written in capital letters, how the month “ September” be
written.
(1) SeptEMbEr (2) SEpTeMBEr (3) SeptembeR
(4) SepteMber (5) None of the above.
30. The length of the side of a square is represented by x+2. The length of the side of
an equilateral triangle is 2x. If the square and the equilateral triangle have equal
perimeter, then the value of x is _______.
108
31. It takes Mr. Karthik y hours to complete typing a manuscript. After 2 hours, he
was called away. What fractional part of the assignment was left incomplete?
34. There are 3 persons Sudhir, Arvind, and Gauri. Sudhir lent cars to Arvind and
Gauri as many as they had already. After some time Arvind gave as many cars to
Sudhir and Gauri as many as they have. After sometime Gauri did the same thing.
At the end of this transaction each one of them had 24. Find the cars each
originally had.
35. A man bought a horse and a cart. If he sold the horse at 10 % loss and the cart at
20 % gain, he would not lose anything; but if he sold the horse at 5% loss and the
cart at 5% gain, he would lose Rs. 10 in the bargain. The amount paid by him was
Rs._______ for the horse and Rs.________ for the cart.
Answers:
1. Answer:
30 days.
Explanation:
Before:
One day work = 1 / 20
One man’s one day work = 1 / ( 20 * 75)
Now:
No. Of workers = 50
One day work = 50 * 1 / ( 20 * 75)
The total no. of days required to complete the work = (75 * 20) / 50 = 30
2. Answer:
0%
Explanation:
Since 3x / 2 = x / (2 / 3)
3. Answer:
5.3 %
Explanation:
He sells 950 grams of pulses and gains 50 grams.
If he sells 100 grams of pulses then he will gain (50 / 950) *100 = 5.26
4. Answer:
250 lines of codes
109
5. Answer:
7 days
Explanation:
The equation portraying the given problem is:
10 * x – 2 * (30 – x) = 216 where x is the number of working days.
Solving this we get x = 23
Number of days he was absent was 7 (30-23) days.
6. Answer:
150 men.
Explanation:
One day’s work = 2 / (7 * 90)
One hour’s work = 2 / (7 * 90 * 8)
One man’s work = 2 / (7 * 90 * 8 * 75)
The remaining work (5/7) has to be completed within 60 days, because the
total number of days allotted for the project is 150 days.
We get x = 225
Since we have 75 men already, it is enough to add only 150 men.
7. Answer:
(c) 1
Explanation:
a percent of b : (a/100) * b
b percent of a : (b/100) * a
a percent of b divided by b percent of a : ((a / 100 )*b) / (b/100) * a )) = 1
8. Answer:
Cost price of horse = Rs. 400 & the cost price of cart = 200.
Explanation:-
Let x be the cost price of the horse and y be the cost price of the cart.
In the first sale there is no loss or profit. (i.e.) The loss obtained is equal to the
gain.
X = 2 * y -----------------(1)
In the second sale, he lost Rs. 10. (i.e.) The loss is greater than the profit by Rs.
10.
110
Therefore (5 / 100) * x = (5 / 100) * y + 10 -------(2)
Substituting (1) in (2) we get
(10 / 100) * y = (5 / 100) * y + 10
(5 / 100) * y = 10
y = 200
From (1) 2 * 200 = x = 400
9. Answer:
3.
Explanation:
Since inclusion of any male player will reject a female from the team.
Since there should be four member in the team and only three males are available,
the girl, n should included in the team always irrespective of others selection.
10. Answer:
5
11. Answer:
1,2,3 & 4
12. Answer:
B
13. Answer:
11 & 9 apples per tree.
Explanation:
Let a, b, c, d & e be the total number of apples bored per year in A, B, C,
D & E ‘s orchard. Given that a + 1 = b + 3 = c – 1 = d + 3 = e – 6
But the question is to find the number of apples bored per tree in C and D ‘s
orchard. If is enough to consider c – 1 = d + 3.
Since the number of trees in C’s orchard is 11 and that of D’s orchard is
13. Let x and y be the number of apples bored per tree in C & d ‘s orchard
respectively.
Therefore 11 x – 1 = 13 y + 3
By trial and error method, we get the value for x and y as 11 and 9
14. Answer:
G.
Explanation:
The order in which they are climbing is R – G – K – H – J
15 – 18
Answer:
Novel Name Author Publisher
Spy thriller Rathko Heron
111
Murder mystery Gorky Piegon
Gothic romance Burchfield Blueja
Science fiction Hopper Sparrow
Explanation:
Given
Novel Name Author Publisher
Spy thriller Rathko Heron
Murder mystery Gorky Piegon
Gothic romance Burchfield Blueja
Science fiction Hopper Sparrow
Since Blueja doesn’t publish the novel by Burchfield and Heron publishes
the novel spy thriller, Piegon publishes the novel by Burchfield.
Since Hopper writes Gothic romance and Heron publishes the novel spy
thriller, Blueja publishes the novel by Hopper.
Since Heron publishes the novel spy thriller and Heron publishes the novel
by Gorky, Gorky writes Spy thriller and Rathko writes Murder mystery.
19. Answer:
451 times.
Explanation:
There are 60 minutes in an hour.
In ¾ of an hour there are (60 * ¾) minutes = 45 minutes.
In ¾ of an hour there are (60 * 45) seconds = 2700 seconds.
Light flashed for every 6 seconds.
In 2700 seconds 2700/6 = 450 times.
The count start after the first flash, the light will flashes 451 times in ¾ of
an hour.
20. Answer:
(4)
Explanation:
P
A B
Since p is a point on the line segment AB, AB > AP
112
Ahmed
23 - 27.Answer:
Fakis Chandra
28. Answer: Fakis
Explanation: Harsha Geetha
Eswar Balaji
Dhinesh
29. Answer:
(5).
Explanation:
Since every alternative letter starting from B of the English alphabet is
written in small letter, the letters written in small letter are b, d, f...
In the first two answers the letter E is written in both small & capital
letters, so they are not the correct answers. But in third and fourth answers the
letter is written in small letter instead capital letter, so they are not the answers.
30. Answer:
x=4
Explanation:
Since the side of the square is x + 2, its perimeter = 4 (x + 2) = 4x + 8
Since the side of the equilateral triangle is 2x, its perimeter = 3 * 2x = 6x
Also, the perimeters of both are equal.
(i.e.) 4x + 8 = 6x
(i.e.) 2x = 8 x = 4.
31. Answer:
5 (y – 2) / y.
Explanation:
To type a manuscript karthik took y hours.
Therefore his speed in typing = 1/y.
He was called away after 2 hours of typing.
Therefore the work completed = 1/y * 2.
Therefore the remaining work to be completed = 1 – 2/y.
(i.e.) work to be completed = (y-2)/y
32. Answer:
(2)
33. Answer:
1
Explanation:
113
One is the only number exists without reciprocal because the reciprocal of
one is one itself.
34. Answer:
Sudhir had 39 cars, Arvind had 21 cars and Gauri had 12 cars.
Explanation:
Sudhir Arvind Gauri
Finally 24 24 24
Before Gauri’s transaction 12 12 48
Before Arvind’s transaction 6 42 24
Before Sudhir’ s transaction 39 21 12
35. Answer:
Cost price of horse: Rs. 400 &
Cost price of cart: Rs. 200
Explanation:
Let x be the cost of horse & y be the cost of the cart.
10 % of loss in selling horse = 20 % of gain in selling the cart
Therefore (10 / 100) * x = (20 * 100) * y
x = 2y -----------(1)
5 % of loss in selling the horse is 10 more than the 5 % gain in selling the
cart.
Therefore (5 / 100) * x - 10 = (5 / 100) * y
5x - 1000 = 5y
Substituting (1)
10y - 1000 = 5y
5y = 1000
y = 200
x = 400 from (1)
Exercise 2.1
For the following, find the next term in the series
Answer : a) 336
Explanation : The series is 1.2.3, 2.3.4, 3.4.5, 4.5.6, 5.6.7, ..... ( '.' means product)
2. 1, 5, 13, 25
Answer : 41
Explanation : The series is of the form 0^2+1^2, 1^2+2^2,...
114
3. 0, 5, 8, 17
Answer : 24
Explanation : 1^2-1, 2^2+1, 3^2-1, 4^2+1, 5^2-1
Answer : 216
Explanation : 1^2, 2^3, 3^2, 4^3, 5^2, 6^3
5. 8,24,12,36,18,54
Answer : 27
6. 71,76,69,74,67,72
Answer : 67
7. 5,9,16,29,54
Answer : 103
Explanation : 5*2-1=9; 9*2-2=16; 16*2-3=29; 29*2-4=54; 54*2-5=103
Exercise 2.2
1. 3,5,7,12,13,17,19
Answer : 12
Explanation : All but 12 are odd numbers
2. 2,5,10,17,26,37,50,64
Answer : 64
Explanation : 2+3=5; 5+5=10; 10+7=17; 17+9=26; 26+11=37; 37+13=50; 50+15=65;
3. 105,85,60,30,0,-45,-90
Answer : 0
Explanation : 105-20=85; 85-25=60; 60-30=30; 30-35=-5; -5-40=-45; -45-45=-90;
Exercise 3
Solve the following.
115
1. What is the number of zeros at the end of the product of the numbers from 1 to 100?
Answer : 127
2. A fast typist can type some matter in 2 hours and a slow typist can type the same in 3
hours. If both type combinely, in how much time will they finish?
Answer : 1 hr 12 min
Explanation : The fast typist's work done in 1 hr = 1/2
The slow typist's work done in 1 hr = 1/3
If they work combinely, work done in 1 hr = 1/2+1/3 = 5/6
So, the work will be completed in 6/5 hours. i.e., 1+1/5 hours = 1hr 12 min
3. Gavaskar's average in his first 50 innings was 50. After the 51st innings, his average
was 51. How many runs did he score in his 51st innings. (supposing that he lost his
wicket in his 51st innings)
Answer : 101
Explanation : Total score after 50 innings = 50*50 = 2500
Total score after 51 innings = 51*51 = 2601
So, runs made in the 51st innings = 2601-2500 = 101
If he had not lost his wicket in his 51st innings, he would have scored an
unbeaten 50 in his 51st innings.
4. Out of 80 coins, one is counterfeit. What is the minimum number of weighings needed
to find out the counterfeit coin?
Answer : 4
5. What can you conclude from the statement : All green are blue, all blue are red. ?
(i) some blue are green
(ii) some red are green
(iii) some green are not red
(iv) all red are blue
(a) i or ii but not both
(b) i & ii only
(c) iii or iv but not both
(d) iii & iv
Answer : (b)
6. A rectangular plate with length 8 inches, breadth 11 inches and thickness 2 inches is
available. What is the length of the circular rod with diameter 8 inches and equal to the
volume of the rectangular plate?
Answer : 3.5 inches
Explanation : Volume of the circular rod (cylinder) = Volume of the rectangular
plate
(22/7)*4*4*h = 8*11*2
h = 7/2 = 3.5
116
7. What is the sum of all numbers between 100 and 1000 which are divisible by 14 ?
Answer : 35392
Explanation : The number closest to 100 which is greater than 100 and divisible
by 14 is 112, which is the first term of the series which has to be summed.
The number closest to 1000 which is less than 1000 and divisible by 14 is
994, which is the last term of the series.
112 + 126 + .... + 994 = 14(8+9+ ... + 71) = 35392
8. If s(a) denotes square root of a, find the value of s(12+s(12+s(12+ ...... upto infinity.
Answer : 4
Explanation : Let x = s(12+s(12+s(12+.....
We can write x = s(12+x). i.e., x^2 = 12 + x. Solving this quadratic equation, we
get x = -3 or x=4. Sum cannot be -ve and hence sum = 4.
9. A cylindrical container has a radius of eight inches with a height of three inches.
Compute how many inches should be added to either the radius or height to give the same
increase in volume?
Answer : 16/3 inches
Explanation : Let x be the amount of increase. The volume will increase by the
same amount if the radius increased or the height is increased.
So, the effect on increasing height is equal to the effect on increasing the radius.
i.e., (22/7)*8*8*(3+x) = (22/7)*(8+x)*(8+x)*3
Solving the quadratic equation we get the x = 0 or 16/3. The possible increase
would be by 16/3 inches.
10. With just six weights and a balance scale, you can weigh any unit number of kgs from
1 to 364. What could be the six weights?
Answer : 1, 3, 9, 27, 81, 243 (All powers of 3)
11. Diophantus passed one sixth of his life in childhood, one twelfth in youth, and one
seventh more as a bachelor; five years after his marriage a son was born who died four
years before his father at half his final age. How old is Diophantus?
Answer : 84 years
Explanation : x/6 + x/12 + x/7 + 5 + x/2 + 4 = x
12 . If time at this moment is 9 P.M., what will be the time 23999999992 hours later?
Answer : 1 P.M.
Explanation : 24 billion hours later, it would be 9 P.M. and 8 hours before that it
would be 1 P.M.
13. How big will an angle of one and a half degree look through a glass that magnifies
things three times?
Answer : 1 1/2 degrees
Explanation : The magnifying glass cannot increase the magnitude of an angle.
117
14. Divide 45 into four parts such that when 2 is added to the first part, 2 is subtracted
from the second part, 2 is multiplied by the third part and the fourth part is divided by
two, all result in the same number.
Answer: 8, 12, 5, 20
Explanation: a + b + c + d =45; a+2 = b-2 = 2c = d/2; a=b-4; c = (b-2)/2; d =
2(b-2); b-4 + b + (b-2)/2 + 2(b-2) = 45;
16. Which of the following can act as interpreter if Mr. C & Mr. D wish to converse
a) only Mr. A b) Only Mr. B c) Mr. A & Mr. B d) Any of the other three
118
iv) French is 2
Italian & Spanish are spoken by the maximum no of executives. So, if the 6th
executive is fluent in Italian & Spanish, he can communicate with all the original five
because everybody knows either Spanish or Italian.
Exercise 3
Try the following.
1. There are seventy clerks working in a company, of which 30 are females. Also, 30
clerks are married; 24 clerks are above 25 years of age; 19 married clerks are
above 25 years, of which 7 are males; 12 males are above 25 years of age; and 15
males are married. How many bachelor girls are there and how many of these are
above 25?
2. A man sailed off from the North Pole. After covering 2,000 miles in one direction
he turned West, sailed 2,000 miles, turned North and sailed ahead another 2,000
miles till he met his friend. How far was he from the North Pole and in what
direction?
4. In a group of five people, what is the probability of finding two persons with the
same month of birth?
5. A father and his son go out for a 'walk-and-run' every morning around a track
formed by an equilateral triangle. The father's walking speed is 2 mph and his
119
running speed is 5 mph. The son's walking and running speeds are twice that of
his father. Both start together from one apex of the triangle, the son going
clockwise and the father anti-clockwise. Initially the father runs and the son walks
for a certain period of time. Thereafter, as soon as the father starts walking, the
son starts running. Both complete the course in 45 minutes. For how long does the
father run? Where do the two cross each other?
6. The Director of Medical Services was on his annual visit to the ENT Hospital.
While going through the out patients' records he came across the following data
for a particular day : " Ear consultations 45; Nose 50; Throat 70; Ear and Nose
30; Nose and Throat 20; Ear and Throat 30; Ear, Nose and Throat 10; Total
patients 100." Then he came to the conclusion that the records were bogus. Was
he right?
7. Amongst Ram, Sham and Gobind are a doctor, a lawyer and a police officer. They
are married to Radha, Gita and Sita (not in order). Each of the wives have a
profession. Gobind's wife is an artist. Ram is not married to Gita. The lawyer's
wife is a teacher. Radha is married to the police officer. Sita is an expert cook.
Who's who?
10. Which of the following groups of three can sit together on a bench?
(a) Freddy, Jonathan and Marta (b) Freddy, Jonathan and Vicky
(c) Freddy, Sarah and Vicky (d) Hillary, Lupe and Sarah
(e) Lupe, Marta and Roberto
11. If Freddy sits immediately beside Vicky, which of the following cannot be true ?
a. Jonathan sits immediately beside Sarah
b. Lupe sits immediately beside Vicky
c. Hillary sits in the front passenger seat
d. Freddy sits on the same bench as Hillary
120
e. Hillary sits on the same bench as Roberto
12. If Sarah sits on a bench that is behind where Jonathan is sitting, which of the
following must be true ?
a. Hillary sits in a seat or on a bench that is in front of where Marta is sitting
b. Lupe sits in a seat or on a bench that is in front of where Freddy is sitting
c. Freddy sits on the same bench as Hillary
d. Lupe sits on the same bench as Sarah
e. Marta sits on the same bench as Vicky
13. Make six squares of the same size using twelve match-sticks. (Hint : You will
need an adhesive to arrange the required figure)
14. A farmer has two rectangular fields. The larger field has twice the length and 4
times the width of the smaller field. If the smaller field has area K, then the are of
the larger field is greater than the area of the smaller field by what amount?
(a) 6K (b) 8K (c) 12K (d) 7K
15. Nine equal circles are enclosed in a square whose area is 36sq units. Find the area
of each circle.
16. There are 9 cards. Arrange them in a 3*3 matrix. Cards are of 4 colors. They are
red, yellow, blue, green. Conditions for arrangement: one red card must be in first
row or second row. 2 green cards should be in 3 rd column. Yellow cards must be in
the 3 corners only. Two blue cards must be in the 2nd row. At least one green card
in each row.
18. A speaks truth 70% of the time; B speaks truth 80% of the time. What is the
probability that both are contradicting each other?
19. In a family 7 children don't eat spinach, 6 don't eat carrot, 5 don't eat beans, 4
don't eat spinach & carrots, 3 don't eat carrot & beans, 2 don't eat beans &
spinach. One doesn't eat all 3. Find the no. of children.
20. Anna, Bena, Catherina and Diana are at their monthly business meeting. Their
occupations are author, biologist, chemist and doctor, but not necessarily in that
order. Diana just told the neighbour, who is a biologist that Catherina was on her
121
way with doughnuts. Anna is sitting across from the doctor and next to the
chemist. The doctor was thinking that Bena was a good name for parent's to
choose, but didn't say anything. What is each person's occupation?
122
UNIX Concepts
UNIX Concepts
SECTION - I
FILE MANAGEMENT IN UNIX
2. What is 'inode'?
All UNIX files have its description stored in a structure called 'inode'. The inode
contains info about the file-size, its location, time of last access, time of last modification,
permission and so on. Directories are also represented as files and have an associated
inode. In addition to descriptions about the file, the inode contains pointers to the data
blocks of the file. If the file is large, inode has indirect pointer to a block of pointers to
additional data blocks (this further aggregates for larger files). A block is typically 8k.
Inode consists of the following fields:
File owner identifier
File type
File access permissions
File access times
Number of links
File size
Location of the file data
124
7. What is a FIFO?
FIFO are otherwise called as 'named pipes'. FIFO (first-in-first-out) is a special
file which is said to be data transient. Once data is read from named pipe, it cannot be
read again. Also, data can be read only in the order written. It is used in interprocess
communication where a process writes to one end of the pipe (producer) and the other
reads from the other end (consumer).
8. How do you create special files like named pipes and device files?
The system call mknod creates special files in the following sequence.
1. kernel assigns new inode,
2. sets the file type to indicate that the file is a pipe, directory or special file,
3. If it is a device file, it makes the other entries like major, minor device numbers.
For example:
If the device is a disk, major device number refers to the disk controller and minor
device number is the disk.
SECTION - II
PROCESS MODEL and IPC
1. Brief about the initial process sequence while the system boots up.
While booting, special process called the 'swapper' or 'scheduler' is created with
125
Process-ID 0. The swapper manages memory allocation for processes and influences
CPU allocation. The swapper inturn creates 3 children:
the process dispatcher,
vhand and
dbflush
with IDs 1,2 and 3 respectively.
This is done by executing the file /etc/init. Process dispatcher gives birth to the
shell. Unix keeps track of all the processes in an internal data structure called the Process
Table (listing command is ps -el).
9. What is a zombie?
When a program forks and the child finishes before the parent, the kernel still
keeps some of its information about the child in case the parent might need it - for
example, the parent may need to check the child's exit status. To be able to get this
information, the parent calls `wait()'; In the interval between the child terminating and the
parent calling `wait()', the child is said to be a `zombie' (If you do `ps', the child will have
a `Z' in its status field to indicate this.)
127
environment for that program. This environment contains everything needed for the
system to run the program as if no other program were running on the system. Each
process has process context, which is everything that is unique about the state of the
program you are currently running. Every time you execute a program the UNIX system
does a fork, which performs a series of operations to create a process context and then
execute your program in that context. The steps include the following:
Allocate a slot in the process table, a list of currently running programs kept by
UNIX.
Assign a unique process identifier (PID) to the process.
iCopy the context of the parent, the process that requested the spawning of the new
process.
Return the new PID to the parent process. This enables the parent process to examine
or control the process directly.
After the fork is complete, UNIX runs your program.
Message Queues :
Message queues can be used between related and unrelated processes
running on a machine.
Shared Memory:
This is the fastest of all IPC schemes. The memory to be shared is mapped
into the address space of the processes (that are sharing). The speed achieved is
attributed to the fact that there is no kernel involvement. But this scheme needs
synchronization.
SECTION - III
MEMORY MANAGEMENT
129
Whole process is moved from the swap device to the main memory for
execution. Process size must be less than or equal to the available main memory. It is
easier to implementation and overhead to the system. Swapping systems does not handle
the memory more flexibly as compared to the paging systems.
Paging:
Only the required memory pages are moved to main memory from the
swap device for execution. Process size does not matter. Gives the concept of the virtual
memory.
It provides greater flexibility in mapping the virtual address space into the
physical memory of the machine. Allows more number of processes to fit in the main
memory simultaneously. Allows the greater process size than the available physical
memory. Demand paging systems handle the memory more flexibly.
2. What is major difference between the Historic Unix and the new BSD release of Unix
System V in terms of Memory Management?
Historic Unix uses Swapping – entire process is transferred to the main memory
from the swap device, whereas the Unix System V uses Demand Paging – only the part of
the process is moved to the main memory. Historic Unix uses one Swap Device and Unix
System V allow multiple Swap Devices.
4. What is a Map?
A Map is an Array, which contains the addresses of the free space in the swap
device that are allocatable resources, and the number of the resource units available there.
Address Units
1 10,000
5. What scheme does the Kernel in Unix System V follow while choosing a swap device
among the multiple swap devices?
Kernel follows Round Robin scheme choosing a swap device among the multiple
swap devices in Unix System V.
130
6. What is a Region?
A Region is a continuous area of a process’s address space (such as text, data and
stack). The kernel in a ‘Region Table’ that is local to the process maintains region.
Regions are sharable among the process.
7. What are the events done by the Kernel after a process is being swapped out from the
main memory?
When Kernel swaps the process out of the primary memory, it performs the
following:
Kernel decrements the Reference Count of each region of the process. If the
reference count becomes zero, swaps the region out of the main memory,
Kernel allocates the space for the swapping process in the swap device,
Kernel locks the other swapping process while the current swapping operation
is going on,
The Kernel saves the swap address of the region in the region table.
8. Is the Process before and after the swap are the same? Give reason.
Process before swapping is residing in the primary memory in its original form.
The regions (text, data and stack) may not be occupied fully by the process, there may be
few empty slots in any of the regions and while swapping Kernel do not bother about the
empty slots while swapping the process out.
After swapping the process resides in the swap (secondary memory) device. The
regions swapped out will be present but only the occupied region slots but not the empty
slots that were present before assigning.
While swapping the process once again into the main memory, the Kernel
referring to the Process Memory Map, it assigns the main memory accordingly taking
care of the empty slots in the regions.
10. What are the entities that are swapped out of the main memory while swapping the
process out of the main memory?
All memory space occupied by the process, process’s u-area, and Kernel stack are
swapped out, theoretically.
Practically, if the process’s u-area contains the Address Translation Tables for the
process then Kernel implementations do not swap the u-area.
131
12. What is Expansion swap?
At the time when any process requires more memory than it is currently allocated,
the Kernel performs Expansion swap. To do this Kernel reserves enough space in the
swap device. Then the address translation mapping is adjusted for the new virtual address
space but the physical memory is not allocated. At last Kernel swaps the process into the
assigned space in the swap device. Later when the Kernel swaps the process into the
main memory this assigns memory according to the new address translation mapping.
14. What are the processes that are not bothered by the swapper? Give Reason.
Zombie process: They do not take any up physical memory.
Processes locked in memories that are updating the region of the process.
Kernel swaps only the sleeping processes rather than the ‘ready-to-run’
processes, as they have the higher probability of being scheduled than the
Sleeping processes.
16. What are the criteria for choosing a process for swapping into memory from the swap
device?
The resident time of the processes in the swap device, the priority of the processes
and the amount of time the processes had been swapped out.
17. What are the criteria for choosing a process for swapping out of the memory to the
swap device?
The process’s memory resident time,
Priority of the process and
The nice value.
132
Only the administrator can supply the nice value. The nice () system call works
for the running process only. Nice value of one process cannot affect the nice value of the
other process.
19. What are conditions on which deadlock can occur while swapping the processes?
All processes in the main memory are asleep.
All ‘ready-to-run’ processes are swapped out.
There is no space in the swap device for the new incoming process that are
swapped out of the main memory.
There is no space in the main memory for the new incoming process.
25. What are data structures that are used for Demand Paging?
Kernel contains 4 data structures for Demand paging. They are,
Page table entries,
Disk block descriptors,
Page frame data table (pfdata),
Swap-use table.
133
Page address Age Copy on write Modify Reference Valid Protection
27.How the Kernel handles the fork() system call in traditional Unix and in the System V
Unix, while swapping?
Kernel in traditional Unix, makes the duplicate copy of the parent’s address space
and attaches it to the child’s process, while swapping. Kernel in System V Unix,
manipulates the region tables, page table, and pfdata table entries, by incrementing the
reference count of the region table of shared regions.
134
Page fault refers to the situation of not having a page in the main memory when
any process references it.
There are two types of page fault :
Validity fault,
Protection fault.
34.In what way the Fault Handlers and the Interrupt handlers are different?
Fault handlers are also an interrupt handler with an exception that the interrupt
handlers cannot sleep. Fault handlers sleep in the context of the process that caused the
memory fault. The fault refers to the running process and no arbitrary processes are put to
sleep.
36.What does the swapping system do if it identifies the illegal page for swapping?
If the disk block descriptor does not contain any record of the faulted page, then
this causes the attempted memory reference is invalid and the kernel sends a
“Segmentation violation” signal to the offending process. This happens when the
swapping system identifies any invalid memory reference.
37.What are states that the page can be in, after causing a page fault?
On a swap device and not in memory,
On the free page list in the main memory,
In an executable file,
Marked “demand zero”,
Marked “demand fill”.
41.How the Kernel handles the copy on write bit of a page, when the bit is set?
135
In situations like, where the copy on write bit of a page is set and that page is
shared by more than one process, the Kernel allocates new page and copies the content to
the new page and the other processes retain their references to the old page. After copying
the Kernel updates the page table entry with the new page number. Then Kernel
decrements the reference count of the old pfdata table entry.
In cases like, where the copy on write bit is set and no processes are sharing the
page, the Kernel allows the physical page to be reused by the processes. By doing so, it
clears the copy on write bit and disassociates the page from its disk copy (if one exists),
because other process may share the disk copy. Then it removes the pfdata table entry
from the page-queue as the new copy of the virtual page is not on the swap device. It
decrements the swap-use count for the page and if count drops to 0, frees the swap space.
44.How the Kernel handles both the page stealer and the fault handler?
The page stealer and the fault handler thrash because of the shortage of the
memory. If the sum of the working sets of all processes is greater that the physical
memory then the fault handler will usually sleep because it cannot allocate pages for a
process. This results in the reduction of the system throughput because Kernel spends too
much time in overhead, rearranging the memory in the frantic pace.
136
RDBMS Concepts
RDBMS Concepts
1. What is database?
A database is a logically coherent collection of data with some inherent meaning,
representing some aspect of real world and which is designed, built and populated with
data for a specific purpose.
2. What is DBMS?
It is a collection of programs that enables user to create and maintain a database.
In other words it is general-purpose software that provides the users with the processes of
defining, constructing and manipulating the database for various applications.
4. Advantages of DBMS?
Redundancy is controlled.
Unauthorised access is restricted.
Providing multiple user interfaces.
Enforcing integrity constraints.
Providing backup and recovery.
10. How is the data structure of System R different from the relational structure?
Unlike Relational systems in System R
Domains are not supported
Enforcement of candidate key uniqueness is optional
Enforcement of entity integrity is optional
Referential integrity is not enforced
138
Growth and restructuring of base tables is not reflected in views. Thus the view
can insulate users from the effects of restructuring and growth in the database. Hence
accounts for logical data independence.
139
23. What is degree of a Relation?
It is the number of attribute of its relation schema.
140
33. What is DDL Interpreter?
It interprets DDL statements and record them in tables containing metadata.
52. What are partial, alternate,, artificial, compound and natural key?
Partial Key:
It is a set of attributes that can uniquely identify weak entities and that are
related to same owner entity. It is sometime called as Discriminator.
Alternate Key:
All Candidate Keys excluding the Primary Key are known as Alternate
Keys.
Artificial Key:
If no obvious key, either stand alone or compound is available, then the
last resort is to simply create a key, by assigning a unique number to each record or
occurrence. Then this is known as developing an artificial key.
Compound Key:
If no single data element uniquely identifies occurrences within a
construct, then combining multiple elements to create a unique identifier for the construct
is known as creating a compound key.
Natural Key:
When one of the data elements stored within a construct is utilized as the
primary key, then it is called the natural key.
53. What is indexing and what are the different kinds of indexing?
Indexing is a technique for determining how quickly specific data can be found.
Types:
Binary search style indexing
B-Tree indexing
Inverted list indexing
Memory resident table
Table indexing
54. What is system catalog or catalog relation? How is better known as?
A RDBMS maintains a description of all the data that it contains, information
about every relation and index that it contains. This information is stored in a collection
of relations maintained by the system called metadata. It is also called data dictionary.
144
63. What is "transparent DBMS"?
It is one, which keeps its Physical Structure hidden from user.
67. What are the primitive operations common to all record management systems?
Addition, deletion and modification.
68. Name the buffer in which all the commands that are typed in are stored
‘Edit’ Buffer
70. Are the resulting relations of PRODUCT and JOIN operation the same?
No.
PRODUCT: Concatenation of every row in one relation with every row in
another.
JOIN: Concatenation of rows from one relation and related rows from another.
145
retrieving, and securing data. An RDBMS maintains its own list of authorized users and
their associated privileges; manages memory caches and paging; controls locking for
concurrent resource usage; dispatches and schedules user requests; and manages space
usage within its table-space structures
.
72. Name the sub-systems of a RDBMS
I/O, Security, Language Processing, Process Control, Storage Management,
Logging and Recovery, Distribution Control, Transaction Control, Memory Management,
Lock Management
73. Which part of the RDBMS takes care of the data dictionary? How
Data dictionary is a set of tables and database objects that is stored in a special
area of the database and maintained exclusively by the kernel.
77. Define SQL and state the differences between SQL and other conventional
programming Languages
SQL is a nonprocedural language that is designed specifically for data access
operations on normalized relational database structures. The primary difference between
SQL and other conventional programming languages is that SQL statements specify what
data operations should be performed rather than how to perform them.
78. Name the three major set of files on disk that compose a database in Oracle
There are three major sets of files on disk that compose a database. All the files
are binary. These are
Database files
Control files
Redo logs
The most important of these are the database files where the actual data resides.
The control files and the redo logs support the functioning of the architecture itself.
All three sets of files must be present, open, and available to Oracle for any data
on the database to be useable. Without these files, you cannot access the database, and the
database administrator might have to recover some or all of the database using a backup, if
there is one.
146
The Oracle system processes, also known as Oracle background processes,
provide functions for the user processes—functions that would otherwise be done by the
user processes themselves
Oracle database-wide system memory is known as the SGA, the system global
area or shared global area. The data and control structures in the SGA are shareable, and
all the Oracle background processes and user processes can use them.
The combination of
the SGA and the Oracle background processes is known as an Oracle instance
80. What are the four Oracle system processes that must always be up and running for
the database to be useable
The four Oracle system processes that must always be up and running for the
database to be useable include DBWR (Database Writer), LGWR (Log Writer), SMON
(System Monitor), and PMON (Process Monitor).
81. What are database files, control files and log files. How many of these files should a
database have at least? Why?
Database Files
The database files hold the actual data and are typically the largest in size.
Depending on their sizes, the tables (and other objects) for all the user accounts can go in
one database file—but that's not an ideal situation because it does not make the database
structure very flexible for controlling access to storage for different users, putting the
database on different disk drives, or backing up and restoring just part of the database.
You must have at least one database file but usually, more than one files
are used. In terms of accessing and using the data in the tables and other objects, the
number (or location) of the files is immaterial.
The database files are fixed in size and never grow bigger than the size at
which they were created
Control Files
The control files and redo logs support the rest of the architecture. Any
database must have at least one control file, although you typically have more than one to
guard against loss. The control file records the name of the database, the date and time it
was created, the location of the database and redo logs, and the synchronization
information to ensure that all three sets of files are always in step. Every time you add a
new database or redo log file to the database, the information is recorded in the control
files.
Redo Logs
147
Any database must have at least two redo logs. These are the journals for
the database; the redo logs record all changes to the user objects or system objects. If any
type of failure occurs, the changes recorded in the redo logs can be used to bring the
database to a consistent state without losing any committed transactions. In the case of
non-data loss failure, Oracle can apply the information in the redo logs automatically
without intervention from the DBA.
The redo log files are fixed in size and never grow dynamically from the
size at which they were created.
83. What is Oracle Block? Can two Oracle Blocks have the same address?
Oracle "formats" the database files into a number of Oracle blocks when they are
first created—making it easier for the RDBMS software to manage the files and easier to
read data into the memory areas.
The block size should be a multiple of the operating system block size. Regardless
of the block size, the entire block is not available for holding data; Oracle takes up some
space to manage the contents of the block. This block header has a minimum size, but it
can grow.
These Oracle blocks are the smallest unit of storage. Increasing the Oracle block
size can improve performance, but it should be done only when the database is first
created.
Each Oracle block is numbered sequentially for each database file starting at 1.
Two blocks can have the same block address if they are in different database files.
85. Name two utilities that Oracle provides, which are use for backup and recovery.
Along with the RDBMS software, Oracle provides two utilities that you can use
to back up and restore the database. These utilities are Export and Import.
148
The Export utility dumps the definitions and data for the specified part of the
database to an operating system binary file. The Import utility reads the file produced by
an export, recreates the definitions of objects, and inserts the data
If Export and Import are used as a means of backing up and recovering the
database, all the changes made to the database cannot be recovered since the export was
performed. The best you can do is recover the database to the time when the export was
last performed.
86. What are stored-procedures? And what are the advantages of using them.
Stored procedures are database objects that perform a user defined operation. A
stored procedure can have a set of compound SQL statements. A stored procedure
executes the SQL commands and returns the result to the client. Stored procedures are
used to reduce network traffic.
87. How are exceptions handled in PL/SQL? Give some of the internal exceptions' name
PL/SQL exception handling is a mechanism for dealing with run-time errors
encountered during procedure execution. Use of this mechanism enables execution to
continue if the error is not severe enough to cause procedure termination.
The exception handler must be defined within a subprogram specification. Errors
cause the program to raise an exception with a transfer of control to the exception-handler
block. After the exception handler executes, control returns to the block in which the
handler was defined. If there are no more executable statements in the block, control
returns to the caller.
User-Defined Exceptions
PL/SQL enables the user to define exception handlers in the declarations
area of subprogram specifications. User accomplishes this by naming an exception as in
the following example:
ot_failure EXCEPTION;
In this case, the exception name is ot_failure. Code associated with this handler is written
in the EXCEPTION specification area as follows:
EXCEPTION
when OT_FAILURE then
out_status_code := g_out_status_code;
out_msg := g_out_msg;
The following is an example of a subprogram exception:
EXCEPTION
when NO_DATA_FOUND then
g_out_status_code := 'FAIL';
RAISE ot_failure;
Within this exception is the RAISE statement that transfers control back to the ot_failure
exception handler. This technique of raising the exception is used to invoke all user-
defined exceptions.
System-Defined Exceptions
Exceptions internal to PL/SQL are raised automatically upon error.
NO_DATA_FOUND is a system-defined exception. Table below gives a complete list of
internal exceptions.
149
PL/SQL internal exceptions.
150
c) i & iii d) ii & iii
(a) i & iii because theta joins are joins made on keys that are not primary keys.
94. Select 'NORTH', CUSTOMER From CUST_DTLS Where REGION = 'N' Order By
CUSTOMER Union Select 'EAST', CUSTOMER From CUST_DTLS Where REGION
= 'E' Order By CUSTOMER
The above is
a) Not an error
b) Error - the string in single quotes 'NORTH' and 'SOUTH'
c) Error - the string should be in double quotes
d) Error - ORDER BY clause
(d) Error - the ORDER BY clause. Since ORDER BY clause cannot be used in
UNIONS
151
95. What is Storage Manager?
It is a program module that provides the interface between the low-level data
stored in database, application programs and queries submitted to the system.
103.What are Armstrong rules? How do we say that they are complete and/or sound
The well-known inference rules for FDs
Reflexive rule :
If Y is subset or equal to X then X Y.
Augmentation rule:
If X Y then XZ YZ.
Transitive rule:
If {X Y, Y Z} then X Z.
Decomposition rule :
If X YZ then X Y.
Union or Additive rule:
If {X Y, X Z} then X YZ.
Pseudo Transitive rule :
If {X Y, WY Z} then WX Z.
Of these the first three are known as Amstrong Rules. They are sound because it is
enough if a set of FDs satisfy these three. They are called complete because using these
three rules we can generate the rest all inference rules.
154
SQL
SQL
1.Which is the subset of SQL commands used to manipulate Oracle Database structures,
including tables?
Data Definition Language (DDL)
5.What is the parameter substitution symbol used with INSERT INTO command?
&
6.Which command displays the SQL command in the SQL buffer, and then executes it?
RUN
9.State true or false. !=, <>, ^= all denote the same operation.
True
10.What are the privileges that can be granted on a table by a user to others?
Insert, update, delete, select, references, index, execute, alter, all
11.What command is used to get back the privileges offered by the GRANT command?
REVOKE
13.Which system table contains information on constraints on all the tables created?
USER_CONSTRAINTS
16.What command is used to create a table by copying the structure of another table?
Answer :
CREATE TABLE .. AS SELECT command
Explanation :
To copy only the structure, the WHERE clause of the SELECT command should
contain a FALSE statement as in the following.
CREATE TABLE NEWTABLE AS SELECT * FROM EXISTINGTABLE
WHERE 1=2;
If the WHERE condition is true, then all the rows or rows satisfying the condition
will be copied to the new table.
20.Which date function is used to find the difference between two dates?
MONTHS_BETWEEN
156
21.Why does the following command give a compilation error?
DROP TABLE &TABLE_NAME;
Variable names should start with an alphabet. Here the table name starts with an
'&' symbol.
23.What is the use of the DROP option in the ALTER TABLE command?
It is used to drop constraints specified on the table.
24.What is the value of ‘comm’ and ‘sal’ after executing the following query if the initial
value of ‘sal’ is 10000?
UPDATE EMP SET SAL = SAL + 1000, COMM = SAL*0.1;
sal = 11000, comm = 1000
27.Which function is used to find the largest integer less than or equal to a specific
value?
FLOOR
SQL – QUERIES
157
I. SCHEMAS
Table 1 : STUDIES
Table 2 : SOFTWARE
Table 3 : PROGRAMMER
LEGEND :
PNAME – Programmer Name, SPLACE – Study Place, CCOST – Course Cost, DEVIN
– Developed in, SCOST – Software Cost, DCOST – Development Cost, PROF1 –
Proficiency 1
QUERIES :
1. Find out the selling cost average for packages developed in Oracle.
2. Display the names, ages and experience of all programmers.
3. Display the names of those who have done the PGDCA course.
4. What is the highest number of copies sold by a package?
5. Display the names and date of birth of all programmers born in April.
6. Display the lowest course fee.
7. How many programmers have done the DCA course.
8. How much revenue has been earned through the sale of packages developed in C.
9. Display the details of software developed by Rakesh.
10. How many programmers studied at Pentafour.
11. Display the details of packages whose sales crossed the 5000 mark.
12. Find out the number of copies which should be sold in order to recover the
development cost of each package.
13. Display the details of packages for which the development cost has been
recovered.
14. What is the price of costliest software developed in VB?
15. How many packages were developed in Oracle ?
16. How many programmers studied at PRAGATHI?
17. How many programmers paid 10000 to 15000 for the course?
18. What is the average course fee?
19. Display the details of programmers knowing C.
158
20. How many programmers know either C or Pascal?
21. How many programmers don’t know C and C++?
22. How old is the oldest male programmer?
23. What is the average age of female programmers?
24. Calculate the experience in years for each programmer and display along with
their names in descending order.
25. Who are the programmers who celebrate their birthdays during the current
month?
26. How many female programmers are there?
27. What are the languages known by the male programmers?
28. What is the average salary?
29. How many people draw 5000 to 7500?
30. Display the details of those who don’t know C, C++ or Pascal.
31. Display the costliest package developed by each programmer.
32. Produce the following output for all the male programmers
Programmer
Mr. Arvind – has 15 years of experience
KEYS:
159
20. SELECT * FROM PROGRAMMER WHERE PROF1 IN ('C','PASCAL') OR
PROF2 IN ('C','PASCAL');
21. SELECT * FROM PROGRAMMER WHERE PROF1 NOT IN ('C','C++') AND
PROF2 NOT IN ('C','C++');
22. SELECT TRUNC(MAX(MONTHS_BETWEEN(SYSDATE,DOB)/12)) FROM
PROGRAMMER WHERE SEX = 'M';
23. SELECT TRUNC(AVG(MONTHS_BETWEEN(SYSDATE,DOB)/12)) FROM
PROGRAMMER WHERE SEX = 'F';
24. SELECT PNAME, TRUNC(MONTHS_BETWEEN(SYSDATE,DOJ)/12) FROM
PROGRAMMER ORDER BY PNAME DESC;
25. SELECT PNAME FROM PROGRAMMER WHERE TO_CHAR(DOB,'MON') =
TO_CHAR(SYSDATE,'MON');
26. SELECT COUNT(*) FROM PROGRAMMER WHERE SEX = 'F';
27. SELECT DISTINCT(PROF1) FROM PROGRAMMER WHERE SEX = 'M';
28. SELECT AVG(SAL) FROM PROGRAMMER;
29. SELECT COUNT(*) FROM PROGRAMMER WHERE SAL BETWEEN 5000
AND 7500;
30. SELECT * FROM PROGRAMMER WHERE PROF1 NOT IN
('C','C++','PASCAL') AND PROF2 NOT IN ('C','C++','PASCAL');
31. SELECT PNAME,TITLE,SCOST FROM SOFTWARE WHERE SCOST IN
(SELECT MAX(SCOST) FROM SOFTWARE GROUP BY PNAME);
32.SELECT 'Mr.' || PNAME || ' - has ' ||
TRUNC(MONTHS_BETWEEN(SYSDATE,DOJ)/12) || ' years of experience'
“Programmer” FROM PROGRAMMER WHERE SEX = 'M' UNION SELECT
'Ms.' || PNAME || ' - has ' || TRUNC (MONTHS_BETWEEN
(SYSDATE,DOJ)/12) || ' years of experience' “Programmer” FROM
PROGRAMMER WHERE SEX = 'F';
II . SCHEMA :
Table 1 : DEPT
Table 2 : EMP
MGR is the empno of the employee whom the employee reports to. DEPTNO is a foreign
key.
QUERIES
160
1.List all the employees who have at least one person reporting to them.
2.List the employee details if and only if more than 10 employees are present in
department no 10.
3.List the name of the employees with their immediate higher authority.
4.List all the employees who do not manage any one.
5.List the employee details whose salary is greater than the lowest salary of an employee
belonging to deptno 20.
6.List the details of the employee earning more than the highest paid manager.
7.List the highest salary paid for each job.
8.Find the most recently hired employee in each department.
9.In which year did most people join the company? Display the year and the number of
employees.
10.Which department has the highest annual remuneration bill?
11.Write a query to display a ‘*’ against the row of the most recently hired employee.
12.Write a correlated sub-query to list out the employees who earn more than the
average salary of their department.
13.Find the nth maximum salary.
14.Select the duplicate records (Records, which are inserted, that already exist) in the
EMP table.
15.Write a query to list the length of service of the employees (of the form n years and m
months).
KEYS:
161
10.SELECT DEPTNO, LPAD(SUM(12*(SAL+NVL(COMM,0))),15)
"COMPENSATION" FROM EMP GROUP BY DEPTNO HAVING SUM(
12*(SAL+NVL(COMM,0))) = (SELECT MAX(SUM(12*(SAL+NVL(COMM,0))))
FROM EMP GROUP BY DEPTNO);
11.SELECT ENAME, HIREDATE, LPAD('*',8) "RECENTLY HIRED" FROM EMP
WHERE HIREDATE = (SELECT MAX(HIREDATE) FROM EMP) UNION SELECT
ENAME NAME, HIREDATE, LPAD(' ',15) "RECENTLY HIRED" FROM EMP
WHERE HIREDATE != (SELECT MAX(HIREDATE) FROM EMP);
12.SELECT ENAME,SAL FROM EMP E WHERE SAL > (SELECT AVG(SAL) FROM
EMP F WHERE E.DEPTNO = F.DEPTNO);
13.SELECT ENAME, SAL FROM EMP A WHERE &N = (SELECT COUNT
(DISTINCT(SAL)) FROM EMP B WHERE A.SAL<=B.SAL);
14.SELECT * FROM EMP A WHERE A.EMPNO IN (SELECT EMPNO FROM EMP
GROUP BY EMPNO HAVING COUNT(EMPNO)>1) AND A.ROWID!=MIN
(ROWID));
15.SELECT ENAME
"EMPLOYEE",TO_CHAR(TRUNC(MONTHS_BETWEEN(SYSDATE,HIREDATE)/1
2))||' YEARS '|| TO_CHAR(TRUNC(MOD(MONTHS_BETWEEN (SYSDATE,
HIREDATE),12)))||' MONTHS ' "LENGTH OF SERVICE" FROM EMP;
162
Computer
Networks
Computer Networks
1. What are the two types of transmission technology available?
(i) Broadcast and (ii) point-to-point
2. What is subnet?
A generic term for section of a large networks usually separated by a bridge or
router.
5. What is SAP?
Series of interface points that allow other computers to communicate with the
other layers of network protocol stack.
9. What is Beaconing?
The process that allows a network to self-repair networks problems. The stations
on the network notify the other stations on the ring when they are not receiving the
transmissions. Beaconing is used in Token ring and FDDI networks.
163
10. What is redirector?
Redirector is software that intercepts file or prints I/O requests and translates them
into network requests. This comes under presentation layer.
164
where N is no-of-bits represented by each signal shift.
27. What are the data units at different layers of the TCP / IP protocol suite?
The data unit created at the application layer is called a message, at the transport
layer the data unit created is called either a segment or an user datagram, at the network
layer the data unit created is called the datagram, at the data link layer the datagram is
encapsulated in to a frame and finally transmitted as signals along the transmission
media.
29. What is the minimum and maximum length of the header in the TCP segment and IP
datagram?
166
The header should have a minimum length of 20 bytes and can have a maximum
length of 60 bytes.
31. What is the difference between TFTP and FTP application layer protocols?
The Trivial File Transfer Protocol (TFTP) allows a local host to obtain files from
a remote host but does not provide reliability or security. It uses the fundamental packet
delivery services offered by UDP.
The File Transfer Protocol (FTP) is the standard mechanism provided by TCP / IP
for copying a file from one host to another. It uses the services offer by TCP and so is
reliable and secure. It establishes two connections (virtual circuits) between the hosts, one
for data transfer and another for control information.
STAR topology:
In this all computers are connected using a central hub.
Advantages:
Can be inexpensive, easy to install and reconfigure and easy to trouble
shoot physical problems.
RING topology:
In this all computers are connected in loop.
Advantages:
All computers have equal access to network media, installation can be
simple, and signal does not degrade as much as in other topologies because each
computer regenerates it.
167
34. What is mesh network?
A network in which there are multiple network links between computers to
provide multiple paths for data to travel.
38. What is the difference between routable and non- routable protocols?
Routable protocols can work with a router and can be used to build large
networks. Non-Routable protocols are designed to work on small, local networks and
cannot be used with a router
39. Why should you care about the OSI Reference Model?
It provides a framework for discussing network operations and design.
168
One of the main causes of congestion is that traffic is often busy. If hosts could be
made to transmit at a uniform rate, congestion would be less common. Another open loop
method to help manage congestion is forcing the packet to be transmitted at a more
predictable rate. This is called traffic shaping.
169
55. What is BGP (Border Gateway Protocol)?
It is a protocol used to advertise the set of networks that can be reached with in an
autonomous system. BGP enables this information to be shared with the autonomous
system. This is newer than EGP (Exterior Gateway Protocol).
170
Operating Systems
Operating Systems
Following are a few basic questions that cover the essentials of OS:
4. What is thrashing?
It is a phenomenon in virtual memory schemes when the processor spends most of
its time swapping pages, rather than executing instructions. This is due to an inordinate
number of page faults.
171
Circular Wait: A closed chain of processes exist such that each process holds at least
one resource needed by another process in the chain.
172
The set of dispatchable processes is in a safe state if there exists at least one
temporal order in which all processes can be run to completion without resulting in a
deadlock.
173
17. When does the condition 'rendezvous' arise?
In message passing, it is the condition in which, both, the sender and receiver are
blocked until the message is delivered.
20. Define latency, transfer and seek time with respect to disk I/O.
Seek time is the time required to move the disk arm to the required track.
Rotational delay or latency is the time it takes for the beginning of the required sector to
reach the head. Sum of seek time (if any) and latency is the access time. Time taken to
actually transfer a span of data is transfer time.
23. How are the wait/signal operations for monitor different from those for semaphores?
If a process in a monitor signal and no task is waiting on the condition variable,
the signal is lost. So this allows easier program design. Whereas in semaphores, every
operation affects the value of the semaphore, so the wait and signal operations should be
perfectly balanced in the program.
174
24. In the context of memory management, what are placement and replacement
algorithms?
Placement algorithms determine where in available real-memory to load a
program. Common methods are first-fit, next-fit, best-fit. Replacement algorithms are
used when memory is full, and one process (or part of a process) needs to be swapped out
to accommodate a new program. The replacement algorithm determines which are the
partitions to be swapped out.
25. In loading programs into memory, what is the difference between load-time dynamic
linking and run-time dynamic linking?
For load-time dynamic linking: Load module to be loaded is read into memory.
Any reference to a target external module causes that module to be loaded and the
references are updated to a relative address from the start base address of the application
module.
With run-time dynamic loading: Some of the linking is postponed until actual
reference during execution. Then the correct module is loaded and linked.
30. What are the four layers that Windows NT have in order to achieve independence?
Hardware abstraction layer
Kernel
Subsystems
System Services.
175
32. What are the key object oriented concepts used by Windows NT?
Encapsulation
Object class and instance
33. Is Windows NT a full blown object oriented operating system? Give reasons.
No Windows NT is not so, because its not implemented in object oriented
language and the data structures reside within one executive component and are not
represented as objects and it does not support object oriented capabilities .
47. What are DDks? Name an operating system that includes this feature.
DDks are device driver kits, which are equivalent to SDKs for writing device
drivers. Windows NT includes DDks.
177
178
Visual Basic 6.0
1. How long have you programmed in VB and how would
you rate yourself (1-10)?
Statement Description
Resume [0] Program execution resumes with the
statement that caused the error or the most recently
executed call out of the procedure containing the
error-handling routine. Use it to repeat an operation
after correcting the condition that caused the error.
Resume Next Resumes program execution at the statement
immediately following the one that caused the error.
If the error occurred outside the procedure that
contains the error handler, execution resumes at the
statement immediately following the call to the
179
procedure wherein the error occurred, if the called
procedure does not have an enabled error handler.
Resume line Resumes program execution at the label
specified by line, where line is a line label (or
nonzero line number) that must be in the same
procedure as the error handler.
Err.Raise Number:= number Triggers a run-time error.
When this statement is executed within the
error-handling routine, Visual Basic searches the
calls list for another error-handling routine. (The
calls list is the chain of procedures invoked to
arrive at the current point of execution. See the
section, "Error-Handling Hierarchy," later in this
chapter.)
189
37. What are the different cursor types that can we
create using ADO Recordset?
Difference between these cursor types?
Visual Basic Concepts
ADO, DAO and RDO in Visual Basic
You can control how the data source and the chosen ADO
cursor library manage concurrency with the locking
options in the following table.
Locking type Constant
Pessimistic concurrency. adLockPessimistic
Optimistic concurrency using row values.
adLockOptimistic
Read-only. Changes are not permitted. adLockReadOnly
All updates are deferred until the batch update is
finished. To do batch updating, you should select
either a keyset or static cursor.
adLockBatchOptimistic
204
Puzzles
Three friends divided some bullets equally. After all of them shot 4 bullets the total number of bullets remaining is equal to
the bullets each had after division. Find the original number divided.
Answer
18
But it is given that,after they shot 4 bullets each, total number of bullets remaining is equal to the bullets each had after
division i.e. X
Let
A= 19991999
B = sum of digits of A
C = sum of digits of B
D = sum of digits of C
Answer
A = 19991999
< 20002000
= 22000 * 10002000
205
= 1024200 * 106000
= 106800
i.e. C < 5 * 9 = 45
i.e. D < 2 * 9 = 18
i.e. E <= 9
Also,
1999 = 1 (mod 9)
so 19991999 = 1 (mod 9)
In the mean time the whole platoon has moved ahead by 50m.
The question is how much distance did the last person cover in that time. Assuming that he ran the whole distance with uniform speed.
Submitted
Answer
It is given that the platoon and the last person moved with uniform speed. Also, they both moved for the identical amount
of time. Hence, the ratio of the distance they covered - while person moving forward and backword - are equal.
Let's assume that when the last person reached the first person, the platoon moved X meters forward.
Thus, while moving forward the last person moved (50+X) meters whereas the platoon moved X meters.
Similarly, while moving back the last person moved [50-(50-X)] X meters whereas the platoon moved (50-X) meters.
Note that at first glance, one might think that the total distance covered by the last person is 100 meters, as he ran the
total lenght of the platoon (50 meters) twice. TRUE, but that's the relative distance covered by the last person i.e.
assuming that the platoon is stationary.
206
If you take a marker & start from a corner on a cube, what is the maximum number of edges you can trace across if you
never trace across the same edge twice, never remove the marker from the cube, & never trace anywhere on the cube,
except for the corners & edges?
Answer
To verify this, you can make a drawing of a cube, & number each of its 12 edges. Then, always starting from 1 corner & 1
edge, you can determine all of the possible combinations for tracing along the edges of a cube.
There is no need to start from other corners or edges of the cube, as you will only be repeating the same combinations.
The process is a little more involved than this, but is useful for solving many types of spatial puzzles.
One of Mr. Bajaj, his wife, their son and Mr. Bajaj's mother is an Engineer and another is a Doctor.
Mr. Bajaj is the Engineer and either his wife or his son is the Doctor.
Mr. Bajaj's wife and mother are not blood relatives. So from 3, if the Engineer is a female, the Doctor is a male. But from
1, if the Doctor is a male, then the Engineer is a male. Thus, there is a contradiction, if the Engineer is a female. Hence,
either Mr. Bajaj or his son is the Engineer.
Mr. Bajaj's son is the youngest of all four and is blood relative of each of them. So from 2, Mr. Bajaj's son is not the
Engineer. Hence, Mr. Bajaj is the Engineer.
Now from 2, Mr. Bajaj's mother can not be the Doctor. So the Doctor is either his wife or his son . It is not possible to
determine anything further.
Three men - Sam, Cam and Laurie - are married to Carrie, Billy and Tina, but not necessarily in the same order.
Sam's wife and Billy's Husband play Carrie and Tina's husband at bridge. No wife partners her husband and Cam does
not play bridge.
Answer
"Sam's wife and Billy's Husband play Carrie and Tina's husband at bridge."
It means that Sam is not married to either Billy or Carrie. Thus, Sam is married to Tina.
There are 3 persons X, Y and Z. On some day, X lent tractors to Y and Z as many as they had. After a month Y gave as
many tractors to X and Z as many as they have. After a month Z did the same thing. At the end of this transaction each
one of them had 24.
Answer
207
One way to solve it is by making 3 equations and solve them simultaneously. But there is rather easier way to solve it
using Backtracing.
It's given that at the end, each had 24 tractors (24, 24, 24) i.e. after Z gave tractors to X & Y as many as they had. It
means that after getting tractors from Z their tractors got doubled. So before Z gave them tractors, they had 12 tractors
each and Z had 48 tractors. (12, 12, 48)
Similarly, before Y gave tractors to X & Z, they had 6 & 24 tractors respectively and Y had 42 tractors i.e. (6, 42, 24)
Again, before X gave tractors to Y & Z, they had 21 & 12 tractors respectively and X had 39 tractors i.e. (39, 21, 12)
A certain street has 1000 buildings. A sign-maker is contracted to number the houses from 1 to 1000. How many zeroes
will he need?
Answer
There are 9 coins. Out of which one is odd one i.e weight is less or more. How many iterations of
weighing are required to find odd coin?
Answer
It is always possible to find odd coin in 3 weighings and to tell whether the odd coin is heavier or
lighter.
2. One of these 8 coins is the odd one. Name the coins on heavier side of the scale as H1,
H2, H3 and H4. Similarly, name the coins on the lighter side of the scale as L1, L2, L3
and L4. Either one of H's is heavier or one of L's is lighter. Weigh (H1, H2, L1) against
(H3, H4, X) where X is one coin remaining in intial weighing.
o If both are equal, one of L2, L3, L4 is lighter. Weigh L2 against L3.
If both are equal, L4 is the odd coin and is lighter.
If L2 is light, L2 is the odd coin and is lighter.
If L3 is light, L3 is the odd coin and is lighter.
208
o If (H1, H2, L1) is heavier side on the scale, either H1 or H2 is heavier. Weight H1
against H2
If both are equal, there is some error.
If H1 is heavy, H1 is the odd coin and is heavier.
If H2 is heavy, H2 is the odd coin and is heavier.
3. The remaining coin X is the odd one. Weigh X against the anyone coin used in initial
weighing.
o If both are equal, there is some error.
o If X is heavy, X is the odd coin and is heavier.
o If X is light, X is the odd coin and is lighter.
In a sports contest there were m medals awarded on n successive days (n > 1).
1. On the first day 1 medal and 1/7 of the remaining m - 1 medals were awarded.
2. On the second day 2 medals and 1/7 of the now remaining medals was awarded; and so
on.
3. On the nth and last day, the remaining n medals were awarded.
How many days did the contest last, and how many medals were awarded altogether?
Answer
Total 36 medals were awarded and the contest was for 6 days.
I got this answer by writing small program. If anyone know any other simpler method, do submit it.
• The number comprising the leftmost two digits is divisible by 2, that comprising the
leftmost three digits is divisible by 3, the leftmost four by 4, the leftmost five by 5, and so
on for the nine digits of the number i.e. the number formed from the first n digits is
divisible by n, 2<=n<=9.
• Each digit in the number is different i.e. no digits are repeated.
• The digit 0 does not occur in the number i.e. it is comprised only of the digits 1-9 in some
order.
209
Find the number.
Answer
One way to solve it is Trial-&-Error. You can make it bit easier as odd positions will always occupy
ODD numbers and even positions will always occupy EVEN numbers. Further 5th position will
contain 5 as 0 does not occur.
The other way to solve this problem is by writing a computer program that systematically tries all
possibilities
1/3 rd of the contents of a container evaporated on the 1st day. 3/4th of the remaining contents of the
container evaporated on the second day.
What part of the contents of the container is left at the end of the second day?
Answer
Vipul was studying for his examinations and the lights went off. It was around 1:00 AM. He lighted
two uniform candles of equal length but one thicker than the other. The thick candle is supposed
to last six hours and the thin one two hours less. When he finally went to sleep, the thick candle
was twice as long as the thin one.
Answer
Assume that the initial lenght of both the candle was L and Vipul studied for X hours.
Also, it is given that the thick candle was twice as long as the thin one when he finally went to
sleep.
(L - XL/6) = 2(L - XL/4)
210
(6 - X)/6 = (4 - X)/2
(6 - X) = 3*(4 - X)
6 - X = 12 - 3X
2X = 6
X=3
Hence, Vipul studied for 3 hours i.e. 180 minutes in candle light.
If you started a business in which you earned Rs.1 on the first day, Rs.3 on the second day, Rs.5
on the third day, Rs.7 on the fourth day, & so on.
How much would you have earned with this business after 50 years (assuming there are exactly
365 days in every year)?
Answer
Rs.333,062,500
To begin with, you want to know the total number of days: 365 x 50 = 18250.
By experimentation, the following formula can be discovered, & used to determine the amount
earned for any particular day: 1 + 2(x-1), with x being the number of the day. Take half of the
18250 days, & pair them up with the other half in the following way: day 1 with day 18250, day 2
with day 18249, & so on, & you will see that if you add these pairs together, they always equal
Rs.36500.
Multiply this number by the total number of pairs (9125), & you have the amount you would have
earned in 50 years.
Math gurus may use series formula to solve it.(series: 1,3,5,7,9,11.....upto 18250 terms)
A worker earns a 5% raise. A year later, the worker receives a 2.5% cut in pay, & now his salary is
Rs. 22702.68
Rs.22176
A year later he receives 2.5% cut. So his salary is ((105*X)/100)*(97.5/100) which is Rs. 22702.68
Answer
66 seconds
211
It is given that the time between first and last ticks at 6'o is 30 seconds.
Total time gaps between first and last ticks at 6'o = 5
(i.e. between 1 & 2, 2 & 3, 3 & 4, 4 & 5 and 5 & 6)
Now, total time gaps between first and last ticks at 12'o = 11
Therefore time taken for 12 ticks = 11 * 6 = 66 seconds (and not 60 seconds)
500 men are arranged in an array of 10 rows and 50 columns according to their heights.
Tallest among each row of all are asked to come out. And the shortest among them is A.
Similarly after resuming them to their original positions, the shortest among each column are
asked to come out. And the tallest among them is B.
No one is taller, both are same as A and B are the same person.
As it is mentioned that 500 men are arranged in an array of 10 rows and 50 columns according
to their heights. Let's assume that position numbers represent their heights. Hence, the shortest
among the 50, 100, 150, ... 450, 500 is person with height 50 i.e. A. Similarly the tallest among 1,
2, 3, 4, 5, ..... 48, 48, 50 is person with height 50 i.e. B
Now, both A and B are the person with height 50. Hence both are same.
In Mr. Mehta's family, there are one grandfather, one grandmother, two fathers, two mothers, one
father-in-law, one mother-in-law, four children, three grandchildren, one brother, two sisters, two
sons, two daughters and one daughter-in-law.
How many members are there in Mr. Mehta's family? Give minimal possible answer.
Answer
There are 7 members in Mr. Mehta's family. Mother & Father of Mr. Mehta, Mr. & Mrs. Mehta, his
son and two daughters.
212
The soldier could make only one statement. He made that statement and went free. What did he
say?
Answer
The soldier has to say a Paradox to save himself. If his statement is true, he will be hanged,
which is not the sword and hence false. If his statement is false, he will be put to the sword, which
will make it true. A Paradox !!!
A person wanted to withdraw X rupees and Y paise from the bank. But cashier made a mistake
and gave him Y rupees and X paise. Neither the person nor the cashier noticed that.
After spending 20 paise, the person counts the money. And to his surprise, he has double the
amount he wanted to withdraw.
Answer
After spending 20 paise, he has double the amount he wanted to withdraw. Hence, the
equation is
2 * (100X + Y) = 100Y + X - 20
200X + 2Y = 100Y +X - 20
98Y - 199X = 20
Now, we got one equation; but there are 2 variables. We have to apply little bit of logic over
here. We know that if we interchange X & Y, amount gets double. So Y should be twice of X or
one more than twice of X i.e. Y = 2X or Y = 2X+1
Case I : Y=2X
Solving two equations simultaneously
98Y - 199X = 20
Y - 2X = 0
We get X = - 20/3 & Y = - 40/2
Case II : Y=2X+1
Solving two equations simultaneously
98Y - 199X = 20
Y - 2X = 1
We get X = 26 & Y = 53
213
Submit Users BrainVista
Answer Answer (2) Answer
The game of Tic-Tac-Toe is being played between two players. Only the last mark to
be placed in the game as shown.
Who will win the game, O or X? Can you tell which was the sixth mark and at which position? Do
explain your answer.
At the Party:
Also, of the three groups - men, women and children - at the party:
4. There were 4 of one group.
5. There were 6 of one group.
6. There were 8 of one group.
Can you tell which one is false? Also, how many men, women and children are there at the party
Answer
The 7th mark must be placed in square 5 which is the win situation for both X and O. Hence, the
6th mark must be placed in a line already containing two of the opponents marks. There are two
such possibilities - the 6th mark would have been either O in square 7 or X in square 9.
As we know both the players are intelligent enough, the 6th mark could not be O in square 7.
Instead, he would have placed O in square 5 and would have won.
Hence, the sixth mark must be X placed in square 9. And the seventh mark will be O. Thus O will
win the game.
Answer
Assume that Statements (4), (5) and (6) are all true. Then, Statement (1) is false. But then
Statement (2) and (3) both can not be true. Thus, contradictory to the fact that exactly one
statement is false.
So Statement (4) or Statement (5) or Statement (6) is false. Also, Statements (1), (2) and (3) all
are true.
214
From (1) and (2), there are 11 men and women. Then from (3), there are 2 possible cases - either
there are 8 men and 3 women or there are 3 men and 8 women.
If there are 8 men and 3 women, then there is 1 child. Then Statements (4) and (5) both are false,
which is not possible.
Hence, there are 3 men, 8 women and 6 children. Statement (4) is false.
There is a shortage of tubelights, bulbs and fans in a village - Kharghar. It is found that
Let's assume that there are 100 houses. Hence, there should be total 300 items i.e. 100
tubelights, 100 bulbs and 100 fans.
From the given data, we know that there is shortage of atleast (67+83+73) 223 items in every 100
houses.
Also, exactly 19 houses do not have just one item. It means that remaining 81 houses should
account for the shortage of remaining (223-19) 204 items. If those remaining 81 houses do not
have 2 items each, there would be a shortage of 162 items. But total of 204 items are short.
Hence, atleast (204-162) 42 houses do not have all 3 items - tubelight, bulb and fan.
One day the car driver informed Mr. Subramaniam that there were two students from Bandra who
wished to go from Bandra to Colaba and back to Bandra. Bandra is halfway between Andheri and
Colaba. Mr. Subramaniam asked the driver to let the students travel with him.
On the first day when they came, Mr. Subramaniam said, "If you tell me the mathematically
correct price you should pay individually for your portion of the trip, I will let you travel for free."
How much should the individual student pay for their journey?
Answer
The entire trip costs Rs. 300 to Mr. Subramanian. Hence, half of the trip costs Rs. 150.
For Andheri-Bandra-Andheri, only one person i.e. Mr. Subramaniam is travelling. Hence, he
would pay Rs. 150.
215
For Bandra-Colaba-Bandra, three persons i.e Mr. Subramaniam and two students, are travelling.
Hence, each student would pay Rs. 50.
Substitute digits for the letters to make the following Division true
O U T
-------------
S T E M | D E M I S E
| D M O C
-------------
T U I S
S T E M
----------
Z Z Z E
Z U M M
--------
I S T
Note that the leftmost letter can't be zero in any word. Also, there must be a one-to-one mapping
between digits and letters. e.g. if you substitute 3 for the letter M, no other letter can be 3 and all
other M in the puzzle must be
Answer
C=0, U=1, S=2, T=3, O=4, M=5, I=6, Z=7, E=8, D=9
S*O is a single digit and also S*T is a single digit. Hence, their values (O, S, T) must be 2, 3 or 4
(as they can not be 0 or 1 or greater than 4).
Consider, STEM*O=DMOC, where C=0. It means that M must be 5. Now, its simple. O=4, S=2,
T=3, E=8, Z=7, I=6 and D=9.
O U T 4 1 3
------------- -------------
S T E M | D E M I S E 2 3 8 5 | 9 8 5 6 2 8
| D M O C | 9 5 4 0
------------- -------------
T U I S 3 1 6 2
S T E M 2 3 8 5
---------- ----------
216
Z Z Z E 7 7 7 8
Z U M M 7 1 5 5
-------- --------
I S T 6 2 3
Also, when arranged from 0 to 9, it spells CUSTOMIZED.
At what time after 4.00 p.m. is the minutes hand of a clock exactly aligned with the hour hand?
Answer
4:21:49.5
Assume that X minutes after 4.00 PM minute hand exactly aligns with and hour hand.
At 4.00 PM, the angle between minute hand and hour hand is 120 degrees. Also, after X minutes,
minute hand and hour hand are exactly aligned. So the angle with respect to 12 i.e. Vertical Plane
will be same. Therefore,
6 * X = 120 + X/2
12 * X = 240 + X
11 * X = 240
X = 21.8182
X = 21 minutes 49.5 seconds
Hence, at 4:21:49.5 minute hand is exactly aligned with the hour hand.
A soldier looses his way in a thick jungle. At random he walks from his camp but mathematically
in an interesting fashion.
First he walks one mile East then half mile to North. Then 1/4 mile to West, then 1/8 mile to South
and so on making a loop.
Answer
The soldier is 0.8944 miles away from his camp towards East-North.
(1/2) * ( 1 - (-1/4)n )
= ---------------------------
( 1 - (-1/4) )
217
= 1 / ( 2 * ( 1 - (-1/4) ) )
= 2/5
(1) * ( 1 - (-1/4)n )
= ---------------------------
( 1 - (-1/4) )
= 1 / ( ( 1- (-1/4) )
= 4/5
So the soldier is 4/5 miles away towards East and 2/5 miles away towards North. So using right
angled triangle, soldier is 0.8944 miles away from his camp.
Raj has a jewel chest containing Rings, Pins and Ear-rings. The chest contains 26 pieces. Raj
has 2 1/2 times as many rings as pins, and the number of pairs of earrings is 4 less than the
number of rings.
Answer
12 earrings
And, the number of pairs of earrings is 4 less than the number of rings.
E = R - 4 or R = E + 4
Given that each pawn is identical and each rook, knight and bishop is identical to its pair.
Submitted
Answer
6,48,64,800 ways
There are total 16 pieces which can be arranged on 16 places in 16P16 = 16! ways.
218
(16! = 16 * 15 * 14 * 13 * 12 * ..... * 3 * 2 * 1)
A person with some money spends 1/3 for cloths, 1/5 of the remaining for food and 1/4 of the
remaining for travel. He is left with Rs 100/-
Answer
Rs. 250/-
Again, he spent 1/4 of remaining maoney for travel = (1/4) * (8/15) * X = (2/15) * X
Remaining money = (8/15) * X - (2/15) * X = (6/15) * X
Grass in lawn grows equally thick and in a uniform rate. It takes 24 days for 70 cows and 60 days
for 30 cows to eat the whole of the grass.
20 cows
65292
As per given conditions, there are three possible combinations for 2nd, 3rd and 4th digits. They
are (3, 0, 7) or (4, 1, 8) or (5, 2, 9)
It is given that there are 3 pairs whose sum is 11. All possible pairs are (2, 9), (3, 8), (4, 7), (5, 6).
Now required number is 5 digit number and it contains 3 pairs of 11. So it must not be having 0
and 1 in it. Hence, the only possible combination for 2nd, 3rd and 4th digits is (5, 2, 9)
Also, 1st digit is thrice the last digit. The possible combinations are (3, 1), (6, 2) and (9, 3), out of
which only (6, 2) with (5, 2, 9) gives 3 pairs of 11. Hence, the answer is 65292.
Four friends - Arjan, Bhuvan, Guran and Lakha were comparing the number of sheep that they
owned.
It was found that Guran had ten more sheep than Lakha.
If Arjan gave one-third to Bhuvan, and Bhuvan gave a quarter of what he then held to Guran, who
then passed on a fifth of his holding to Lakha, they would all have an equal number of sheep.
How many sheep did each of them possess? Give the minimal possible answer
Answer
220
Arjan, Bhuvan, Guran and Lakha had 90, 50, 55 and 45 sheep respectively.
Assume that Arjan, Bhuvan, Guran and Lakha had A, B, G and L sheep respectively. As it is given
that at the end each would have an equal number of sheep, comparing the final numbers from the
above table.
Also, it is given that Guran had ten more sheep than Lakha.
G = L + 10
11A/18 = A/2 + 10
A/9 = 10
A = 90 sheep
Thus, Arjan had 90 sheep, Bhuvan had 5A/9 i.e. 50 sheep, Guran had 11A/18 i.e. 55 sheep and
Lakha had A/2 i.e. 45 sheep.
Consider a number 235, where last digit is the sum of first two digits i.e. 2 + 3 = 5.
Answer
If the last digit is 1, the only possible number is 101. (Note that 011 is not a 3-digit number)
If the last digit is 2, the possible numbers are 202 and 112.
If the last digit is 3, the possible numbers are 303, 213 and 123.
If the last digit is 4, the possible numbers are 404, 314, 224 and 134.
If the last digit is 5, the possible numbers are 505, 415, 325, 235 and 145.
Note the pattern here - If the last digit is 1, there is only one number. If the last digit is 2, there are
two numbers. If the last digit is 3, there are three numbers. If the last digit is 4, there are four
221
numbers. If the last digit is 5, there are five numbers. And so on.....
Altogether then, there are 45 different 3-digit numbers, where last digit is the sum of first two
digits.
Find the smallest number such that if its rightmost digit is placed at its left end, the new number
so formed is precisely 50% larger than the original number.
Answer
If its rightmost digit is placed at its left end, then new number is 428571 which is 50% larger than
the original number 285714.
The simplest way is to write a small program. And the other way is trial and error !!!
Two identical pack of cards A and B are shuffled throughly. One card is picked from A and shuffled
with B. The top card from pack A is turned up. If this is the Queen of Hearts, what are the chances
that the top card in B will be the King of Hearts?
Answer
52 / 2703
CASE 1 : King of Hearts is drawn from Pack A and shuffled with Pack B
Probability of drawing King of Hearts from Pack A = 1/51 (as Queen of Hearts is not to be drawn)
Probability of having King of Hearts on the top of the Pack B = 2/53
Probability of not drawing King of Hearts from Pack A = 50/51 (as Queen of Hearts is not to be
drawn)
Probability of having King of Hearts on the top of the Pack B = 1/53
Answer
Let's mark the corners of the triangle as A,B,C. There are total 8 ways in which ants can move.
222
1. A->B, B->C, C->A
2. A->B, B->C, C->B
3. A->B, B->A, C->A
4. A->B, B->A, C->B
5. A->C, C->B, B->A
6. A->C, C->B, B->C
7. A->C, C->A, B->A
8. A->C, C->A, B->C
Out of which, there are only two cases under which the ants won't collide :
Answer
1. Sum of 2000 numbers starting from -999 i.e. summation of numbers from -999 to 1000.
(-999) + (-998) + (-997) + ..... + (-1) + 0 + 1 + 2 + ..... + 997 + 998 + 999 + 1000 = 1000
2. Sum of 400 numbers starting from -197 i.e. summation of numbers from -197 to 202.
(-197) + (-196) + (-195) + ..... + (-1) + 0 + 1 + 2 + ..... + 199 + 200 + 201 + 202 = 1000
3. Sum of 125 numbers starting from -54 i.e. summation of numbers from -54 to 70.
(-54) + (-53) + (-52) + ..... + (-1) + 0 + 1 + 2 + ..... + 68 + 69 + 70 = 1000
4. Sum of 80 numbers starting from -27 i.e. summation of numbers from -27 to 52.
(-27) + (-26) + (-25) + ..... + (-1) + 0 + 1 + 2 + ..... + 50 + 51 + 52 = 1000
5. Sum of 25 numbers starting from 28 i.e. summation of numbers from 28 to 52.
28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 36 + 37 + 38 + 39 + 40 + 41 + 42 + 43 + 44 +
45 + 46 + 47 + 48 + 49 + 50 + 51 + 52 = 1000
6. Sum of 16 numbers starting from 55 i.e. summation of numbers from 55 to 70.
55 + 56 + 57 + 58 + 59 +60 + 61 + 62 + 63 + 64 + 65 + 66 + 67 + 68 + 69 + 70 = 1000
7. Sum of 5 numbers starting from 198 i.e. summation of numbers from 198 to 202.
198 + 199 + 200 +201 + 202 = 1000
There is a 4-character code, with 2 of them being letters and the other 2 being numbers.
How many maximum attempts would be necessary to find the correct code? Note that the code is
case-sensitive.
Answer
Consider an example : Let's assume that @ represents letter and # represents number. the 6
possible ways of arranging them are : @@##, @#@#, @##@, #@@#, #@#@, ##@@
In other words, if you wanted to solve the rubics cube by trying different combinations, how many
might it take you (worst case senerio)?
Answer
There are 4.3252 * 10^19 possible combinations for 3x3x3 Rubics and 7.4012 * 10^45
possible combinations for 4x4x4 Rubics.
Here, we have essentially pulled the cubes apart and stuck cubes back in place wherever we
please. In reality, we can only move cubes around by turning the faces of the cubes. It turns out
that you can't turn the faces in such a way as to switch the positions of two cubes while returning
all the others to their original positions. Thus if you get all but two cubes in place, there is only
one attainable choice for them (not 2!). Hence, we must divide by 2.
Note that there are 24 edge cubes, which you can not turn in 2 orientations (hence no 2^24 / 2).
Also, there are 4 center cubes per face i.e. (24!) / (4!^6). You can switch 2 cubes without affecting
the rest of the combination as 4*4*4 has even dimensions (hence no division by 2). But pattern on
one side is rotated in 4 directions over 6 faces, hence divide by 24.
Substitute digits for the letters to make the following relation true.
N E V E R
L E A V E
+ M E
-----------------
A L O N E
Note that the leftmost letter can't be zero in any word. Also, there must be a one-to-one mapping
between digits and letters. e.g. if you substitute 3 for the letter M, no other letter can be 3 and all
other M in the puzzle must be 3.
Answer
A tough one!!!
N E V E R 2 1 4 1 9
L E A V E 3 1 5 4 1
+ M E + 6 1
----------------- -----------------
A L O N E 5 3 0 2 1
One of the four people - Mr. Clinton, his wife Monika, their son Mandy and their daughter Cindy -
is a singer and another is a dancer. Mr. Clinton is older than his wife and Mady is older than his
sister.
1. If the singer and the dancer are the same sex, then the dancer is older than the singer.
2. If neither the singer nor the dancer is the parent of the other, then the singer is older than
the dancer.
3. If the singer is a man, then the singer and the dancer are the same age.
4. If the singer and the dancer are of opposite sex then the man is older than the woman.
5. If the dancer is a woman, then the dancer is older than the singer.
225
From (1) and (3), the singer and the dancer, both can not be a man. From (3) and (4), if the singer
is a man, then the dancer must be a man. Hence, the singer must be a woman.
In both the cases, we know that Cindy is the Singer. And either Mr. Clinton or Monika is the
Dancer.
There are 20 people in your applicant pool, including 5 pairs of identical twins.
If you hire 5 people randomly, what are the chances you will hire at least 1 pair of identical twins?
(Needless to say, this could cause trouble ;))
Submitted
Answer
The probability to hire 5 people with at least 1 pair of identical twins is 25.28%
Let's find out all possible ways to hire 5 people without a single pair of indentical twins.
People People No of ways to hire G1 without a single No of ways to Total
from G1 from G2 pair of indentical twins hire G2 ways
0 5 10C0 10C5 252
1 4 10C1 10C4 2100
2 3 10C2 * 8/9 10C3 4800
3 2 10C3 * 8/9 * 6/8 10C2 3600
4 1 10C4 * 8/9 * 6/8 * 4/7 10C1 800
5 0 10C5 * 8/9 * 6/8 * 4/7 * 2/6 10C0 32
Total 11584
Thus, total possible ways to hire 5 people without a single pair of indentical twins = 11584 ways
So, total possible ways to hire 5 people with at least a single pair of indentical twins = 15504 -
11584 = 3920 ways
Hence, the probability to hire 5 people with at least a single pair of indentical twins
= 3920/15504
= 245/969
= 0.2528
= 25.28%
In a hotel, rooms are numbered from 101 to 550. A room is chosen at random. What is the
probability that room number starts with 1, 2 or 3 and ends with 4, 5 or 6?
226
Answer
Out of which 299 room number starts with either 1, 2 or 3. (as room number 100 is not there) Now
out of those 299 rooms only 90 room numbers end with 4, 5 or 6
There are 3 persons X, Y and Z. On some day, X lent tractors to Y and Z as many as they had.
After a month Y gave as many tractors to X and Z as many as they have. After a month Z did the
same thing. At the end of this transaction each one of them had 24.
Answer
One way to solve it is by making 3 equations and solve them simultaneously. But there is rather
easier way to solve it using Backtracing.
It's given that at the end, each had 24 tractors (24, 24, 24) i.e. after Z gave tractors to X & Y as
many as they had. It means that after getting tractors from Z their tractors got doubled. So before
Z gave them tractors, they had 12 tractors each and Z had 48 tractors. (12, 12, 48)
Similarly, before Y gave tractors to X & Z, they had 6 & 24 tractors respectively and Y had 42
tractors i.e. (6, 42, 24)
Again, before X gave tractors to Y & Z, they had 21 & 12 tractors respectively and X had 39
tractors i.e. (39, 21, 12)
There is a 50m long army platoon marching ahead. The last person in the platoon wants to give a
letter to the first person leading the platoon. So while the platoon is marching he runs ahead,
reaches the first person and hands over the letter to him and without stopping he runs and comes
back to his original position.
In the mean time the whole platoon has moved ahead by 50m.
The question is how much distance did the last person cover in that time. Assuming that he ran
the whole distance with uniform speed.
Submitted
Answer
227
The last person covered 120.71 meters.
It is given that the platoon and the last person moved with uniform speed. Also, they both moved
for the identical amount of time. Hence, the ratio of the distance they covered - while person
moving forward and backword - are equal.
Let's assume that when the last person reached the first person, the platoon moved X meters
forward.
Thus, while moving forward the last person moved (50+X) meters whereas the platoon moved X
meters.
Similarly, while moving back the last person moved [50-(50-X)] X meters whereas the platoon
moved (50-X) meters.
Note that at first glance, one might think that the total distance covered by the last person is 100
meters, as he ran the total lenght of the platoon (50 meters) twice. TRUE, but that's the relative
distance covered by the last person i.e. assuming that the platoon is stationary.
Assume that you have enough coins of 1, 5, 10, 25 and 50 cents.
How many ways are there to make change for a dollar? Do explain your answer.
There are 292 ways to make change for a dollar using coins of 1, 5, 10, 25 and 50 cents.
If you wish to make change for 75 cents using only 1, 5, 10 and 25 cent coins, go to the .25 row
and the 75 column to obtain 121 ways to do this.
The table can be created from left-to-right and top-to-bottom. Start with the top left i.e. 1 cent row.
There is exactly one way to make change for every amount. Then calculate the 5 cents row by
adding the number of ways to make change for the amount using 1 cent coins plus the number of
ways to make change for 5 cents less using 1 and 5 cent coins.
For people who don't want to tease their brain and love to do computer programming, there is a
simple way. Write a small multi-loop program to solve the equation: A + 5B + 10C + 25D + 50E =
100
where,
A = 0 to 100
B = 0 to 20
C = 0 to 10
D = 0 to 4
E = 0 to 2
The program should output all the possible values of A, B, C, D and E for which the equation is
satisfied.
In a Road Race, one of the three bikers was doing 15km less than the first and 3km more than
the third. He also finished the race 12 minutes after the first and 3 minutes before the third.
Can you find out the speed of each biker, the time taken by each biker to finish the race and the
length of the course?
Assume that there were no stops in the race and also they were driving with constant speeds
through out the
Answer
X1 - 15 = V2 * T ----> 2
X1 - 18 = V3 * T ----> 3
At a Distance S Km.
S = V1 * T1 ----> 4
Thus there are 6 equations and 7 unknown data that means it has infinite number of solutions.
Also, we get
Speed of first biker, V1 = 90/T km/min
Speed of second biker, V2 = (5/6)V1 = 75/T km/min
Speed of third biker, V3 = (4/5)V1 = 72/T km/min
Thus, for the data given, only the time taken by each biker can be found i.e. 60, 72 and 75
minutes. For other quantities, one more independent datum is required i.e. either T or V1 or V2 or
V3
Answer
It is given that the first digit is 1/3 of the second. There are 3 such possibilities.
1. 1 and 3
2. 2 and 6
3. 3 and 9
Now, the third digit is the sum of the first and second digits.
1. 1 + 3 = 4
2. 2 + 6 = 8
3. 3 + 9 = 12
230
It is clear that option 3 is not possible. So we are left with only two options. Also, the last digit is
three times the second, which rules out the second option. Hence, the answer is 1349.
Difference between Bholu's and Molu's age is 2 years and the difference between Molu's and
Kolu's age is 5 years.
What is the maximum possible value of the sum of the difference in their ages, taken two at a
time?
Answer
The maximum possible value of the sum of the difference in their ages - taken two at a
time - is 14 years.
It is given that -
"Difference between Bholu's and Molu's age is 2 years"
"Difference between Molu's and Kolu's age is 5 years"
Now, to get the maximum possible value, the difference between Bholu's and Kolu's age should
be maximum i.e. Molu's age should be in between Bholu's and Kolu's age. Then, the difference
between Bholu's and Kolu's age is 7 years.
Hence, the maximum possible value of the sum of the difference in their ages - taken two at a
time - is (2 + 5 + 7) 14 years.
If it is given that:
25 - 2 = 3
100 x 2 = 20
36 / 3 = 2
What is 144 - 3 = ?
Submitted
Answer
Answer 1 : 9
Simply replace the first number by its square root.
(25) 5 - 2 = 3
(100) 10 x 2 = 20
(36) 6 / 3 = 2
(144) 12 - 3 = 9
Answer 2 : 11
Drop the digit in the tens position from the first number.
(2) 5 - 2 = 3
1 (0) 0 x 2 = 20
(3) 6 / 3 = 2
1 (4) 4 - 3 = 11
You will get the same answer on removing left and right digit alternatively from the first number i.e
remove left digit from first (2), right digit from second (0), left digit from third (3) and right digit from
forth (4).
(2) 5 - 2 = 3
10 (0) x 2 = 20
(3) 6 / 3 = 2
14 (4) - 3 = 11
231
Answer 3 : 14
Drop left and right digit alternatively from the actual answer.
25 - 2 = (2) 3 (drop left digit i.e. 2)
100 * 2 = 20 (0) (drop right digit i.e. 0)
36 / 3 = (1) 2 (drop left digit i.e. 1)
144 - 3 = 14 (1) (drop right digit i.e. 1)
A 3 digit number is such that it's unit digit is equal to the product of the other two digits which are
prime. Also, the difference between it's reverse and itself is 396.
Answer
It is given that the first two digits of the required number are prime numbers i.e. 2, 3, 5 or 7. Note
that 1 is neither prime nor composite. Also, the third digit is the multiplication of the first two digits.
Thus, first two digits must be either 2 or 3 i.e. 22, 23, 32 or 33 which means that there are four
possible numbers - 224, 236, 326 and 339.
Now, it is also given that - the difference between it's reverse and itself is 396. Only 236 satisfies
this condition. Hence, the sum of the three digits is 11.
There are 4 mugs placed upturned on the table. Each mug have the same number of marbles
and a statement about the number of marbles in it. The statements are: Two or Three, One or
Four, Three or One, One or Two.
Only one of the statement is correct. How many marbles are there under each mug?
Answer
A simple one.
As it is given that only one of the four statement is correct, the correct number can not appear in
more than one statement. If it appears in more than one statement, then more than one
statement will be correct.
What percent chance is there that it will be a junior? Round to the nearest whole percent
Answer
19%
This puzzle is easy. Divide the number of juniors (187) by the total number of students (981), &
then multiply the number by 100 to convert to a percentage.
If you were to dial any 7 digits on a telephone in random order, what is the probability that you will
dial your own phone number?
232
Assume that your telephone number is 7-digits.
Answer
1 in 10,000,000
There are 10 digits i.e. 0-9. First digit can be dialed in 10 ways. Second digit can be dialed in 10
ways. Third digit can be dialed in 10 ways. And so on.....
Thus, 7-digit can be dialed in 10*10*10*10*10*10*10 (=10,000,000) ways. And, you have just one
telephone number. Hence, the possibility that you will dial your own number is 1 in 10,000,000.
Note that 0123456 may not be a valid 7-digit telephone number. But while dialing in random
order, that is one of the possible 7-digit number which you may dial.
An anthropologist discovers an isolated tribe whose written alphabet contains only six letters (call
the letters A, B, C, D, E and F). The tribe has a taboo against using the same letter twice in the
same word. It's never done.
If each different sequence of letters constitues a different word in the language, what is the
maximum number of six-letter words that the language can employ?
Submitted
Answer
It is a simple permutation problem of arranging 6 letters to get different six-letter words. And it can
be done in in 6! ways i.e. 720 ways.
In otherwords, the first letter can be any of the given 6 letters (A through F). Then, whatever the
first letter is, the second letter will always be from the remaining 5 letters (as same letter can not
be used twice), and the third letter always be from the remaining 4 letters, and so on. Thus, the
different possible six-letter words are 6*5*4*3*2*1 = 720
Kate, Demi, Madona, Sharon, Britney and Nicole decided to lunch together in a restaurant. The
waiter led them to a round table with six chairs.
Answer
The first person can sit on any one of the seats. Now, for the second person there are 5 options,
for the third person there are 4 options, for the forth person there are 3 options, for the fifth
person there are 2 options and for the last person there is just one option.
233
Answer
There are total of 64 blocks on a chessboard. So 3 blocks can be chosen out of 64 in 64C3
ways.
So the sample space is = 41664
There are 2 diagonal on chessboard each one having 8 blocks. Consider one of them.
3 blocks out of 8 blocks in diagonal can be chosen in 8C3 ways.
But there are 2 such diagonals, hence favourables = 2 * 8C3 = 2 * 56 = 112
What is the area of the triangle ABC with A(e,p) B(2e,3p) and C(3e,5p)?
where p = PI (3.141592654)
Answer
A tricky ONE.
Meenu replied that she wouldn't reveal her weight directly as she is overweight. But she said, "I
weigh 29 Kgs plus half of my weight."
Answer
It is given that Meenu weighs 29 Kgs plus half of her own weight. It means that 29 Kgs is the
other half. So she weighs 58 Kgs.
234
If different letters represent different digits, and there are no leading zeros, what does J
represent?
Answer
Since there are no leading zeros, J must be 7, 8, or 9. (JJJ = ABC + DEF + GHI = 14? + 25? +
36? = 7??)
Now, the remainder left after dividing any number by 9 is the same as the remainder left after
dividing the sum of the digits of that number by 9. Also, note that 0 + 1 + ... + 9 has a remainder
of 0 after dividing by 9 and JJJ has a remainder of 0, 3, or 6.
The number 9 is the only number from 7, 8 and 9 that leaves a remainder of 0, 3, or 6 if you
remove it from the sum 0 + 1 + ... + 9. Hence, it follows that J must be 9.
A man has Ten Horses and nine stables as shown here.
[] [] [] [] [] [] [] [] []
The man wants to fit Ten Horses into nine stables. How can he fit Ten horses into nine stables?
Submitted
Answer
The answer is simple. It says the man wants to fit "Ten Horses" into nine stables. There are nine
letters in the phrase "Ten Horses". So you can put one letter each in all nine stables.
[T] [E] [N] [H] [O] [R] [S] [E] [S]
A man is at a river with a 9 gallon bucket and a 4 gallon bucket. He needs exactly 6 gallons of
water.
Note that he cannot estimate by dumping some of the water out of the 9 gallon bucket or the 4
gallon bucket
Answer
For the sack of explanation, let's identify 4 gallon bucket as Bucket P and 9 gallon bucket as
Bucket Q.
4 gallon bucket 9 gallon bucket
Operation (Bucket P) (Bucket Q)
Initially 0 0
Empty bucket P 0 5
Empty bucket P 0 1
Each of the five characters in the word BRAIN has a different value between 0 and 9. Using the
given grid, can you find out the value of each character?
B R A I N 31
B B R B A 31
N I A B B 32
N I B A I 30
I R A A A 23
37 29 25 27 29
The numbers on the extreme right represent the sum of the values represented by the characters
in that row. Also, the numbers on the last raw represent the sum of the values represented by the
characters in that column. e.g. B + R + A + I + N = 31 (from first row)
236
Answer
Make total 10 equations - 5 for rows and 5 for columns - and sovle them.
From Column2,
R + B + I + I + R = 29
B + 2R + 2I = 29
B + 2(B - 1) + 2I = 29
3B + 2I = 31
3(I + 2) + 2I = 31
5I = 25
I=5
From Row2,
B + B + R + B + A = 31
3B + R + A = 31
3(7) + 6 + A = 31
A=4
From Row1,
B + R + A + I + N = 31
7 + 6 + 4 + 5 + N = 31
N=9
Submit Users
BrainV
Answer Answer (24)
There are 9 coins. Out of which one is odd one i.e weight is less or more. How many iterations of
weighing are required to find odd coin?
Answer
It is always possible to find odd coin in 3 weighings and to tell whether the odd coin is heavier or
lighter.
237
2. One of these 8 coins is the odd one. Name the coins on heavier side of the scale as H1,
H2, H3 and H4. Similarly, name the coins on the lighter side of the scale as L1, L2, L3
and L4. Either one of H's is heavier or one of L's is lighter. Weigh (H1, H2, L1) against
(H3, H4, X) where X is one coin remaining in intial weighing.
o If both are equal, one of L2, L3, L4 is lighter. Weigh L2 against L3.
If both are equal, L4 is the odd coin and is lighter.
If L2 is light, L2 is the odd coin and is lighter.
If L3 is light, L3 is the odd coin and is lighter.
o If (H1, H2, L1) is heavier side on the scale, either H1 or H2 is heavier. Weight H1
against H2
If both are equal, there is some error.
If H1 is heavy, H1 is the odd coin and is heavier.
If H2 is heavy, H2 is the odd coin and is heavier.
3. The remaining coin X is the odd one. Weigh X against the anyone coin used in initial
weighing.
o If both are equal, there is some error.
o If X is heavy, X is the odd coin and is heavier.
o If X is light, X is the odd coin and is lighter.
In a sports contest there were m medals awarded on n successive days (n > 1).
1. On the first day 1 medal and 1/7 of the remaining m - 1 medals were awarded.
2. On the second day 2 medals and 1/7 of the now remaining medals was awarded; and so
on.
3. On the nth and last day, the remaining n medals were awarded.
How many days did the contest last, and how many medals were awarded altogether?
Answer
Total 36 medals were awarded and the contest was for 6 days.
238
I got this answer by writing small program. If anyone know any other simpler method, do submit it.
• The number comprising the leftmost two digits is divisible by 2, that comprising the
leftmost three digits is divisible by 3, the leftmost four by 4, the leftmost five by 5, and so
on for the nine digits of the number i.e. the number formed from the first n digits is
divisible by n, 2<=n<=9.
• Each digit in the number is different i.e. no digits are repeated.
• The digit 0 does not occur in the number i.e. it is comprised only of the digits 1-9 in some
order.
Answer
One way to solve it is Trial-&-Error. You can make it bit easier as odd positions will always occupy
ODD numbers and even positions will always occupy EVEN numbers. Further 5th position will
contain 5 as 0 does not occur.
The other way to solve this problem is by writing a computer program that systematically tries all
possibilities.
1/3 rd of the contents of a container evaporated on the 1st day. 3/4th of the remaining contents of
the container evaporated on the second day.
What part of the contents of the container is left at the end of the second day?
Answer
There are four people in a room (not including you). Exactly two of these four always tell the truth.
The other two always lie.
You have to figure out who is who IN ONLY 2 QUESTIONS. Your questions have to be YES or
NO questions and can only be answered by one person. (If you ask the same question to two
different people then that counts as two questions). Keep in mind that all four know each other's
characteristics whether they lie or not.
What questions would you ask to figure out who is who? Remember that you can ask only 2
questions.
Submitted
239
You have 3 baskets, & each one contains exactly 4 balls, each of which is of the same size. Each
ball is either red, black, white, or purple, & there is one of each color in each basket.
If you were blindfolded, & lightly shook each basket so that the balls would be randomly
distributed, & then took 1 ball from each basket, what chance is there that you would have exactly
2 red balls?
Answer
There are 64 different possible outcomes, & in 9 of these, exactly 2 of the balls will be red. There
is thus a slightly better than 14% chance [(9/64)*100] that exactly 2 balls will be red.
A much faster way to solve the problem is to look at it this way. There are 3 scenarios where
exactly 3 balls are red:
1 2 3
-----------
R R X
R X R
X R R
Take the first one, for example: 25% chance the first ball is red, multiplied by a 25% chance the
second ball is red, multiplied by a 75% chance the third ball is not red.
Because there are 3 scenarios where this outcome occurs, you multiply the 4.6875% chance of
any one occurring by 3, & you get 14.0625%
Consider a state lottery where you get to choose 8 numbers from 1 to 80, no repetiton allowed.
The Lottery Commission chooses 11 from those 80 numbers, again no repetition. You win the
lottery if atleast 7 of your numbers are there in the 11 chosen by the Lottery Commission.
240
Answer
The probability of winning the lottery is two in one billion i.e. only two person can win from one
billion !!!
Let's find out sample space first. The Lottery Commission chooses 11 numbers from the 80.
Hence, the 11 numbers from the 80 can be selected in 80C11 ways which is very very high and is
equal to 1.04776 * 1013
Now, you have to select 8 numbers from 80 which can be selected in 80C8 ways. But we are
interested in only those numbers which are in 11 numbers selected by the Lottery Commision.
There are 2 cases.
• You might select 8 numbers which all are there in 11 numbers choosen by the Lottery
Commission. So there are 11C8 ways.
• Another case is you might select 7 lucky numbers and 1 non-lucky number from the
remaining 69 numbers. There are ( 11C7 ) * ( 69C1 ) ways to do that.
How far will the safe have moved forward when the rollers have made one revolution?
Answer
If the rollers make one revolution, the safe will move the distance equal to the circumference of
the roller. Hence, the distance covered by the safe is
= PI * Diameter (or 2 * PI * Radius)
= PI * 7
= 3.14159265 * 7
= 21.99115
= 22 inches approx.
SubmittIf a rook and a bishop of a standard chess set are randomly placed on a chessboard,
what is the probability that one is attacking the other?
The probability of either the Rook or the Bishop attacking the other is 0.3611
241
A Rook and a Bishop on a standard chess-board can be arranged in 64P2 = 64*63 = 4032 ways
Now, there are 2 cases - Rook attacking Bishop and Bishop attacking Rook. Note that the Rook
and the Bishop never attack each other simultaneously. Let's consider both the cases one by one.
If the bishop is in one of the outer 28 squares, then it can attack 7 positions. If the bishop is in one
of the 20 squares at next inner-level, then it can attack 9 positions. Similarly if the bishop is in one
of the 12 squares at next inner-level, then it can attack 11 positions. And if the bishop is in one of
the 4 squares at next inner-level (the innermost level), then it can attack 13 positions.
Given that the maximum number of items allowed is 8, and you are allowed to have less than 8
items, and that the order of purchase does not matter (i.e. buying a burger and fries is the same
as buying fries and a burger)
How many possible combinations are there? Are McDonald's correct in claiming there are 40312
combinations?
Answer
It is given that you can order maximum of 8 items and you are allowed to have less than 8 items.
Also, the order of purchase does not matter. Let's create a table for ordering total N items using X
products.
1 1 - - - - - - -
2 1 1 - - - - - -
3 1 2 1 - - - - -
242
4 1 3 3 1 - - - -
5 1 4 6 4 1 - - -
6 1 5 10 10 5 1 - -
7 1 6 15 20 15 6 1 -
8 1 7 21 35 35 21 7 1
Total (T) 8 28 56 70 56 28 8 1
Ways to choose 8C1 8C2 8C3 8C4 8C5 8C6 8C7 8C8
X products from
8 products (W)
The probability of atleast two out of a group of 50 people share the same birthday is 97%
Probability of atleast two share the same birthday = 1 - probability of all 50 have different
birthdays
Thus, the probability of atleast two out of a group of 50 people share the same birthday is 97%
This explains why in a school/college with classrooms of 50 students, there are at least two
students with a birthday on the same day of the year. Also, if there are 23 people in the room,
then there are 50% chances that atleast two of them have a birthday on the same day of the
year!!!
A tank can be filled by pipe A in 30 minutes and by pipe B in 24 minutes. Outlet pipe C can empty
the full tank in X minutes.
If the tank is empty initially and if all the three pipes A, B and C are opened simultaneously, the
tank will NEVER be full. Give the maximal possible value of X.
Answer
243
In one minute,
pipe A can fill 1/30 part of the tank.
pipe B can fill 1/24 part of the tank.
In order to keep the tank always empty, outlet pipe C should empty at least 3/40 part of the tank
in one minute. Thus, pipe C can empty the full tank in 40/3 i.e. 13 minutes 20 seconds.
A worker earns a 5% raise. A year later, the worker receives a 2.5% cut in pay, & now his salary is
Rs. 22702.68
Rs.22176
A year later he receives 2.5% cut. So his salary is ((105*X)/100)*(97.5/100) which is Rs. 22702.68
500 men are arranged in an array of 10 rows and 50 columns according to their heights.
Tallest among each row of all are asked to come out. And the shortest among them is A.
Similarly after resuming them to their original positions, the shortest among each column are
asked to come out. And the tallest among them is B.
After spending 20 paise, the person counts the money. And to his surprise, he has double the
amount he wanted to withdraw.
244
As given, the person wanted to withdraw 100X + Y paise.
After spending 20 paise, he has double the amount he wanted to withdraw. Hence, the
equation is
2 * (100X + Y) = 100Y + X - 20
200X + 2Y = 100Y +X - 20
98Y - 199X = 20
Now, we got one equation; but there are 2 variables. We have to apply little bit of logic over
here. We know that if we interchange X & Y, amount gets double. So Y should be twice of X or
one more than twice of X i.e. Y = 2X or Y = 2X+1
Case I : Y=2X
Solving two equations simultaneously
98Y - 199X = 20
Y - 2X = 0
We get X = - 20/3 & Y = - 40/2
Case II : Y=2X+1
Solving two equations simultaneously
98Y - 199X = 20
Y - 2X = 1
We get X = 26 & Y = 53
At the Party:
Also, of the three groups - men, women and children - at the party:
4. There were 4 of one group.
5. There were 6 of one group.
6. There were 8 of one group.
Can you tell which one is false? Also, how many men, women and children are there at the party?
Answer
So Statement (4) or Statement (5) or Statement (6) is false. Also, Statements (1), (2) and
(3) all are true.
From (1) and (2), there are 11 men and women. Then from (3), there are 2 possible cases
- either there are 8 men and 3 women or there are 3 men and 8 women.
If there are 8 men and 3 women, then there is 1 child. Then Statements (4) and (5) both
are false, which is not possible.
Hence, there are 3 men, 8 women and 6 children. Statement (4) is false.
Brain Teaser No : 00242
There is a shortage of tubelights, bulbs and fans in a village - Kharghar. It is found that
Answer
Let's assume that there are 100 houses. Hence, there should be total 300 items i.e. 100
tubelights, 100 bulbs and 100 fans.
From the given data, we know that there is shortage of atleast (67+83+73) 223 items in every 100
houses.
Also, exactly 19 houses do not have just one item. It means that remaining 81 houses should
account for the shortage of remaining (223-19) 204 items. If those remaining 81 houses do not
have 2 items each, there would be a shortage of 162 items. But total of 204 items are short.
Hence, atleast (204-162) 42 houses do not have all 3 items - tubelight, bulb and fan.
A tricky one.
246
7! onwards all terms are divisible by 7 as 7 is one of the factor. So there is no remainder left for
those terms i.e. remainder left after dividing 7! + 8! + 9! + ... + 100! is 0.
Imagine that you have 26 constants, labelled A through Z. Each constant is assigned a value in
the following way: A = 1; the rest of the values equal their position in the alphabet (B corresponds
to the second position so it equals 2, C = 3, etc.) raised to the power of the preceeding constant
value. So, B = 2 ^ (A's value), or B = 2^1 = 2. C = 3^2 = 9. D = 4^9, etc.
Answer
9,46,08,000 babies
Thus, there are 3,15,36,000 seconds in the year 2001. Also, three babies born are every second.
Hence, total babies born
= 3 * 3,15,36,000 seconds
= 9,46,08,000bmitted
X T W O
---------
T H R E E
x 1 3 8
247
------------
1 9 0 4 4
You can reduce the number of trials. T must be 1 as there is multiplication of T with T in
hundred's position. Also, O can not be 0 or 1. Now, you have to find three digit number
whose square satisfies above conditions and square of that has same last two digits.
Hence, it must be between 102 and 139.
Brain Teaser No : 00052
mars
venus
uranus
saturn
-------- +
neptune
Each of the ten letters (m, a, r, s, v, e, n, u, t, and p) represent a unique number from the
range 0 .. 9.
The easiest way to solve this problem is by writing a computer program that systematically tries
all possible mappings from the numbers onto the letters. This will give you only one solution
which meets the condition that numbers 1 and 6 are most frequently used.
mars m = 4
venus a = 5
uranus r = 9
saturn s = 3
-------- + v = 2 4593
neptune e = 0 20163
n = 1 695163
u = 6 358691
t = 8 -------- +
p = 7 1078610
248
There are 4 army men. They have been captured by a rebel group and have been held at
ransom. An army intelligent officer orders them to be burried deep in dirt up to their necks. The
format of their burrial are as shown in the figure.
Conditions
• They each have hats on their heads. either black(b) or white (w) look at diagram above.
There are total 2 white hats and 2 black hats.
• They only look in front of them not behind. They are not allowed to communicate by
talking.
• Between army man 1 and 2, there is a wall.
• Captive man 4 can see the colour of hats on 2 and 3
• 3 can only see 2's hat
• 2 can only see a wall and 1 can see a wall too, but is on the other side
The officer speaks up, "If one of you can correctly tell me the colour of your hat, you will all go
scott free back to your contries. If you are wrong, you will all be killed.
How can one of them be certain about the hat they are wearing and not risk the lives of their
fellow souldiers by taking a 50/50 guess!
Submitted
Answer
Either soldier 3 or soldier 4 can save the life as soldier 1 and soldier 2 can not see colour of any
hat, even not their own.. In our case soldier 3 will tell the colour of his hat.
Soldier 4 can see the hat on soldier 2 and soldier 3. If both are white, then he can be sure about
colour of his hat which will be black and vice-versa. But if one of them is white and one is black,
then soldier 4 can not say anything as he can have either of them. So he will keep mum.
If soldier 4 won't say anyhing for a while, then soldier 3 will know that soldier 4 is not in position to
tell the colour of hat on his hat. It means that colour of soldier 3's hat is opposite of colour of
soldier 2's hat. So soldier 3 can tell correctly the colour of hat on his head which is Black.
Here, we are assuming that all the soldiers are intelligent enough. Also, this solution will work for
any combination of 2 Black hats and 2 White hats.
One side of the bottom layer of a triangular pyramid has 12 balls. How many are there in the
whole pyramid?
As there are 12 balls along one side, it means that there are 12 layers of balls. The top most layer
has 1 ball. The second layer has 3 (1+2) balls. The third layer has 6 (1+2+3) balls. The fourth
layer has 10 (1+2+3+4) balls. The fifth layer has 15 (1+2+3+4+5) balls. Similarly, there are 21, 28,
36, 45, 55, 66 and 78 balls in the remaining layers.
A blindfolded man is asked to sit in the front of a carrom board. The holes of the board are shut
249
with lids in random order, i.e. any number of all the four holes can be shut or open.
Now the man is supposed to touch any two holes at a time and can do the following.
After he has done it, the carrom board is rotated and again brought to some position. The man is
again not aware of what are the holes which are open or closed.
How many minimum number of turns does the blindfolded man require to either open all the holes
or close all the holes?
Note that whenever all the holes are either open or close, there will be an alarm so that the
blindfolded man will know that he has won.
Submitted
Answer
2. Open two diagonal holes. Now atleast 3 holes are open. If 4th hole is also open, then you
are done. If not, the 4th hole is close.
In the middle of the confounded desert, there is the lost city of "Ash". To reach it, I will have to
travel overland by foot from the coast. On a trek like this, each person can only carry enough
rations for five days and the farthest we can travel in one day is 30 miles. Also, the city is 120
miles from the starting point.
250
What I am trying to figure out is the fewest number of persons, including myself, that I will need in
our Group so that I can reach the city, stay overnight, and then return to the coast without running
out of supplies.
How many persons (including myself) will I need to accomplish this mission?
Answer
It is given that each person can only carry enough rations for five days. And there are 4 persons.
Hence, total of 20 days rations is available.
1. First Day : 4 days of rations are used up. One person goes back using one day of rations
for the return trip. The rations remaining for the further trek is for 15 days.
2. Second Day : The remaining three people use up 3 days of rations. One person goes
back using 2 days of rations for the return trip. The rations remaining for the further trek is
for 10 days.
3. Third Day : The remaining two people use up 2 days of rations. One person goes back
using 3 days of rations for the return trip. The rations remaining for the further trek is for 5
days.
4. Fourth Day : The remaining person uses up one day of rations. He stays overnight. The
next day he returns to the coast using 4 days of rations.
4:21:49.5
Assume that X minutes after 4.00 PM minute hand exactly aligns with and hour hand.
At 4.00 PM, the angle between minute hand and hour hand is 120 degrees. Also, after X minutes,
minute hand and hour hand are exactly aligned. So the angle with respect to 12 i.e. Vertical Plane
will be same. Therefore,
6 * X = 120 + X/2
12 * X = 240 + X
11 * X = 240
X = 21.8182
X = 21 minutes 49.5 seconds
Hence, at 4:21:49.5 minute hand is exactly aligned with the hour hand.
Substitute digits for the letters to make the following Division true
O U T
-------------
251
S T E M | D E M I S E
| D M O C
-------------
T U I S
S T E M
----------
Z Z Z E
Z U M M
--------
I S T
Note that the leftmost letter can't be zero in any word. Also, there must be a one-to-one mapping
between digits and letters. e.g. if you substitute 3 for the letter M, no other letter can be 3 and all
other M in the puzzle must be 3.
Submitted by : Calon
Answer
C=0, U=1, S=2, T=3, O=4, M=5, I=6, Z=7, E=8, D=9
S*O is a single digit and also S*T is a single digit. Hence, their values (O, S, T) must be 2, 3 or 4
(as they can not be 0 or 1 or greater than 4).
Consider, STEM*O=DMOC, where C=0. It means that M must be 5. Now, its simple. O=4, S=2,
T=3, E=8, Z=7, I=6 and D=9.
O U T 4 1 3
------------- -------------
S T E M | D E M I S E 2 3 8 5 | 9 8 5 6 2 8
| D M O C | 9 5 4 0
------------- -------------
T U I S 3 1 6 2
S T E M 2 3 8 5
---------- ----------
Z Z Z E 7 7 7 8
Z U M M 7 1 5 5
-------- --------
252
I S T 6 2 3
Also, when arranged from 0 to 9, it spells CUSTOMIZED.
Brain Teaser No : 00015
Answer
2025
It is given that no inhabitants have exactly 2025 hairs. Hence there are 2025 inhabitants with 0 to
2024 hairs in the head.
Suppose there are more than 2025 inhabitants. But these will violate the condition that "There are
more inhabitants than there are hairs on the head of any one inhabitants." As for any number
more than 2025, there will be same number of inhabitants as the maximum number of hairs on
the head of any inhabitant.
There are four groups of Mangoes, Apples and Bananas as follows:
Group I : 1 Mango, 1 Apples and 1 Banana
Group II : 1 Mango, 5 Apples and 7 Bananas
Group III : 1 Mango, 7 Apples and 10 Bananas
Group IV : 9 Mango, 23 Apples and 30 Bananas
Can you tell how much does Group I and Group IV cost?
Answer
Assume that the values of one mango, one apple and one banana are M, A and B respectively.
For Group I :
=M+A+B
= (M + 5A + 7B) - (4A + 6B)
= (M + 5A + 7B) - 2(2A + 3B)
= 300 - 2(90)
= 300 - 180
= 120
Where does the player that is playing 'O' has to put his first 'O' so that 'X' doesn't win?
Assume that both players are very intelligent. Explain your answer
Answer
---------
4 | 5 | 6
---------
7 | 8 | 9
It is given that "X" is placed in one of the corner position. Let's assume that its at position 1.
If "O" is placed in position 5 i.e. center position, "X" can't win unless "O" does something foolish
;))
254
Amit is the Mechanical Engineer. Bhavin is the Computer Engineer. Himanshu and Rakesh are
either Chemical Engineer or Elecronics Engineer.
Amit and Bhavin are sitting opposite to each other. Whereas Chemical Engineer and Elecronics
Engineer are sitting opposite to each other.
We cannot find out who is Chemical Engineer and Elecronics Engineer as data provided is not
sufficient
Five friends with surname Batliwala, Pocketwala, Talawala, Chunawala and Natakwala have their
first name and middle name as follow.
From (1) and (7), it is clear that Batliwala, Pocketwala and Talawala are named Paresh.
From (6) and (5), if Pocketwala or Talawala both are named Kamlesh, then either of them will
have three names i.e. Paresh, Kamlesh and Naresh. Hence, Pocketwala and Talawala both are
not named Kamlesh. It means that Batliwala, Chunawala and Natakwala are named Kamlesh.
Now it is clear that Talawala and Chunawala are named Naresh. Also, Pocketwala is named
Elesh.
Mr. Wagle goes to work by a bus. One day he falls asleep when the bus still has twice as far to go
as it has already gone.
Halfway through the trip he wakes up as the bus bounces over some bad potholes. When he
finally falls asleep again, the bus still has half the distance to go that it has already travelled.
Fortunately, Mr. Wagle wakes up at the end of his trip.
Answer
Let's draw a timeline. Picture the bus route on a line showen below:
255
----- shows time for which Mr. Wagle was not sleeping
When Mr. Wagle fell asleep the first time, the bus sill had twice as far to go as it had
already gone, that marks the first third of his trip.
He wake up halfway through the trip i.e slept from 1/3 mark to the 1/2 mark. He fell sleep
again when the bus still had half the distance to go that it had already traveled i.e 2/3
mark.
In your sock drawer, you have a ratio of 5 pairs of blue socks, 4 pairs of brown socks, and 6
pairs of black socks.
In complete darkness, how many socks would you need to pull out to get a matching pair of
the same color?
How many do you have to grab to be sure you have 2 of the same?
You have a bucket of jelly beans. Some are red, some are blue, and some green. With your eyes
closed, pick out 2 of a like color.
How many do you have to grab to be sure you have 2 of the same?
If you select 4 Jelly beans you are guarenteed that you will have 2 that are the same color.
There are 70 employees working with BrainVista of which 30 are females. Also,
How many unmarried females are there and how many of them are above 25?
Answer
256
15 unmarried females & none are above 25 years of age.
Simply put all given information into the table structure and you will get the answer.
Married Unmarried
Female 3 12 15 0
Male 8 7 20 5
There is a safe with a 5 digit number as the key. The 4th digit is 4 greater than the second digit,
while the 3rd digit is 3 less than the 2nd digit. The 1st digit is thrice the last digit. There are 3 pairs
whose sum is 11.
65292
As per given conditions, there are three possible combinations for 2nd, 3rd and 4th digits. They
are (3, 0, 7) or (4, 1, 8) or (5, 2, 9)
It is given that there are 3 pairs whose sum is 11. All possible pairs are (2, 9), (3, 8), (4, 7), (5, 6).
Now required number is 5 digit number and it contains 3 pairs of 11. So it must not be having 0
and 1 in it. Hence, the only possible combination for 2nd, 3rd and 4th digits is (5, 2, 9)
Also, 1st digit is thrice the last digit. The possible combinations are (3, 1), (6, 2) and (9, 3), out of
which only (6, 2) with (5, 2, 9) gives 3 pairs of 11. Hence, the answer is 65292.
My friend collects antique stamps. She purchased two, but found that she needed to raise money
urgently. So she sold them for Rs. 8000 each. On one she made 20% and on the other she lost
20%.
Consider the first stamp. She mades 20% on it after selling it for Rs 8000.
Similarly, consider second stamp. She lost 20% on it after selling it for Rs 8000
Assume for a moment that the earth is a perfectly uniform sphere of radius 6400 km. Suppose a
thread equal to the length of the circumference of the earth was placed along the equator, and
drawn to a tight fit.
Now suppose that the length of the thread is increased by 12 cm, and that it is pulled away
uniformly in all directions.
By how many cm. will the thread be separated from the earth's surface?
Answer
Now length of the thread is increasd by 12 cm. So the new length is = (1280000000 * PI) + 12 cm
This thread will make one concentric circle with the earth which is slightly away from the earth.
The circumfernce of that circle is nothing but (1280000000 * PI) + 12 cm
Six months later, there were 1000Z rabbits. At the beginning of the 3rd year, there were roughly
2828Z rabbits, which was 4 times what the scientists placed in there at the beginning of the 1st
year.
If Z is a positive variable, how many rabbits would be there at the beginning of the 11th year?
SubmiAnswer
258
At the beginning, there were 1000 rabbits. Also, there were 4000 rabbits at the beginning of third
year which is equal to 2828Z. Thus, Z = 4000/2828 i.e. 1.414 (the square root of 2)
Note that 2828Z can be represented as 2000*Z*Z (Z=1.414), which can be further simplified as
1000*Z*Z*Z*Z
Also, it is given that at the end of 6 months, there were 1000Z rabbits.
It is clear that the population growth is 1.414 times every six months i.e. 2 times every year. After
N years, the population would be 1000*(Z^(2N)) i.e. 1000*(2^N)
Thus, at the beginning of the 11th year (i.e. after 10 years), there would be 1000*(2^10) i.e.
1,024,000 rabbits.
tted
A class of 100 students. 24 of them are girls and 32 are not. Which base am I using?
Answer
Therefore
(X*X + X*0 + 0) = (2*X +4) + (3*X + 2)
X*X = 5*X + 6
X*X - 5*X -6 = 0
(X-6)(X+1) = 0
Therefore base is 6
A man is stranded on a desert island. All he has to drink is a 20oz bottle of sprite.
To conserve his drink he decides that on the first day he will drink one oz and the refill the bottle
back up with water. On the 2nd day he will drink 2oz and refill the bottle. On the 3rd day he will
drink 3oz and so on...
By the time all the sprite is gone, how much water has he drunk?
SubmittAnswer
It is given that the man has 20oz bottle of sprite. Also, he will drink 1oz on the first day and refill
the bottle with water, will drink 2oz on the second day and refill the bottle, will drink 3oz on the
third day and refill the bottle, and so on till 20th day. Thus at the end of 20 days, he must have
drunk (1 + 2 + 3 + 4 + ..... +18 + 19 + 20) = 210oz of liquid.
Out of that 210oz, 20oz is the sprite which he had initially. Hence, he must have drunk 190oz of
water.ed
You have four 9's and you may use any of the (+, -, /, *) as many times as you like. I want to see a
mathematical expression which uses the four 9's to = 100
99 + (9/9) = 100
259
(99/.99) = 100
(99-9)/.9 = 100
Two planes take off at the same exact moment. They are flying across the Atlantic. One leaves
New York and is flying to Paris at 500 miles per hour. The other leaves Paris and is flying to New
York at only 450 miles per hour ( because of a strong head wind ).
12 members were present at a board meeting. Each member shook hands with all of the other
members before & after the meeting.
132
Think of it this way: the first person shakes hands with 11 people, the second person also shakes
hands with 11 people, but you only count 10, because the hand shake with the first person was
already counted. Then add 9 for the third person, 8 for the fourth, & so on.
66 hand shakes took place before & 66 after the meeting, for a total of 132.
Arrange five planets such that 4 of them add up to 5th planet numerically. Each of the letters of
the planet should represent a unique number from the range 0 - 9. You have to use all ten digits.
There is an amazing mathematical relationship exists among the names of the planet.
Answer
The tought process is initially to find planets such that the total number of alphabets in them is 10.
The only possible combination of planets is Saturn, Uranus, Venus, Mars and Neptune because
for other combinations there will be more than 10 alphabets. Among these five, Neptune is the
lenghtiest, so it must be the sum of the other four.
S A T U R N
U R A N U S
V E N U S
+ M A R S
--------------
N E P T U N E
Now the only possible value for N is 1. By finding the value for S, we can reach the result:
260
3 5 8 6 9 1
6 9 5 1 6 3
2 0 1 6 3
+ 4 5 9 3
--------------
1 0 7 8 6 1 0
You have 14 apples. Your Friend Marge takes away 3 and gives you 2. You drop 7 but pick up 4.
Bret takes 4 and gives 5. You take one from Marge and give it to Bret in exchange for 3 more.
You give those 3 to Marge and she gives you an apple and an orange. Frank comes and takes
the apple Marge gave you and gives you a pear. You give the pear to Bret in exchange for an
apple. Frank then takes an apple from Marge, gives it to Bret for an orange, gives you the orange
for an apple.
None
Frank gave you a pear in exchange of the apple which Marge gave you. And you gave that pear
to Bret in exchange for an apple. All the others exchanges involved apples and/or organges.
Four couples are going to the movie. Each row holds eight seats. Betty and Jim don't want to sit
next to Alice and Tom. Alice and Tom don't want to sit next to Gertrude and Bill. On the otherhand,
Sally and Bob don't want to sit next to Betty and Jim.
How can the couples arrange themselves in a row so that they all sit where they would like?
Submitted by : Tara Smith
Answer
(A) NOT (B) means A and B can not seat next to each other.
Now, it is obvious that (Betty & Jim) and (Alice & Tom) will occupy the corner seats as both of
them can have only one neighbour. Therefore,
(Gertrude & Bill) will seat next to (Betty & Jim)
(Sally & Bob) will seat next to (Gertrude & Bill)
(Alice & Tom) will seat next to (Sally & Bob)
Thus, there are two possible arrangements - a mirror images of each other.
1. (Betty & Jim) - (Gertrude & Bill) - (Sally & Bob) - (Alice & Tom)
2. (Alice & Tom) - (Sally & Bob) - (Gertrude & Bill) - (Betty & Jim)
Substitute digits for the letters to make the following addition problem true.
W H O S E
T E E T H
261
A R E
+ A S
-------------------
S W O R D S
Note that the leftmost letter can't be zero in any word. Also, there must be a one-to-one mapping
between digits and letters. e.g. if you substitute 3 for the letter H, no other letter can be 3 and all
other H in the puzzle must be 3.
Answer
Also, (H + E) should be greater than 10 and hence, (E + H + E) must 20. Thus, there are 3
possible values for (E, H) pair: (6, 8) or (7, 6) or (8, 4). Use trial-n-error and everything will fit-in.
W H O S E 2 8 5 1 6
T E E T H 9 6 6 9 8
A R E 4 7 6
+ A S + 4 1
------------------- -------------------
S W O R D S 1 2 5 7 3 1
When Socrates was imprisoned for being a disturbing influence, he was held in high esteem by
his guards. All four of them hoped that something would occur that would facilitate his escape.
One evening, the guard who was on duty intentionally left the cell door open so that Socrates
could leave for distant parts.
Socrates did not attempt to escape, as it was his philosophy that if you accept society's rules, you
must also accept it's punishments. However, the open door was considered by the authorities to
be a serious matter. It was not clear which guard was on that evening. The four guards make the
following statements in their defense:
Aaron:
A) I did not leave the door open.
B) Clement was the one who did it.
Bob:
A) I was not the one who was on duty that evening.
B) Aaron was on duty.
Clement:
A) Bob was the one on duty that evening.
B) I hoped Socrates would escape.
David:
A) I did not leave the door open.
B) I was not surprised that Socrates did not attempt to escape.
262
Considering that, in total, three statements are true, and five statements are false, which guard is
guiltyAnswer
Note that "All four of them hoped that something would occur that would facilitate his escape". It
makes Clement's statement B True and David's statement B False.
If Aaron is guilty False False True True False True True False 4
If Bob is guilty True False False False True True True False 4
If Clement is guilty True True True False False True True False 5
If David is guilty True False True False False True False False 3
Since in total, three statements are true and five statements are false. It is clear from the above
table that David is?
Brain Teaser No : 00474
Given any whole number take the sum of the digits, and the product of the digits, and multiply
these together to get a new whole number.
For example, starting with 6712, the sum of the digits is (6+7+1+2) = 16, and the product of
the digits is (6*7*1*2) = 84. The answer in this case is then 84 x 16 = 1344.
At this stage we know what the next answer will be (without working it out) because, as one
digit is 0, the product of the digits will be 0, and hence the answer will also be 0.
Can you find any numbers to which when we apply the above mentioned rule repeatedly, we
never end up at 0?
Given any whole number take the sum of the digits, and the product of the digits, and
multiply these together to get a new whole number.
For example, starting with 6712, the sum of the digits is (6+7+1+2) = 16, and the
product of the digits is (6*7*1*2) = 84. The answer in this case is then 84 x 16 =
1344.
At this stage we know what the next answer will be (without working it out) because,
as one digit is 0, the product of the digits will be 0, and hence the answer will also
be 0.
263
Can you find any numbers to which when we apply the above mentioned rule repeatedly,
we never end up at 0?
There were N stations on a railroad. After adding X stations 46 additional tickets have to be
printed.
Find N and X.
Answer
Now there are only two possible factors of 46. They are (46,1) and (23,2)
Case I: (46,1)
2N - 1 = 45
2N = 46
N = 23
And X = 1
How fast must the vehicle travel on the return trip if the round-trip travel time is to be 20 minutes?
Answer
While going to the destination, the vehicle travels 10 mils at the speed of 50 miles per hour. So
the time taken to travel 10 miles is
= (60 * 10) / 50
= 12 minutes
Now it's given that round-trip travel time is 20 minutes. So the vehicle should complete its return
trip of 10 miles in 8 minutes. So the speed of the vehicle must
= (60 * 10) / 8
= 75 miles per hour
264
All of the students at a college are majoring in psychology, business, or both. 73% of the students
are psychology majors, & 62% are business majors.
If there are 200 students, how many of them are majoring in both psychology & business?
Answer
If 73% of the students are psychology majors, we know that 27% are not psychology majors. By
the same reasoning, 38% are not business majors, because 62% of the students do major in
business. So: 27 + 38 = 65
65% of the students are not majoring in both psychology & business, so 35% are double majors,
a total of 70 students.
Two trains starting at same time, one from Bangalore to Mysore and other in opposite direction
arrive at their destination 1hr and 4hrs respectively after passing each other.
Answer
Now, assume that both the trains met each other at T kms from the Bangalore (point P in figure)
Time taken by Bangalore-Mysore train to reach P = Time taken by Mysore-Bangalore train to
reach P
( T / X ) = ( D - T ) / Y -----equ(I)
Also, Bangalore-Mysore train and Mysore-Bangalore train arrive destination 1 hr and 4 hrs
respectively after passing each other. It means that Bangalore-Mysore train travels (D - T) kms in
1 hr at X km/hr and Mysore-Bangalore train travels T kms in 4 hrs at Y km/hr. Hence,
( D - T ) = X and
T=4*Y
Hence, the speed of Bangalore-Mysore train is TWICE the speed of Mysore-Bangalore train.How
much faster is one train from other?
Answer
49 times
Let's assume that everyone clinked their mug with friend to his left only. It means that there are
265
total 49 clinks. Now the right clink of each person is left clink of the person on right which is
already happened. Hence, there are only 49 clinks.
Mrs. Watsherface had a garage sale. A custmer named Gina bought an old lamp and a rug. She
paid a total of $5.25 for everything. The rug cost 25 cents more than the lamp.
A simple one.
Hence, the lamp cost $ 2.50 and the rug cost $ 2.75
Write 1111......(243 times) i.e. a 243 digit number with all 1s.
[2] Whenever a number (X) is multiplied with another number (Y) then the product (X*Y) will have
all the factors of X as well as all the factors of Y in its set of factors.
e.g. if X has factors of (1,P,Q,X) and Y has factors of (1,Q,R,Y) then X*Y has factors of
(1,P,Q,Q,R,X,Y).
Let
N = any series of digits (e.g. N=369)
D = the number of digits in N (e.g. if N=369 then D=3)
P = is a number constructed in the following way : a 1, followed by (D-1) 0s, followed by another
1, followed by (D-1) 0s, followed by another 1. (e.g. if N=369 then D=3 and P would be 1001001)
Note that P will always be divisible by 3.
266
The resulting number 111111111 must be divisible by 9 as N and P both are divisible by 3.
Repeat the same procedure for N=1111111... (27 times) The resulting number 1111111... (81
times) must be divisible by 81 as N is divisible by 27 and P is divisible by 3.
Similarly, for N=1111111... (81 times) The resulting number 1111111... (243 times) must be
divisible by 243 as N is divisible by 81 and P is divisible by 3.
He then used up six of the matches, and found that with the remainder he could again construct
another triangle whose area was just as many square inches as there were matches.
And using another six matches he could again do precisely the same.
There are 42 matches in the box with which he could form a triangle 20, 15, 7, with an area of 42
square inches. After 6 matches had been used, the remaining 36 matches would form a triangle
17, 10, 9, with an area of 36 square inches. After using another 6 matches, the remaining 30
matches would form a triangle 13, 12, 5, with an area of 30 square inches. After using another 6,
the 24 remaining would form a triangle 10, 8, 6, with an area of 24 square inches.
Thus, there are two possible answers. There were either 42 or 36 matches in the match-box.
Also it is interesting to know that there are just 5 such triangles for which the perimeter and the
area is the same (assuming all sides are integers) and they are :
1. 24 (10, 8, 6)
2. 30 (13, 12, 5)
3. 36 (17, 10, 9)
4. 42 (20, 15, 7)
5. 60 (29, 25, 6)
267
N O O N
S O O N
+ M O O N
----------
J U N E
Answer
Using trial and error. There are 2 solutions to it and may be more.
2 4 4 2
1 4 4 2
+ 5 4 4 2
----------
9 3 2 6
4 1 1 4
5 1 1 4
+ 0 1 1 4
----------
9 3 4 2
We have to fill number from 1 to 12 at the intersection point of two or more lines. We have to
construct a star using two triangle. The sum of all number lying in straight lines should be same.
This can be easilty understood by the fig. and hence solved.
Submitted by : Vaibhav Gupta
268
We have one answer where sum of all the numbers lying in straight lines is 26.
Montu says, "If Pintu and I each have a dog, then exactly one of Bantu and Chantu has a
dog."
Bantu says, "If Chantu and I each have a cat, then exactly one of Montu and Pintu has a dog."
Chantu says, "If Montu and I each have a dog, then exactly one of Bantu and Pintu has a cat."
Pintu says, "If Bantu and I each have a cat, then exactly one of Bantu and I has a dog."
Only one of the four is telling the truth. Who is telling the truth?
Answer
For a IF-THEN statement to be false, IF part has to be true and THEN part has to be false.
Since only one statement is true and remaining three are false, IF part of three statements are
true & THEN part of one statement is true. Let's put the given information in table. The pet-name
in the normal text represents the IF part and the pet-name in round brackets represents the
THEN part.
269
Bantu says (Dog) Cat Cat (Dog)
It is clear that the IF part of the statements made by Montu, Chantu and Pintu are true as
they do not contradict each other. And the IF part of the statement made by Bantu is false.
Somebody marked the six faces of a die with the numbers 1, 2 and 3 - each number twice.
The die was put on a table. Four people - Abu, Babu, Calu and Dabu - sat around the table so
that each one was able to see only three sides of the die at a glance.
Answer
If Abu can see two even numbers i.e. number 2 twice, and if Dabu can see number 2 twice, then
number 2 must be facing up.
Dabu Abu
3 2 2
1
270
Calu Babu
Thus, the number hidden from the view is number 3 and hence the answer.
Two identical pack of cards A and B are shuffled throughly. One card is picked from A and shuffled
with B. The top card from pack A is turned up. If this is the Queen of Hearts, what are the chances
that the top card in B will be the King of Hearts?
Answer
52 / 2703
CASE 1 : King of Hearts is drawn from Pack A and shuffled with Pack B
Probability of drawing King of Hearts from Pack A = 1/51 (as Queen of Hearts is not to be drawn)
Probability of having King of Hearts on the top of the Pack B = 2/53
Probability of not drawing King of Hearts from Pack A = 50/51 (as Queen of Hearts is not to be
drawn)
Probability of having King of Hearts on the top of the Pack B = 1/53
In other words, if you wanted to solve the rubics cube by trying different combinations, how many
might it take you (worst case senerio)?
There are 4.3252 * 10^19 possible combinations for 3x3x3 Rubics and 7.4012 * 10^45
possible combinations for 4x4x4 Rubics.
Here, we have essentially pulled the cubes apart and stuck cubes back in place wherever we
please. In reality, we can only move cubes around by turning the faces of the cubes. It turns out
that you can't turn the faces in such a way as to switch the positions of two cubes while returning
all the others to their original positions. Thus if you get all but two cubes in place, there is only
one attainable choice for them (not 2!). Hence, we must divide by 2.
Note that there are 24 edge cubes, which you can not turn in 2 orientations (hence no 2^24 / 2).
Also, there are 4 center cubes per face i.e. (24!) / (4!^6). You can switch 2 cubes without affecting
the rest of the combination as 4*4*4 has even dimensions (hence no division by 2). But pattern on
one side is rotated in 4 directions over 6 faces, hence divide by 24.
Substitute digits for the letters to make the following relation true.
N E V E R
L E A V E
+ M E
-----------------
A L O N E
Note that the leftmost letter can't be zero in any word. Also, there must be a one-to-one
mapping between digits and letters. e.g. if you substitute 3 for the letter M, no other letter can
be 3 and all other M in the puzzle must be 3.
Answer
A tough one!!!
N E V E R 2 1 4 1 9
L E A V E 3 1 5 4 1
272
+ M E + 6 1
----------------- -----------------
A L O N E 5 3 0 2 1
There are 20 people in your applicant pool, including 5 pairs of identical twins.
If you hire 5 people randomly, what are the chances you will hire at least 1 pair of identical twins?
(Needless to say, this could cause trouble ;))
SubmAnswer
The probability to hire 5 people with at least 1 pair of identical twins is 25.28%
Let's find out all possible ways to hire 5 people without a single pair of indentical twins.
People People No of ways to hire G1 without a single No of ways to Total
from G1 from G2 pair of indentical twins hire G2 ways
0 5 10C0 10C5 252
1 4 10C1 10C4 2100
2 3 10C2 * 8/9 10C3 4800
3 2 10C3 * 8/9 * 6/8 10C2 3600
4 1 10C4 * 8/9 * 6/8 * 4/7 10C1 800
5 0 10C5 * 8/9 * 6/8 * 4/7 * 2/6 10C0 32
Total 11584
Thus, total possible ways to hire 5 people without a single pair of indentical twins = 11584 ways
So, total possible ways to hire 5 people with at least a single pair of indentical twins = 15504 -
11584 = 3920 ways
Hence, the probability to hire 5 people with at least a single pair of indentical twins
= 3920/15504
= 245/969
= 0.2528
= 25.28%itted
Veeru says to Jay, "Can you figure out how many Eggs I have in my bucket?" He gives 3 clues to
Jay: If the number of Eggs I have
273
Answer
32 eggs
Let's apply all 3 condition separately and put all possible numbers together.
First condition says that if multiple of 5, then the number is between 1 and 19. Hence, the
possible numbers are (5, 10, 15, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
37, 38, 39)
Second condition says that if not a multiple of 8, then the number is between 20 and 29.
Hence, the possible numbers are (8, 16, 20, 21, 22, 23, 25, 26, 27, 28, 29, 32)
Third condition says that if not a multiple of 10, then the number is between 30 and 39. Hence,
the possible numbers are (10, 20, 31, 32, 33, 34, 35, 36, 37, 38, 39)
Only number 32 is there in all 3 result sets. That means that only number 32 satisfies all three
conditions. Hence, Veeru have 32 eggs in his bucket.
Submit Users
BrainV
Answer Answer (14)
Mr. Black, Mr. White and Mr. Grey were chatting in the Yahoo conference. They were wearing a
black suit, a white suit and a grey suit, not necessarily in the same order.
Mr. Grey sent message, "We all are wearing suit that are of the same color as our names but
none of us is wearing a suit that is the same color as his name."
On that a person wearing the white suit replied, "What difference does that make?"
Can you tell what color suit each of the three persons had on?
Answer
Mr. Grey must not be wearing grey suit as that is the same colour as his name. Also, he was not
wearing white suit as the person wearing white suit responded to his comment. So Mr Grey must
be wearing a black suit.
Similarly, Mr. White must be wearing either black suit or grey suit. But Mr. Grey is wearing a black
suit. Hence, Mr. White must be wearing a grey suit.
3 6 9
Note that the same number must be used for the same letter whenever it appears.
Answer
Now, consider DEF = 6 * IE. Out of three short-listed values, only 73 satisfies the equation. Also,
ABC = 3 * IE is satisfied by 73.
Hence, A=2, B=1, C=9, D=4, E=3, F=8, G=6, H=5, I=7
219 438 657
3 6 9
• One of the four is the opposite sex from each of the other three.
• D is A's brother or only daughter.
• A or B is C's only son.
• B or C is D's sister.
Answer
A, B & D are males; C is female. B is C's only son. A & D are C's brothers.
A(male) --- C(female) --- D(male)
B(male)
Work out which relation can hold and discard the contradictory options.
From (2) and (4), D can not be a only daughter and have a sister (B or C). Hence, D is A's brother
i.e. D is a Male.
Thus, C is D's sister i.e. C is Female. And B must be C's only son.
Now it is clear that D & B are Males and C is Female. A must be a Male as only one of them is of
opposite sex from each of the other three. And he is C & D's brother.How are they related to each
other?
Dr. DoLittle always goes walking to the clinic and takes the same time while going and while
coming back. One day he noticed something.
When he left the home, the hour hand and the minute hand were exactly opposite to each other
275
and when he reached the clinic, they were together.
Similarly, when he left the clinic, the hour hand and the minute hand were together and when he
reached the home, they were exactly opposite to each other.
How much time does Dr. DoLittle take to reach home from the clinic? Give the minimal possible
answer.
Answer
In twelve hours, the minute hand and the hour hand are together for 11 times. It means that after
every 12/11 hours, both the hands are together.
Similarly in twelve hours, the minute hand and the hour hand are exactly opposite to each other
for 11 times. It means that after every 12/11 hours, both the hands are opposite.
Now, let's take an example. We know that at 12 both the hands are together and at 6 both the
hands are exactly opposite to each other.
After 6, both the hands are in opposition at [6+(12/11)] hours, [6+2*(12/11)] hours, [6+3*(12/11)]
hours and so on. The sixth such time is [6+6*(12/11)] hours which is the first time after 12. Thus
after 12, both the hands are opposite to each other at 12:32:43.6
Hence, Dr. DoLittle takes 32 minutes and 43.6 seconds to reach home from the clinic.
SlowRun Express runs between Bangalore and Mumbai, For the up as well as the down journey,
the train leaves the starting station at 10:00 PM everyday and reaches the destination at 11:30
PM after three days.
Mr. Haani once travelled by SlowRun Express from Mumbai to Bangalore. How many SlowRun
Express did he cross during his journey?
Answer
Let's say that Mr. Haani travelled by SlowRun Express on Wednesday 10:00PM from Mumbai.
The first train he would have crossed is the one scheduled to arrive at Mumbai at 11:30 PM the
same day i.e. the one that left Bangalore at 10:00 PM on last Sunday.
Also, he would have crossed the last train just before reaching Bangalore on Saturday.
Thus, Mr. Haani must have crossed 7 SlowRun Expresses during his journey.
Six cabins numbered 1-6 consecutively, are arranged in a row and are separated by thin dividers.
These cabins must be assigned to six staff members based on following facts.
1. Miss Shalaka's work requires her to speak on the phone frequently throughout the day.
2. Miss Shudha prefers cabin number 5 as 5 is her lucky number.
3. Mr. Shaan and Mr. Sharma often talk to each other during their work and prefers to have
adjacent cabins.
4. Mr. Sinha, Mr. Shaan and Mr. Solanki all smoke. Miss Shudha is allergic to smoke and
must have non-smokers adjacent to her.
5. Mr. Solanki needs silence during work.
276
Can you tell the cabin numbers of each of them?
Answer
The cabins from left to right (1-6) are of Mr. Solanki, Mr. Sinha, Mr. Shaan, Mr. Sharma, Miss
Shudha and Miss Shalaka.
As Miss Shudha is allergic to smoke and Mr. Sinha, Mr. Shaan & Mr. Solanki all smoke, they must
be in cabin numbers 1, 2 and 3 not necessarily in the same order. Also, Miss Shalaka and Mr.
Sharma must be in cabin 4 and 6.
From (3), Mr. Shaan must be in cabin 3 and Mr. Sharma must be in cabin 4. Thus, Miss Shalaka
is in cabin 6.
As Mr. Solanki needs silence during work and Mr. Shaan is in cabin 3 who often talks to Mr.
Sharma during work, Mr. Solanki must be in cabin 1. Hence, Mr. Sinha is in cabin 2.
On February 10, it snows all day with the temperature at 18C. On how many lines service will be
delayed or cancelled, including both morning and afternoon?
SkyFi city is served by 6 subway lines - A, E, I, O, U and Z.
On February 10, it snows all day with the temperature at 18C. On how many lines service will be
delayed or cancelled, including both morning and afternoon?
277
In a certain game, if 2 wixsomes are worth 3 changs, and 4 changs are worth 1 plut, then 6 plutes
are worth how many wixsomes?
Answer
It is given that
2 wixsomes = 3 changs
8 wixsomes = 12 changs ----- (I)
Therefore,
6 plutes = 16 wixsomes
In a certain year, the number of girls who graduated from City High School was twice the number
of boys. If 3/4 of the girls and 5/6 of the boys went to college immediately after graduation, what
fraction of the graduates that year went to college immediately after graduation?
Answer
It is given that 3/4 of the girls and 5/6 of the boys went to college immediately after graduation.
Hence, total students went to college
= (3/4)(2*B) + (5/6)(B)
= B * (3/2 + 5/6)
= (7/3)B
Fraction of the graduates that year went to college immediately after graduation
= [(7/3)B] / [3*B]
= 7/9
The mule started complaining that his load was too heavy. The donkey said to him "Why are you
complaining? If you gave me one of your sacks I'd have double what you have and if I give you
one of my sacks we'd have an even amount."
How many sacks were each of them carrying? Give the minimal possible answer.
SubmittAnswer
The mule was carrying 5 sacks and the donkey was carrying 7 sacks.
Let's assume that the mule was carrying M sacks and the donkey was carrying D sacks.
As the donkey told the mule, "If you gave me one of your sacks I'd have double what you have."
D + 1 = 2 * (M-1)
D + 1 = 2M - 2
D = 2M - 3
278
The donkey also said, "If I give you one of my sacks we'd have an even amount."
D-1=M+1
D=M+2
Hence, the mule was carrying 5 sacks and the donkey was carrying 7 sacks.
edTwo people enter a race in whick you run to a point and back. Person A runs 20 mph to and
from the point. Person B runs to the point going 10 mph and 30 mph going back.
Let's assume that the distance between start and the point is D miles.
Alternatively (if you don't like mathematics ;)), analyse the situation as follow:
Note that initially speed of Person A (20 mph) was twice the speed of Person B (10 mph). Hence,
when Person A (20 mph forward) reached the point, Person B (10 mph forward) was halfway.
When Person A (20 mph back) finished, Person B (still 10 mph forward) reached the point.
Thus, Person A wins the race and by that time Person B covers only half the distance, no matter
how far the point is!!!
Mark ate half of a pizza on Monday. He ate half of what was left on Tuesday and so on. He
followed this pattern for one week.
How much of the pizza would he have eaten during the week?
Submitted
Answer
Mark would have ate 127/128 (99.22%) of the pizza during the week.
Mark ate half the pizza on Monday. On Tuesday, he would have ate half of the remaining pizza
i.e. 1/4 of the original pizza. Similarly, he would have ate 1/8 of the original pizza on Wednesday
and so on for the seven days.
279
Total pizza Mark ate during the week is
= 1/2 + 1/4 + 1/8 + 1/16 + 1/32 + 1/64 + 1/128
= 127/128
= 99.22% of the original pizza
In the General meeting of "Friends Club", Sameer said, "The repairs to the Club will come to a
total of Rs 3120 and I propose that this amount should be met by the members, each paying an
equal amount."
The proposal was immediately agreed. However, four members of the Club chose to resign,
leaving the remaining members to pay an extra Rs 26 each.
As 4 members resigned and remaining members paid Rs 26 each, it means that total amount of 4
members is equal to Rs 26 each from remaining (N-4) members. Thus,
4 * (3120 / N) = 26 * (N - 4)
12480 = 26N2 - 104N
26N2 - 104N - 12480 = 0
A tank can be filled by pipe A in 30 minutes and by pipe B in 24 minutes. Outlet pipe C can
empty the full tank in one hour and twenty minutes.
If the tank is empty initially and if all the three pipes A, B and C are opened simultaneously, in
how much time will the tank be full?
Answer
In one minute,
pipe A can fill 1/30 part of the tank.
pipe B can fill 1/24 part of the tank.
pipe C can empty 1/80 part of the tank.
A rich old Arab has three sons. When he died, he willed his 17 camels to the sons, to be divided
as follows:
280
First Son to get 1/2 of the camels Second Son to get 1/3rd of the camels Third Son to get 1/9th of
the camels.
The sons are sitting there trying to figure out how this can possibly be done, when a very old wise
man goes riding by. They stop him and ask him to help them solve their problem. Without
hesitation he divides the camels properly and continues riding on his way.
The old man temporarily added his camel to the 17, making a total of 18 camels.
For a total of 17. He then takes his camel back and rides away......
There were two men standing on a street. The one says to the other, "I have 3 daughters, the
product of their ages is 36. What is the age of the OLDEST daughter?"
The second guy says, "I need more information." So, the first guy says, "The sum of their ages is
equal to the address of the house across the street."
The second guy looks at the address and says, "I still need more information." So, the first guy
says, "My oldest daughter wears a red dress."
281
Answer
First you need to find all the possible sets of three numbers that when multiplied equals 36:
1 1 36
1 2 18
1 3 12
149
166
229
236
334
Even though we don't know the address the guy knows it. For him to need more information
that means that at least two of the sets of numbers has the same sum. Two of them do, 1 6 6
and 2 2 9.
When the first guy said that his OLDEST daugher wears a red dress that meant that there had
to be the oldest. So 1 6 6 can't possibly be the answer. So the possible possiblity is 2 2 9 and
the OLDEST daughter is 9 years old.
Submit
User
Answer
There are 3 colored boxes - Red, Green and Blue. Each box contains 2 envelopes. Each
envelope contains money - two of them contain Rs. 25000 each, two of them contain Rs. 15000
each and remaining two contain Rs. 10000 each.
Only one of the above 3 statements is true and the corresponding box contains the maximum
amount.
Can you tell which box contains the maximum amount and how much?
Answer
As it is given that only one of the given 3 statements is true; assume in turn, each statement to be
282
true & the other 2 false and check whether the corresponding box contains the maximum amount.
Let's assume that the statement on the Blue box is true. Thus, the given 3 statements can be
interpreted as
* Atmost one, a red box or a blue box contains Rs. 10000.
* Atmost one, a green box or a red box contains Rs. 25000.
* Both, a blue box and a green box contain Rs. 15000 each.
You can test out for other two statements i.e. assuming Red box statement true and then Green
box statement true. In both the cases, other statements will contradict the true statement.
Sachin, Dravid and Ganguly played in a Cricket match between India and England.
Sachin's score must be less than 86, otherwise Dravid's score would be more than 99. Also, he
must have scored atleast 42 - incase Dravid and Ganguly scored 99 each.
Also, as none of them scored more than 99 and the total runs scored by them is 240; their
individual scores must be around 80.
Can you figure out where each customer is in the line, his or her full name (one surname is Loti)
and the two things he or she wants to accomplish? Provide your answer is POSITION - FIRST
NAME - LAST NAME - BUSINESS format.
Submit Users
Answer Answer (8)
Answer
Substitute digits for the letters to make the following relation true.
W O R L D
+ T R A D E
-------------
C E N T E R
Note that the leftmost letter can't be zero in any word. Also, there must be a one-to-one
mapping between digits and letters. e.g. if you substitute 3 for the letter W, no other letter can
be 3 and all other W in the puzzle must be 3.
Answer
A tough one.
284
It is obvious that C=1. Also, the maximum possible value of E is 7. Now, start putting possible
values of D, E and R as they occure frequently and use trial-n-error.
W O R L D 5 3 6 8 4
+ T R A D E + 7 6 0 4 2
------------ ------------
C E N T E R 1 2 9 7 2 6
Brain Teaser No : 00107
What is the angle between the hour and the minute hands? ( The answer to this is not zero!)
Answer
7.5 degrees
At 3:15 minute hand will be perfactly horizontal pointing towards 3. Whereas hour hand will be
towards 4. Also, hour hand must have covered 1/4 of angle between 3 and 4.
How did the son place all the apples among the 10 boxes, given that any number of apples can
be put in one box.
Answer
• The apple vandor can ask for only 1 apple, so one box must contain 1 apple.
• He can ask for 2 apples, so one box must contain 2 apples.
He can ask for 3 apples, in that case box one and box two will add up to 3.
• He can ask for 4 apples, so one box i.e. third box must contain 4 apples.
• Now using box number one, two and three containing 1, 2 and 4 apples respectively, his
son can give upto 7 apples. Hence, forth box must contain 8 apples.
• Similarly, using first four boxes containing 1, 2, 4 and 8 apples, his son can give upto 15
apples. Hence fifth box must contain 16 apples.
• You must have noticed one thing till now that each box till now contains power of 2
apples. Hence the answer is 1, 2, 4, 8, 16, 32, 64, 128, 256, 489. This is true for any
number of apples, here in our case only upto 1000.
285
Brain Teaser No : 00261
The letters P, Q, R, S, T, U and V, not necessarily in that order represents seven consecutive
integers from 22 to 33.
Can you find the sequence of letters from the lowest value to the highest value?
Answer
The sequence of letters from the lowest value to the highest value is TUSQRPV.
From (4), there must be exactly 2 numbers between P and S which gives two possible positions.
From (1), the number of letters between U and Q must be same as the number of letters between
S and R. Also, the number of letters between them can be 1, 2 or 3.
Using trial and error, it can be found that there must be 2 letters between them. Also, it is possible
only in option [2] above.
From (2) V must be the highest and the remaining T must be the lowest number.
Thus, the sequence of letters from the lowest value to the highest value is TUSQRPV.
A contractor had employed 100 labourers for a flyover construction task. He did not allow any
woman to work without her husband. Also, atleast half the men working came with their wives.
He paid five rupees per day to each man, four ruppes to each woman and one rupee to each
child. He gave out 200 rupees every evening.
How many men, women and children were working with the constructor?
Answer
Let's assume that there were X men, Y women and Z children working with the constructor.
Hence,
286
X + Y + Z = 100
5X + 4Y + Z = 200
As if woman works, her husband also works and atleast half the men working came with their
wives; the value of Y lies between X and X/2. Substituting these limiting values in equations, we
get
if Y = X,
300 - 4Z = 3Z - 200
7Z = 500
Z = 500/7 i.e. 71.428
if Y = X/2,
300 - 4Z = (3Z - 200)/2
600 - 8Z = 3Z - 200
11Z = 800
Z = 800/11 i.e. 72.727
There were 16 men, 12 women and 72 children working with the constructor.
Because cigars cannot be entirely smoked, a Bobo who collects cigar butts can make a cigar to
smoke out of every 3 butts that he finds.
Today, he has collected 27 cigar butts. How many cigars will he be able to smoke?
Answer
13 not 12
He makes 9 originals from the 27 butts he found, and after he smokes them he has 9 butts left for
another 3 cigars. And then he has 3 butts for another cigar.
So 9+3+1=13
In a small town, there are three temples in a row and a well in front of each temple. A pilgrim
came to the town with certain number of flowers.
Before entering the first temple, he washed all the flowers he had with the water of well. To his
surprise, flowers doubled. He offered few flowers to the God in the first temple and moved to the
second temple. Here also, before entering the temple he washed the remaining flowers with the
water of well. And again his flowers doubled. He offered few flowers to the God in second temple
and moved to the third temple. Here also, his flowers doubled after washing them with water. He
offered few flowers to the God in third temple.
There were no flowers left when pilgrim came out of third temple and he offered same number of
flowers to the God in all three temples.
What is the minimum number of flowers the pilgrim had initially? How many flower did he offer to
each God?
Answer
287
The pilgrim had 7 flowers, initially and he offered 8 flowers to each God.
Assume that the pilgrim had X flowers initially and he offered Y flowers to each God.
From the above figure, there are (8X - 7Y) flowers when the pilgrim came out of the third temple.
But it is given that there were no flowers left when he came out of third temple. It means that
(8X - 7Y) = 0
8X = 7Y
The minimum values of X and Y are 7 and 8 respectively to satisfy above equation. Hence, the
pilgrim had 7 flowers and he offered 8 flowers to each God.
In general, the pilgrim had 7N flowers initially and he offered 8N flowers to each God, where N =
1, 2, 3, 4, .....
Tanya wants to go on a date and prefers her date to be tall, dark and handsome.
1. Of the preferred traits - tall, dark and handsome - no two of Adam, Bond, Cruz and
Dumbo have the same number.
2. Only Adam or Dumbo is tall and fair.
3. Only Bond or Cruz is short and handsome.
4. Adam and Cruz are either both tall or both short.
5. Bond and Dumbo are either both dark or both fair.
Answer
As no two of them have the same number of preferred traits - from (1), exactly one of them has
none of the preferred traits and exactly one of them has all the preferred traits.
But from (2), second possibility is impossible. So the first one is the correct possibility i.e. Adam &
Cruz both are tall and Bond & Dumbo both are fair.
Also, from (1) and (2), Adam is tall and fair. Also, Dumbo is the person without any preferred
traits. Cruz is Dark. Adam and Cruz are handsome. Thus, following are the individual preferred
traits:
If the tower has 2 discs, the least possible moves with which you can move the entire tower to
another peg is 3.
If the tower has 3 discs, the least possible moves with which you can move the entire tower to
another peg is 7.
What is the least possible moves with which you can move the entire tower to another peg if the
tower has N discs?
Submitted
Answer
To move the largest disc (at level N) from one tower to the other, it requires 2(N-1) moves. Thus, to
move N discs from one tower to the other, the number of moves required is
= 2(N-1) + 2(N-2) + 2(N-3) + ..... + 22 + 21 + 20
= 2N - 1
For N discs, the number of moves is one more than two times the number of moves for N-1 discs.
Thus, the recursive function is
F(1) = 1
F(N) = 2*[F(N-1)] + 1
where N is the total number of discs
Also, one can arrive at the answer by finding the number of moves for smaller number of discs
and then derive the pattern.
For 1 disc, number of moves = 1
For 2 discs, number of moves = 3
For 3 discs, number of moves = 7
For 4 discs, number of moves = 15
For 5 discs, number of moves = 31
289
How long would it take for him to cut 48 pieces? He can not fold the strip and also, can not stack
two or more strips and cut them together.
SubmiAnswer
47 seconds.
To get 48 pieces, the boy have to put only 47 cuts. i.e. he can cut 46 pieces in 46 seconds. After
getting 46 pieces, he will have a 2 inches long piece. He can cut it into two with just a one cut in 1
second. Hence, total of 47 seconds.tted by : Kimi
Each batsman scored 10 runs more than his immediate batsman. The lowest score was 10 runs.
How much did each one of them score
Answer
A simple one. Use the given facts and put down all the players in order. The order is as follow
with Harbhajan, the highest scorer and Laxman, the lowest scorer.
1. Harbhajan
2. Ganguly
3. Dravid
4. Badani, Agarkar
5. Sachin
6. Laxman
Also, as the lowest score was 10 runs. Laxman must have scored 10, Sachin 20, Badani &
Agarkar 30 and so on.
1. Harbhajan - 60 runs
2. Ganguly - 50 runs
3. Dravid - 40 runs
4. Badani, Agarkar - 30 runs each
5. Sachin - 20 runs
6. Laxman - 10 runs
Consider Statement 2:
As Statement 1 is false, Statement 9 and Statement 10 both are false i.e. there are three
consecutive true statements.
1 2 3 4 5 6 7 8 9 10
False - - - - True - - False False
Let\'s assume that Statement 3 is false i.e. there are no three consecutive false statements. It
means that Statement 2 and Statement 8 must be true, else there will be three consecutive false
statements.
1 2 3 4 5 6 7 8 9 10
False True False - - True - True False False
Also, atleast two of Statements 4, 5 and 7 must be true as there are three consecutive true
statements.
According to Statement 8, the number that is to be found is the percentage of true statements.
Hence, number is either 50 or 60. Now if Statement 7 is true, then the number of each true
statement divides the number, that is to be found. But 7 and 8 do not divide either 50 or 60.
Hence, Statement 7 is false which means that Statement 4 and 5 are true. But Statement 5
contradicts the Statement 8. Hence, our assumption that Statement 3 is false is wrong and
Statement 3 is true i.e. there are 3 consecutive false statements which means that Statement 8
is false as there is no other possibilities of 3 consecutive false statements.
1 2 3 4 5 6 7 8 9 10
False - True - - True True False False False
According to Statement 7, the number of each true statement divides the number, that is to be
found. And according to Statement 5, the sum of the numbers of the true statements is the
number, that is to be found. For all possible combinations Statement 5 is false.
There 3 consecutive true statements. Hence, Statement 2 and Statement 4 are true.
291
1 2 3 4 5 6 7 8 9 10
False True True True False True True False False False
The divisors of 420, apart from 1 and itself are 2, 3, 4, 5, 6, 7, 10, 12, 14, 15, 20, 21, 28, 30, 35,
42, 60, 70, 84, 105, 140, 210. There are total of 22 divisors. Also, the sum of the numbers of the
true statements is 22 (2+3+4+6+7=22), which satisfies the third condition.
Ankit and Tejas divided a bag of Apples between them.
Tejas said, "It's not fair! You have 3 times as many Apples I have." Ankit said, "OK, I will give you
one Apple for each year of your age." Tejas replied, "Still not fair. Now, you have twice as many
Apples as I have." "Dear, that's fair enough as I am twice older than you.", said Ankit.
Ankit went to Kitchen to drink water. While Ankit was in Kitchen, Tejas took apples from Ankit's
pile equal to Ankit's age.
At the end, Ankit and Tejas, both have the same number of apples.
Let's assume that initially Tejas got N apples and his age is T years. Hence, initially Ankit got 3N
apples and his age is 2T years.
Initially 3N N
It is given that after Ankit gave T apples to Tejas, Ankit had twice as many apples as Tejas had.
3N - T = 2*(N + T)
3N - T = 2N + 2T
N = 3T
From the table, at the end Ankit have (3N - 3T) apples and Tejas have (N + 3T) apples.
Substituting N = 3T, we get
Ankit's apples = 3N - 3T = 9T - 3T = 6T
Tejas's apples = N + 3T = 3T + 3T = 6T
292
Thus, at the end Ankit and Tejas, both have the same number of apples.
On evey Sunday Amar, Akbar and Anthony lunch together at Preetam-Da-Dhaba where they
order lassi based on following facts.
1. Unless neither Amar nor Akbar have lassi, Anthony must have it.
2. If Amar does not have lassi, either Akbar or Anthony or both have it.
3. Anthony has lassi only if either Amar or Akbar or both have it.
4. Akbar and Anthony never have lassi together.
Amar and Anthony both have lassi whereas Akbar never does.
Fact (2) can be alternatively stated that "either Amar or Akbar or Anthony must have
lassi".
From Fact (3), it can be infered that either Amar or Akbar must have lassi.
Now, from Fact (1), it is apparent that Anthony too must have lassi. But according to Fact
(4), Akbar cannot have lassi when Anthony does.
Brain Teaser No : 00191
B R W Q H L F K W H J K Q I B W K
Q I C E D W Z B G W K K M I K E
Z B G Q H S K Z B G J K Z K W
B U U Z B G J D B H F W.
Answer
Start with ZBG and ZBGJ. It should be either "the/then" or "you/your" combination as they appear
more.
B R W Q H L F K W H J K Q I B W K
o b s t a c l e s a r e t h o s e
293
Q I C E D W Z B G W K K M I K E
t h i n g s y o u s e e w h e n
Z B G Q H S K Z B G J K Z K W
y o u t a k e y o u r e y e s
B U U Z B G J D B H F W.
o f f y o u r g o a l s.
Brain Teaser No : 00001
At what time immediately prior to Six O'clock the hands of the clock are exactly opposite to
each other. Give the exact time in hours, minutes and seconds.
Answer
It is obvious that between 5 O'clock and 6 O'clock the hands will not be exactly opposite to each
other. It is also obvious that the hands will be opposite to each other just before 5 O'clock. Now to
find exact time:
The hour hand moves 1 degree for every 12 degrees that the minute hand moves. Let the hour
hand be X degree away from 5 O'clock. Therefore the minute hand is 12X degree away from 12
O'clock.
Angle between minute hand and 12 O'clock + Angle between 12 O'clock and 4 O'clock + Angle
between 4 O'clock and hour hand = 180
12X + 120 + (30-X) = 180
11X = 30
Hence X = 30/11 degrees
(hour hand is X degree away from 5 O'clock)
Therefore the exact time at which the hands are opposite to each other is
= 4 hrs. 54 min. 32.74 seconds
Ali Baba had four sons, to whom he bequeathed his 39 camels, with the proviso that the legacy
be divided in the following way :
The oldest son was to receive one half the property, the next a quarter, the third an eighth and the
youngest one tenth. The four brothers were at a loss as how to divide the inheritance among
294
themselves without cutting up a camel, until a stranger appeared upon the scene.
Dismounting from his camel, he asked if he might help, for he knew just what to do. The brothers
gratefully accepted his offer.
Adding his own camel to Ali Baba's 39, he divided the 40 as per the will. The oldest son received
20, the next 10, the third 5 and the youngest 4. One camel remained : this was his, which he
mounted and rode away.
Scratching their heads in amazement, they started calculating. The oldest thought : is not 20
greater than the half of 39? Someone must have received less than his proper share ! But each
brother discovered that he had received more than his due. How is it possible?
Answer
They took their percentages from 40 and not from 39, so they got more than their share.
And the stranger got 1/40 of 40 = 1 which is 0.025 more (As he is not supposed to get anything)
All these fractions add to = 0.5 + 0.25 + 0.125 + 0.1 + 0.025 = 1 which stranger took away.
There is a family party consisting of two fathers, two mothers, two sons, one father-in-law, one
mother-in-law, one daughter-in-law, one grandfather, one grandmother and one grandson.
There are total 2 couples and a son. Grandfather and Grand mother, their son and his wife and
again their son. So total 5 people.
Grandfather, Grandmother
|
|
Son, wife
|
|
Son
A man went into a fast food restaurant and ate a meal costing Rs. 105, giving the accountant a
Rs. 500 note. He kept the change, came back a few minutes later and had some food packed for
his girl friend. He gave the accountant a Rs. 100 note and received Rs. 20 in change. Later the
bank told the accountant that both the Rs. 500 and the Rs. 100 notes were counterfeit.
How much money did the restaurant lose? Ignore the profit of the food restaurant.
Answer
He lost Rs.600
First time restaurant has given food worth Rs.105 and Rs. 395 change. Similarly second time,
food worth Rs.80 and Rs.20 change. Here, we are not considering food restaurant profits.
S L I D E
295
- D E A N
---------
3 6 5 1
Each of seven digits from 0-9 are represented by a different letter above such that the subtraction
is true.
Let's assign possible values to each letter and then use trial-n-error.
S must be 1.
Then D (under L) must be greater than 5. If D is 6, then L is 0. But then A must be 0 or 1 which is
impossible. Hence, the possible values of D are 7, 8 or 9.
Now using trial-n-error, we get S=1, I=2, L=3, A=4, N=5, E=6 and D=9
S L I D E 1 3 2 9 6
- D E A N - 9 6 4 5
-------------- --------------
3 6 5 1 L E N S
Hence, 3651 represents LENS.
Adam, Burzin, Clark and Edmund each live in an apartment. Their apartments are arranged in a
row numbered 1 to 4 from left to right. Also, one of them is the landlord.
1. If Clark's apartment is not next to Burzin's apartment, then the landlord is Adam and lives
in apartment 1.
2. If Adam's apartment is right of Clark's apartment, then the landlord is Edmund and lives in
apartment 4.
3. If Burzin's apartment is not next to Edmund's apartment, then the landlord is Clark and
lives in apartment 3.
4. If Edmund's apartment is right of Adam's apartment, then the landlord is Burzin and lives
in apartment 2.
Answer
Assume each statement true, one at a time and see that no other statement is contradicted.
296
Let's assume that Statement (1) is true. Then, Adam is the landlord and lives in apartment
1. Also, other three's apartments will be on the right of his apartment - which contradicts
Statement (4) i.e. If Edmund's apartment is right of Adam's apartment, then the landlord
is Burzin. Thus, Adam is not the landlord.
Let's assume that Statement (2) is true. Then, Edmund is the landlord and lives in
apartment 4. Also, other three's apartments will be on the left of his apartment - which
again contradicts Statement (4) i.e. If Edmund's apartment is right of Adam's apartment,
then the landlord is Burzin. Thus, Edmund is not the landlord either.
Let's assume that Statement (3) is true. Then, Clark is the landlord and lives in apartment
3. It satisfies all the statements for
(1) Adam - (2) Edmund - (3) Clark - (4) Burzin
Similarly, you can assume Statement (4) true and find out that it also contradicts.
Brain Teaser No : 00456
1. Among the three are B's legal spouse, J's sibling and P's sister-in-law.
2. B's legal spouse and J's sibling are of the same sex.
Answer
Note that a person's sister-in-law may be the wife of that person's brother or the sister of that
person's spouse.
1. If B's legal spouse is J, then J's sibling must be P and P's sister-in-law must be B.
2. If B's legal spouse is P, then P's sister-in-law must be J and J's sibling must be B.
It is given that B's legal spouse and J's sibling are of the same sex. Also, it is obvious that P's
sister-in-law is female. Then, B's legal spouse and J's sibling both must be males.
------------------------------------------------------
Case I J P B
Case II P B J
297
Case II is not possible as B & P are married to each other and both are male. Hence, J is
the married man.
Brain Teaser No : 00041
The formula to find number of diagonals (D) given total number of vertices or sides (N) is
N * (N - 3)
D = -----------
Alternatively, you can derive the formula as triange has 0 diagonals, quadrangel has 2,
pentagon has 5, hexagon has 9 and so on......
Hence the series is 0, 0, 0, 2, 5, 9, 14, ........ (as diagram with 1,2 or 3 vertices will have 0
diagonals).
Using the series one can arrive to the formula given above.
Brain Teaser No : 00076
If the cube is cut into 125 smaller cubes of exactly the same size, how many of the cubes will
have atleast 2 of their sides painted black?
Answer
44
36 of the cubes have EXACTLY 2 of their sides painted black, but because a cube with 3
of its sides painted black has 2 of its sides painted black, you must also include the corner
cubes. This was a trick question, but hopefully the title of the puzzle tipped you off to
this.
Brain Teaser No : 00238
Imagine a triangle of coins on a table so that the first row has one coin in it and the second
row has two coins in it and so on. If you can only move one coin at a time, how many moves
298
does it take to make the triangle point the other way?
For a triangle with two row it is one, for a triangle with three rows it is two, for a triangle with
four rows it is three.
Answer
It takes 5 moves to make the triangle with 5 rows point the other way.
________X
_______X X
____8 0 0 0 8
_____0 0 0 0
____X 0 0 0 X
_______8 8
________8
For traingle of any number of rows, the optimal number of moves can be achieved by moving the
vertically symmetrical coins i.e. by moving same number of coins from bottom left and right, and
remaining coins from the top.
For a triangle with an odd number of rows, the total moves require are :
(N2/4) - (N-4) Where N = 4, 6, 8, 10, ...
For a triangle with even number of rows, the total moves require are :
((N2-1)/4) - (N-4) Where N = 5, 7, 9, 11, ...
A man is going to an Antique Car auction. All purchases must be paid for in cash. He goes to
the bank and draws out $25,000.
Since the man does not want to be seen carrying that much money, he places it in 15
evelopes numbered 1 through 15. Each envelope contains the least number of bills possible of
any available US currency (i.e. no two tens in place of a twenty).
At the auction he makes a successful bid of $8322 for a car. He hands the auctioneer
envelopes number(s) 2, 8, and 14. After opening the envelopes the auctioneer finds exactly
the right amount.
Answer
299
Each envelope contains the money equal to the 2 raised to the envelope number minus 1. The
sentence "Each envelope contains the least number of bills possible of any available US
currency" is only to misguide you. This is always possible for any amount !!!
One more thing to notice here is that the man must have placed money in envelopes in such a
way that if he bids for any amount less than $25000, he should be able to pick them in terms of
envelopes.
Hence the amount in envelopes are $1, $2, $4, $8, $16, $32, $64, $128, $256, $512,
$1024, $2048, $4096, $8192, $8617
Last envelope (No. 15) contains only $8617 as total amount is only $25000.
Now as he bids for $8322 and gives envelope number 2, 8 and 14 which contains $2,
$128 and $8192 respectively.
The minute and the hour hand of a watch meet every 65 minutes.
How much does the watch lose or gain time and by how much?
Answer
The minute and the hour hand meet 11 times in 12 hours in normal watch i.e. they meet
after every
= (12 * 60) / 11 minutes
= 65.45 minutes
= 65 minutes 27.16 seconds
But in our case they meet after every 65 minutes means the watch is gaining 27.16
seconds.
Brain Teaser No : 00093
There is a number that is 5 times the sum of its digits. What is this number? Answer is not 0.
300
Answer
Let T be the digit in the tens place and U be the digit in the units place. Then, the number is 10*T
+ U, and the sum of its digits is T + U.
Thus, T / U = 4 / 5
One sales man sold one box out of them and then he says, "I have the same number of red balls
left out as that of blue."
Total no of balls = 5 + 7 + 14 + 16 + 18 + 29 = 89
Total number of balls are odd. Also, same number of red balls and blue balls are left out
after selling one box. So it is obvious that the box with odd number of balls in it is sold
out i.e. 5, 7 or 29.
Ekta got chocolates to give her friends on her Birthday. If she gives 3 chocolates to each
friend, one friend will get only 2 chocolates. Also, if she gives 2 chocolates to each friends, she
will left with 15 chocolates.
How many chocolates Ekta got on her Birthday? and how many friends are there?
Answer
301
According to first case, if she gives 3 chocolates to each friend, one friend will get only 2
chocolates.
3*(F - 1) + 2 = C
Similarly, if she gives 2 chocolates to each friends, she will left with 15 chocolates.
2*F + 15 = C
Solving above 2 equations, F = 16 and C = 47. Hence, Ekta got 47 chocolates and 16 friends
Pooja and Esha met each other after long time. In the course of their conversation, Pooja asked
Esha her age. Esha replied, "If you reverse my age, you will get my husbund's age. He is of
course older than me. Also, the difference between our age is 1/11th of the sum of our age."
Assume that Esha's age is 10X+Y years. Hence, her hunsbands age is (10Y + X) years.
It is given that difference between their age is 1/11th of the sum of their age. Hence,
[(10Y + X) - (10X + Y)] = (1/11)[(10Y + X) + (10X + Y)]
(9Y - 9X) = (1/11)(11X + 11Y)
9Y - 9X = X + Y
8Y = 10X
4Y = 5X
Hence, the possible values are X=4, Y=5 and Esha's age is 45 years.
A fish had a tail as long as its head plus a quarter the lenght of its body. Its body was three-
quarters of its total length. Its head was 4 inches long.
It is obvious that the lenght of the fish is the summation of lenghts of the head, the body and the
tail. Hence,
Fish (F) = Head (H) + Body (B) + Tail (T)
But it is given that the lenght of the head is 4 inches i.e. H = 4. The body is three-quarters of its
total length i.e. B = (3/4)*F. And the tail is its head plus a quarter the lenght of its body i.e. T = H +
B/4. Thus, the equation is
F=H+B+T
F = 4 + (3/4)*F + H + B/4
F = 4 + (3/4)*F + 4 + (1/4)*(3/4)*F
F = 8 + (15/16)*F
(1/16)*F = 8
F = 128 inches
Assume that you have just heard of a scandal and you are the first one to know. You pass it on to
four person in a matter of 30 minutes. Each of these four in turn passes it to four other persons in
the next 30 minutes and so on.
How long it will take for everybody in the World to get to know the scandal?
302
Assume that nobody hears it more than once and the population of the World is approximately
5.6 billions.
Answer
You came to know of a scandal and you passed it on to 4 persons in 30 minutes. So total (1+4) 5
persons would know about it in 30 minutes.
By the end of one hour, 16 more persons would know about it. So total of (1+4+16) 21 persons
would know about it in one hour.
Similarly, the other (1+4+16+64) persons would have know about it in one and a half hours.
(1+4+16+64+256) persons would have know about it in two hours and so on...
It can be deduced that the terms of the above series are the power of 4 i.e. 4^0, 4^1, 4^2, 4^3
and so on upto (2N+1) terms. Also, the last term would be 4^2N where N is the number of hours.
The sum of the series must be 5.6 billions. Hence, equating the sum of the series with 5.6 billions,
we get N=8 hours.
E F G
I
Each of the digits from 1 to 9 is represented by a different letter above. Also, A + B + C = C + D +
E = E + F + G = G + H + I = 13
E represents 4.
Find out all possible groups of three different numbers that add up to 13 and arrange them
according to given condition.
It is clear that 9 must go with 1 and 3. Also, no digit may be used in more than two sums. Hence,
there are 2 cases:
Case I: If 8 goes with 1 and 4, then 7 goes with 2 and 4, then 6 goes with 2 and 5.
Case II: If 8 goes with 2 and 3, then 7 goes with 2 and 4, then 6 goes with 3 and 4.
303
But in case II, 3 is used in three sums. Hence, Case I is correct. And the possible arrangements
are:
9 3 1 5 6 2
8 7
4 7 2 4 8 1
6 3
5 9
Thus, E must be 4.
A, B and C are three points on a straight line, not necessarily equidistant with B being between A
and C. Three semicircles are drawn on the same side of the line with AB, BC and AC as the
diameters. BD is perpendicular to the line ABC, and D lies on the semicircle AC.
If the funny shaped diagram between the three semicircles has an area of 1000 square cms, find
the length of BD.
304
Answer
Given that funny shaped diagram beween three semicircles has an area of 1000 square cms.
[PI/2 * (AC/2)^2] - [PI/2 * (AB/2)^2] - [PI/2 * (BC/2)^2] = 1000
PI/8 * [AC^2 - AB^2 - BC^2] = 1000
PI * [(AB+BC)^2 - AB^2 - BC^2] = 8000
PI * [2*AB*BC] = 8000
AB * BC = 4000/PI
Gomzi has 3 timepieces in his house - a wall clock, an alarm clock and a wristwatch. The
wristwatch is always accurate, whereas the wall clock gains 2 minutes everyday and the alarm
clock loses 2 minutes everyday.
At exactly midnight last night, all three watches were showing the same time.
305
If today is 25 July 2003, then on which date all three clocks will show the same time again?
Answer
All three clocks will show the same time again on midnight between 19 July 2004 and 20
July 2004.
If a clock gains 2 minutes everyday, then it would be 720 minutes ahead after 360 days. Thus,
after 360 days, it will show the same time again.
Similary, if a clock loses 2 minutes everyday, then it would be 720 minutes behind after 360 days.
Thus, after 360 days, it will show the same time again.
Thus, after 360 days all three clocks will show the same time again i.e. midnight between 19 July
2004 and 20 July 2004.
You have 9 marbles. 8 marbles weigh 1 ounce each, & one marble weighs 1.5 ounces. You are
unable to determine which is the heavier marble by looking at them. You have a weighing scale
that consists of 2 pans, but the scale is only good for 2 total weighings.
How can you determine which marble is the heaviest one using the scale & in 2 weighings?
Answer
Take any 2 groups and place them on each pan. If they balance, remove the marbles from the
pans, & place any 2 of the marbles from the remaining unweighed group on the pans, 1 on each
pan.
If one is heavier, it is the heavier marble, but if they balance, the remaining unweighed marble is
the heavier one.
If your first weighing does not balance, remove the marbles from the lighter pan, & place 1 marble
on each pan from the heavier pan. The heavier 1 is the 1.5 ounce marble, but if they balance,
then the marble from the heavy pan from the first weighing that was not weighed in the second
weighing is the heavy 1.
Once a week a wagon driver leaves his hut and drives his wagon to the river dock to pick up
supplies for his town. At 4:05 PM, one-fifth of the way to the dock, he passes the Temple. At 4:15
PM, one-third of the way, he passes the Preetam-Da-Dhabaa.
Answer
5:05 PM
At 4:05 PM, the wagon driver passes the temple, one-fifth of the way to the dock. Also, at
4:15 PM, he passes the Preetam-Da-Dhabaa, one-third of the way. Thus, he travels 2/15
(1/3 - 1/5) of the distance in 10 minutes.
306
At 4:15 PM, he has already travelled 1/3 of the distance. Thus 2/3 of the way is
remaining, which can be travelled in
= ( (2/3) * 10 ) / (2/15)
= 50 minutes
• The escape routes were North Road, South Road, East Road and West Road
• None of the prisoners took the road which was their namesake
• Mr. East did not take the South Road
• Mr.West did not the South Road
• The West Road was not taken by Mr. East
What road did each of the prisoners take to make their escape
Answer
Put all the given information into the table structure as follow:
Mr. North No
Mr. South No
Mr. East No No No
Mr. West No No
Now from table, two things are obvious and they are:
Put this information into the table, Also keep in mind that the prisoners head towards different
directions after escaping.
Mr. South No No
307
Mr. West No No No
Shahrukh speaks truth only in the morning and lies in the afternoon, whereas Salman speaks
truth only in the afternoon and lies in the morning.
Want to confirm it? Consider following 4 possible answers and check for its truthness individually.
A rich man died. In his will, he has divided his gold coins among his 5 sons, 5 daughters and a
manager.
According to his will: First give one coin to manager. 1/5th of the remaining to the elder son. Now
give one coin to the manager and 1/5th of the remaining to second son and so on..... After giving
coins to 5th son, divided the remaining coins among five daughters equally.
All should get full coins. Find the minimum number of coins he has?
Answer
We tried to find out some simple mathematical method and finally we wrote small C program to
find out the answer. The answer is 3121 coins.
11550
Here there are 20 rows and 10 columns or vice versa. Hence, total possible rectangles
= ( 20 + 19 + 18 + 17 + 16 + .... + 3 + 2 + 1 ) * ( 10 + 9 +8 + 7 + .... + 3 + 2 + 1)
= ( 210 ) * (55)
= 11550
If you don't believe it, try formula on some smaller grids like 4x2, 3x2, 3x3 etc...
If A+B=C, D-C=A and E-B=C, then what does D+F stands for? Provide your answer in letter terms
as well as in number terms.
Submitted by : David
Answer
J or 10
A simple one.
Assume that each character represents the number equivalent to the position in the alphabet i.e.
A = 1, B = 2, C = 3, D = 4 and so on. Now let's check our assumption.
A + B = C i.e. 1 + 2 = 3
D - C = A i.e. 4 - 3 = 1
E - B = C i.e. 5 - 2 = 3
The next day, through the industry of her hens, the number left over had been doubled, and she
sold the same number as the previous day.
On the third day the new remainder was tripled, and she sold the same number as before.
On the fourth day the remainder was quadrupled, and her sales the same as before.
On the fifth day what had been left over were quintupled, yet she sold exactly the same as on all
the previous occasions and so disposed of her entire stock.
What is the smallest number of eggs she could have taken to market the first day, and how many
did she sell daily? Note that the answer is not zero.
Submitted
Answer
She took 103 eggs to market on the first day and sold 60 eggs everyday.
309
Let's assume that she had N eggs on the first day and she sold X eggs everyday. Putting down
the given information in the table as follow.
Days Eggs at the start of the day Eggs Sold Eggs Remaining
Day 1 N X N-X
It is given that she disposed of her entire stock on the fifth day. But from the table above, the
number of eggs remaining are (120N-206X). Hence,
120N - 206X = 0
120N = 206X
60N = 103X
The smallest value of N and X must be 103 and 60 respectively. Hence, she took 103 eggs to
market on the first day and sold 60 eggs everyday.
John lives in "Friends Society" where all the houses are in a row and are numbered sequentially
starting from 1. His house number is 109.
Jessy lives in the same society. All the house numbers on the left side of Jessy's house add up
exactly the same as all the house numbers on the right side of her house.
What is the number of Jessy's house? Find the minimal possible answer.
Answer
Let's assume that in the "Friends Society" there are total N houses numbered from 1 to N and
Jessy's house number is X.
Now it is given that all the house numbers on the left side of Jessy's house add up exactly the
same as all the house numbers on the right side of her house. Hence,
1 + 2 + 3 + ..... + (X-1) = (X+1) + (X+2) + (X+3) + ..... + N
Both the sides of the above equations are in A.P. Hence, using A.P. summation formaula,
Now, using Trial and Error method to find values of N and X such that above equation is satisfied,
we get
310
1. N = 8, X = 6
2. N = 49, X = 35
3. N = 288, X = 204
4. N = 1681, X = 1189
5. N = 9800, X = 6930
But we require minimal possible answer and it is given that John's house number is 109. It means
that there are atleast 109 houses. Hence, first two are not possible. And the answer is : there are
288 houses and Jessy's house number is 204.
Makayla had $1.19 in change. None of the coins was a dollar.
Nicole ask her for change for a dollar, but Makayla could not make change.
As it is given that Makayla had $1.19, it means she would have four pennies. Now, the remaining
$1.15 in coins must not add up for exactly a dollar. Therefore she would not have 4 quarters or 2
quarters and 5 dimes. But she would have either 1 quarter or 3 quarters. Hence, there are 2
solutions.
Solution I
1 Quarter, 9 Dimes, 4 Pennies (0.25 + 0.90 + 0.04 = $1.19)
Solution II
3 Quarters, 4 Dimes, 4 Pennies (0.75 + 0.40 + 0.04 = $1.19)
A group of friends went on a holiday to a hill station. It rained for 13 days. But when it rained in
the morning, the afternoon was lovely. And when it rained in the afternoon, the day was preceded
by clear morning.
Altogether there were 11 very nice mornings and 12 very nice afternoons. How many days did
their holiday last?
Answer
Substitute digits for the letters to make the following Division true
311
Y F Y
-----------
A Y | N E L L Y
| N L Y
----------------
P P L
P N H
----------
N L Y
N L Y
----------
0 0 0
Note that the leftmost letter can't be zero in any word. Also, there must be a one-to-one
mapping between digits and letters. e.g. if you substitute 3 for the letter N, no other letter can
be 3 and all other N in the puzzle must be 3.
Submitted by : Calon
Answer
See the pattern of the Y. AY * Y = NLY i.e. Y is multiplied by Y and the last digit of the answer is
also Y. Thus, the value of Y would be 5 or 6.
Also,
H=0 as L - H = L
P = 2N as P - N = N
L - Y = P = 2N
E-L=p
Let's find out the minimum possible values. If N=1, then P=2, Y=5, L=7 and E=9. Note that the
value of Y can not be 6 as it makes L=8 and E=10 which is not possible. Hence, Y=5, N=1, P=2,
L=7, E=9, H=0
Now, using trial-n-error or rather solving F*AY=PNH, we get F=6 and A=3.
5 6 5 Y F Y
----------- -----------
3 5 | 1 9 7 7 5 A Y | N E L L Y
| 1 7 5 | N L Y
----------- -----------
312
2 2 7 P P L
2 1 0 P N H
----------- -----------
1 7 5 N L Y
1 7 5 N L Y
----------- -----------
0 0 0 0 0 0
---------------------------------------------
| | | |
| | ?
-------- ------------------
| | | | |
| |
----- -------
| | | | |
Answer
Name of the person and number of his children are related by some pattern.
The number of children to any person is the sum of the values represented by vowels in his
313
name.
RATISH = 0(A) + 2(I) = 2
OM = 3(O) = 3
AMIT = 0(A) + 2(I) = 2
ASHOK = 0(A) + 3(O) = 3
TRILOK = 2(I) + 3(O) = 5
Major Jasbir is forming five-person Special Task Group. The group must contain one leader, two
bomb-experts and two soldiers.
P, Q and R are possible bomb-experts. R, S and T are possible leaders. U, V and W are possible
soldiers. Also, P and R prefers to work with each other in the same team. T prefers to work only if
V works.
As 2 bomb-experts to be selected from the given 3 and also P & R prefers to work together, PR
must be there in all the possible Groups. Also, T prefers to work only if V works. It doesn't mean
that V won't work without T.
PR - T - UV
PR - T - VW
PQ - R - UV
PQ - R - VW
PQ - R - WU
Can you tell which one is fake? Ignore the fact that four of the code-words are of the same length.
Answer
In the village called TALAJA, only three TV channels are available - Moon Plus, Mony and
Mee TV.
Out of 4000 TV viewers in the village, 1500 watch Moon TV, 2000 watch Mony and 2500
watch Mee TV.
314
Amongst these, 500 viewers watch Moon Plus and Mony, 800 watch Moon Plus and Mee TV,
and 1000 watch Mony and Mee TV.
Answer
total viewers who watch only Moon Plus and Mony = 500-X
total viewers who watch only Moon Plus and Mee TV = 800-X
total viewers who watch only Mony and Mee TV = 1000-X
He replied, pointing at the portrait: "Brothers and sisters have I none, but this man's son is my
father's son."
"my father's son" is the man himself as he do not have any brothers and sisters. So the statement
reduces to "this man's son is myself." Now it is clear that the portrait is of his father.
Given the following facts:
315
6. Hemant is older than Gurmit.
From above 3 deductions, Eshrat is younger than Dinesh, Farukh, Irfan, Gurmit, Jatin and
Chandu.
Also,
From (3) Chandu is younger than Amit and Irfan.
From (4) Hemant is younger than Farukh and Bhavin.
From (6) Gurmit is younger than Hemant.
From above 3 deductions, Gurmit is younger than Farukh, Bhavin and Hemant. Also, Chandu is
younger than Amit and Irfan. But as seen earlier, Eshrat is younger than Gurmit and Chandu.
Thus, Milan gave six movie names, all five letter words. But he saw some other movie with five
letter word. Moreover, each of the six movie names mentioned above has exactly two letters
common with the movie he saw. (with the same positions)
The six movie names are - MONEY, JOHNY, BABLU, BHABI, ROBOT and BUNNY.
Compare MONEY and JOHNY. They have O common at the second place and Y common at the
fifth place. Also, they can't have two different letters each, common with the required movie as the
letters in remaining three places are all different. Thus, the required movie must have either O at
the second place or Y at the fifth place or both.
Similarly, comparing JOHNY and BUNNY - the required movie must have either N at the fourth
place or Y at the fifth place or both. Also, comparing MONEY and BUNNY - the required movie
must have either N at the third place or Y at the fifth place or both.
From the above 3 deduction, either Y is at fifth place or O is at the second place and N is at the
316
third & fourth place. The later combination is not possible as BABLU, BHABI & ROBOT will need
at least 3 other letters which makes the required movie 6 letter long. Hence, the required movie
must have Y at the fifth place.
Now Y is not there in BABLU and BHABI at the fifth place and they have only B common at the
first place. Hence, B must be the first letter.
As B is at the first place and Y is at the fifth place and every movie has exactly 2 letters common
with the required movie. From BUNNY, the required movie do not have U at the second place and
N at the third and fourth place. Now looking at JOHNY and MONEY, they must have O common
at the second place.
Using the same kind of arguments for BABLU, BHABI and ROBOT, we can conclude that Milan
saw BOBBY.
Jim lies a lot. He tells the truth on only one day in a week.
As Jim tells truth only on one day in a week, his statement on day 1 and day 3 both can not be
false. Otherwise he tells truth on more than one days in a week. Also, all three statements are
mad on three consecutive days, statement made on day 1 and day 3 both can not be true. Thus,
either the statement made on day 1 or day 3 is true and other is false. Also, the statement made
on day 2 must be false i.e. day 1 is not Saturday, Friday or Wednesday.
Let's assume that the statement 1 is true. Then from the statement 3, day 1 must be either Friday
or Wednesday. But it is already deduced that day 1 is not Saturday, Friday or Wednesday.
Hence, the statement made on day 1 is false and the last statement is true. then from the
statement 1, day 3 must be either Monday or Tuesday. But it is already deduced that day 1 can
not be Saturday i.e. day 3 can't be Monday. Hence, Jim tells the truth on Tuesday.
How many hours does it take for 1 man to dig half a hole?
Submitted
Answer
What is the minimum number of moves the Rook needs to make, in order to pass over all the
squares on the chessboard and return to the original position?
Answer
16 moves
As a Rook can move any number of square sideways/forward, but not diagonally and there are 8
317
rows and 8 columns on the chessboard; the Rook needs minimum 16 moves to pass over all the
squares and return to the original position.
A farmer needs 8 gallons of water. He has only three unmared buckets, two 6 gallon and one 11
gallon bucket.
How can he collect 8 gallons of water using three unmarked buckets? Provide solution with
minimal water wastage.
Answer
Only 0 1 6 8 and 9 can be read upside down. So on rearranging these digits we get the answer
as 10968.
Jack and Jill are playing cards for a stake of $1 a game. At the end of the evening, Jack has won
3 games and Jill has won $3. How many games did they play?
Submitted by : Nathalie Drouin
Answer
They played total of 9 games. Jack won 3 games and Jill won 6 games.
If Jack has won three games and Jill has won $3, she lost a dollar for each loss, therefore she
has won 6 and lost 3 to make $3 and he won the other 3 that she lost!
All the statements by the two are false. How old are they really?
Answer
From first statement it is clear that Sam is over 40. Also, from next 2 statements it is clear that
Mala is less then 38. Hence the possibilities are :
Sam = 41, 42, 43, 44, 45, ......
Mala = 37, 36, 35, 34, 33, ......
It also says that the difference between their age is maximum 4 years. Hence, there is only one
possible pair i.e. 41 and 37, all other combination have differences more then 4.
On the way back to the home, he took 3 hours to reach as wind was in the same direction.
If there is no wind, how much time does he take to travel from home to church?
Answer
A person took 4 hours to reach church. So speed while travelling towards church is D/4.
Similarly, he took 3 hours to reach home. So speed while coming back is D/3.
There is a speed difference of 7*D/12, which is the wind helping person in 1 direction, & slowing
him in the other direction. Average the 2 speeds, & you have the speed that person can travel in
no wind, which is 7*D/24.
Hence, person will take D / (7*D/24) hours to travel distance D which is 24/7 hours.
What are the minimum number of telephone calls needed so that all of the them know
everything?
Answer
319
Divide the N secret agents into two groups. If N is odd, one group will contain one extra agent.
Consider first group: agent 1 will call up agent 2, agent 2 will call up agent 3 and so on. Similarly
in second group, agent 1 will call up agent 2, agent 2 will call up agent 3 and so on. After (N - 2)
calls, two agents in each the group will know anything that anyone knew in his group, say they
are Y1 & Y2 from group 1 and Z1 & Z2 from group 2.
Now, Y1 will call up Z1 and Y2 will call up Z2. Hence, in next two calls total of 4 agents will know
everything.
Let\'s take an example. Say there are 4 secret agents W, X, Y & Z. Divide them into two groups of
2 each i.e. (W, X) and (Y, Z). Here, 4 telephone calls are required.
1. W will call up X.
2. Y will call up Z.
3. W, who knows WX will call up Y, who knows YZ.
4. X, who knows WX will call up Z, who knows YZ.
Take an another example. Say there are 5 secret agents J, K, L, M & N. Divide them into two
groups i.e. (J, K) and (L, M, N). Here, 6 telephone calls are required.
1. J will call up K.
2. L will call up M.
3. M will call up N. Now M and N know LMN.
4. J, who knows JK will call up M, who knows LMN.
5. K, who knows JK will call up N, who knows LMN.
6. L will call up to anyone of four.
Mrs. F has invited several wives of delegates to the United Nations for an informal luncheon. She
plans to seat her 9 guests ina row such that each lady will be able to converse with the person
directly to her left and right. She has prepared the following list.
How many distinct seating arrangements are possible? Give all possible seating arrangements.
320
Mrs. J and Mrs. H must be together and Mrs. J must be at the end as Mrs. J speaks only Russian
and Mrs. H is the only other Russian speaker.
Mrs. L speaks only French and there are two others - Mrs. G and Mrs. M - who speak French.
Here there are 2 cases.
o CASE BA : Mrs. G seats left and Mrs. M seats right to Mrs. L i.e. GLM
321
o CASE BB : Mrs. M seats left and Mrs. G seats right to Mrs. L i.e. MLG
Then, Mrs. N must seat next to Mrs. M. Now, we have a group of four NMLG
where Mrs. G and Mrs. N speak English. Thus, the possible seating arrangement
is JHxxxX, where x is the individual English speakers and X is the group of four
females with English speakers at the both ends. Thus, there are 4! different ways
i.e. 24 ways.
The easiest way is to find the Least Common Multiple (LCM) of 2, 3, 4, 5, 6, 7, 8 and 9. And
subtract 1 from it.
The LCM of 2, 3, 4, 5, 6, 7, 8 and 9 is given by 2520. Hence, the required number is 2519
Three friends divided some bullets equally. After all of them shot 4 bullets the total number of
bullets remaining is equal to the bullets each had after division. Find the original number divided.
Answer
18
But it is given that,after they shot 4 bullets each, total number of bullets remaining is
equal to the bullets each had after division i.e. X
322
Everyday in his business a merchant had to weigh amounts from 1 kg to 121 kgs, to the
nearest kg. What are the minimum number of different weights required and how heavy
should they be?
O N E
O N E
O N E
+ O N E
-------
T E N
Answer
1 8 2
1 8 2
1 8 2
+ 1 8 2
------
7 2 8
A man is on a search for Atlantis and comes upon an island where all the inhabitants know
whether Atlantis is still around or not.
However, all of the inhabitants are either Fairies or Trolls and they all use a spell to appear
humanoid so you cannot tell which is which. And the Faries always tell the truth and the Trolls
always lie, but there is a slight complication, some of the Fairies have gone insane and always lie
and some of the Trolls have also gone insane and always tell the truth.
So here is your task: you must ask the first inhabitant that you come to ONE question and from
that ONE question you must determine wether Atlantis is still around or not.
Answer I"Is the statement that you are reliable equivalent to the statement that Atlantis is still
around?"
323
Answer II"Do you believe that the Statement that you are a Fairy is equivalent to the
statement that Atlantis is still around?"
Brain Teaser No : 00276
A frog starts climbing 15 feet wall. Each hour he climbs 3 feet and rests for 30 minutes. During
rest, he slips back 2 feet.
How many hours does the frog take to reach the top?
Answer
19 hours
A frog climbs 1 foot per 1 1/2 hours as during 30 minutes rest he slips back 2 feet. This way he
will climb 12 feet in 18 hours. In next hour he will climb 3 more feet i.e. he will complete 15 feet in
19 hours and will reach the top of the wall.
If a bear eats 65 pounds in fish every day EXCEPT every 6th day which it only eats 45 pounds of
fish.
If the bear continues this, how many pounds of fish will it eat in 200 days?
Submitted by : David
Answer
It is given that on every 6th day beareats 45 pounds of fish i.e. on day number 6, 12, 18, 24, ....
192, 198 the bear eats 45 pounds of fish.
Now while connecting the points you have to follow one rule - the lines cannot cross over each
other.
A B C
1 2 3
PS : You can arrange the points in order as long as the lines DO NOT cross over each other.
Answer
There is solution, if you consider 3 dimensions. Consider a circular base and a line
perpendicular to it passing from the center. Now take any 3 points along the perimeter of
the circular base as points 1, 2 and 3. Similarly take any 3 points along the perpendicular
324
line as points A, B and C. Now it is quite simple to join each of points A, B and C with
points 1, 2 and 3 without any of the lines crossing each other.
The other possible 3D structure is Pyramid. Take points 1, 2 and 3 as a vertices of the
triangular base and points A, B and C along the height of the Pyramid which is
perpendicular to the triangular base and passing through the apex.
Brain Teaser No : 00477
Suppose five bales of hay are weighed two at a time in all possible ways. The weights in
pounds are 110, 112, 113, 114, 115, 116, 117, 118, 120, and 121.
Answer
Let's assume that the weight of five bales are B1, B2, B3, B4 and B5 pounds respectively. Also,
B1 <= B2 <= B3 <= B4 <= B5
It is given that five bales of hay are weighed two at a time in all possible ways. It means that each
of the bale is weighted four times.
Thus,
4*(B1 + B2 + B3 + B4 + B5) = (110 + 112 + 113 + 114 + 115 + 116 + 117 + 118 + 120 + 121)
4*(B1 + B2 + B3 + B4 + B5) = 1156
(B1 + B2 + B3 + B4 + B5) = 289 pounds
Now, B1 and B2 must add to 110 as they are the lightest one.
B1 + B2 = 110
Similarly, B4 and B5 must add to 121 as they are the heaviest one.
B4 + B5 = 121
Also, it is obvious that B1 and B3 will add to 112 - the next possible higher value. Similarly, B3
and B5 will add to 120 - the next possible lower value.
B1 + B3 = 112
B3 + B5 = 120
Hence, the weight of five bales are 54, 56, 58, 59 and 62 pounds.
The color of the horse can be any color other than Black and Brown.
If the color of the horse is Grey - Pinto and Sandy are telling truth whereas Andy is lying.
If the color of the horse is other than Black, Brown and Grey - Pinto is telling truth
whereas Sandy and Andy are lying.
You must have noticed that for the given conditions, Pinto is always telling truth whereas
Andy is always lying
Brain Teaser No : 00258
Three convicts are brought into the warden's office. He says he can parole one of them and to
decide which one he will parole he takes out 5 hats (3 red and 2 white). He stands behind them and
places a hat on each one of their heads and puts the other two remaining hats in a drawer.
He tells the prisioners they can look at the others hats and if they can tell which hat they have on
they will be the one who is paroled.
The first man looks at the other two and says, "I don't know."
The second man looks at the others hats and says, "I don't know."
The third man who is blind says, "Even though I have not the gift of sight I can tell by what the
others have said that the color of my hat is..."
What color is the blind mans hat and how does he know?
Submitted
326
Answer
Hello sajeesh murali
The color of blind man's hat is Red. • my Answers
• my Favourites
It is sure that the first man saw either both Red hats or one White • Modify Personal Info
hat and one Red hat. There are 6 such possibilities: • Subscribe
1) R R R
• Logout
2) R R W
3) R W R
4) W R R
5) W R W
6) W W R
In all above possibilities, the first man won't be sure of the color of
his hat.
Now, the second man knows that the first man saw either both • Jigsaw Puzzle
Red hats or one White hat and one Red hat. And, he also knows • Join the Dots
that its one of the above 6 possibilities. (like we know ;)) But he • Marbles Game
says, "I don't know". That means that (2) and (5) are not the • Balls Game
possibilities as in either case he would be sure of the color of his • Towers of Hanoi
hat (Red) by just looking at the third man's color of hat (White).
• Think Number
Now, the blind man knows that there are just 4 possibilities - (1),
• Find A Day
(3), (4), (6) - and in all, the color of his hat is Red.
Three Gold (G) coins, three Silver (S) coins and three Copper (C) coins are arranged in a single
row as follow:
G S C G S C G S C
What is the minimum number of moves required to get all the coins in following order?
C C C S S S G G G
Show all moves.
Answer
327
Move Order of Coins
0 G S C G S C G S C
1 G S G S C G S C C
2 G S C G S C C S G
3 G S C G S C C S G
4 G S C C S G S C G
5 G S C C S C S G G
6 G S C C C S S G G
7 C C C S S G G S G
8 C C C S S S G G G
A fly is flying between two trains, each travelling towards each other on the same track at 60
km/h. The fly reaches one engine, reverses itself immediately, and flies back to the other engine,
repeating the process each time.
The fly is flying at 90 km/h. If the fly flies 180 km before the trains meet, how far apart were the
trains initially?
Answer
The fly is flying at the speed of 90 km/h and covers 180 km. Hence, the fly flies for 2 hours after
trains started.
It's obvious that trains met 2 hours after they started travelling towards each other. Also, trains
were travelling at the speed of 60 km/h. So, each train traveled 120 km before they met.
What is the minimum number of numbers needed to form every number from 1 to 7,000?
Example: To form 4884, you would need 2 4s & 2 8s. 4822 requires a 4, a 8, & 2 2s, but you
would not count the numbers again that you had already counted from making 4884.
Answer
36
If each drink costs 50p, how much minimum money do you have to put into the machine to work
out which button gives which selection?
Submitted
328
Answer
Put 50p and push the button for Random. There are only 2 possibilities. It will give either Tea or
Coffee.
• If it gives Tea, then the button named Random is for Tea. The button named Coffee is for
Random selection. And the button named Tea is for Coffee.
• If it gives Coffee, then the button named Random is for Coffee. The button named Tea is
for Random selection. And the button named Coffee is for Tea.
Thus, you can make out which button is for what by putting just 50p and pressing Random
selection first.
You have 13 balls which all look identical. All the balls are the same weight except for one. Using
only a balance scale, can find the odd one out with only 3 weighings?
Is it possible to always tell if the odd one out is heavier or lighter than the other balls?
Submitted by : Brett Hurrell
Answer
It is always possible to find odd ball in 3 weighings and in most of the cases it is possible to tell
whether the odd ball is heavier or lighter. Only in one case, it is not possible to tell the odd ball is
whether heavier or lighter.
2. One of these 8 balls is the odd one. Name the balls on heavier side of the scale as H1,
H2, H3 and H4. Similarly, name the balls on the lighter side of the scale as L1, L2, L3 and
L4. Either one of H's is heavier or one of L's is lighter. Weigh (H1, H2, L1) against (H3,
H4, X) where X is one ball from the remaining 5 balls in intial weighing.
o If both are equal, one of L2, L3, L4 is lighter. Weigh L2 against L3.
If both are equal, L4 is the odd ball and is lighter.
If L2 is light, L2 is the odd ball and is lighter.
If L3 is light, L3 is the odd ball and is lighter.
o If (H1, H2, L1) is heavier side on the scale, either H1 or H2 is heavier. Weight H1
against H2
If both are equal, there is some error.
If H1 is heavy, H1 is the odd ball and is heavier.
If H2 is heavy, H2 is the odd ball and is heavier.
3. One of the remaining 5 balls is the odd one. Name the balls as C1, C2, C3, C4, C5.
Weight (C1, C2, C3) against (X1, X2, X3) where X1, X2, X3 are any three balls from the
first weighing of 8 balls.
o If both are equal, one of remaining 2 balls is the odd i.e. either C4 or C5. Weigh
C4 with X1
If both are equal, C5 is the odd ball. But you can not tell whether it is
heavier or lighter.
If C4 is heavy, C4 is the odd ball and is heavier.
If C4 is light, C4 is the odd ball and is lighter.
o If (C1, C2, C3) is heavier side, one of C1, C2, C3 is the odd ball and is heavier.
Weigh C1 and C2.
If both are equal, C3 is the odd ball and is heavier.
If C1 is heavy, C1 is the odd ball and is heavier.
If C2 is heavy, C2 is the odd ball and is heavier.
o If (C1, C2, C3) is lighter side, one of C1, C2, C3 is the odd ball and is lighter.
Weigh C1 and C2.
If both are equal, C3 is the odd ball and is heavier.
If C1 is light, C1 is the odd ball and is lighter.
If C2 is light, C2 is the odd ball and is lighter.
How many squares are there in a 5 inch by 5 inch square grid? Note that the grid is made up of
one inch by one inch squares.
Submitted by : Kristin Monroe
Answer
You must have noticed one thing that total number squares possible of each size is always a
perfact square i.e. 25, 16, 9, 4, 1
330
For 1 by 1 grid, total squares = 12 = 1
For 2 by 2 grid, total squares = 22 + 12 = 5
For 3 by 3 grid, total squares = 32 + 22 + 12 = 14
For 4 by 4 grid, total squares = 42 + 32 + 22 + 12 = 30
For 5 by 5 grid, total squares = 52 + 42 + 32 + 22 + 12 = 55
Five horses ran in the race.
It's simple.
Let's find the possible places horses can finish. Possibilities are:
Sikandar - 2,3,4 (not 5th as Mughal Glory came one place after him)
Star - 2,3,4
Mughal Glory - 3,4,5
Zozo - 1,3 (not 4th & 5th as Rangila is two place after him)
Rangila - 3,5
If you added together the number of 2's in each of the following sets of numbers, which set would
contain the most 2's: 1-333, 334-666, or 667-999?
Answer
1-333
If one person sends the e-mail to two friends, asking each of them to copy the mail and send it to
two of their friends, those in turn send it to two of their friends and so on.
How many e-mails would have been sent by the time it did 30 sets?
Answer
2147483646
First person sent the mail to 2 persons. Those 2 sent the mail to 2 persons each, total 4 persons.
Now, those 4 person sent mail to total 8 persons, then 8 to 16 persons, 16 to 32 persons and so
on.... Hence, it a series of 2, 4, 8, 16, 32 upto 30 numbers
It is a Geometric series with common ratio 2 and first number is also 2. Summation of such series
331
is given by A * (Rn - 1) / (R - 1) where
A = First term
R = Common Ratio
n = total numbers
At the entrance to a members club stands a stranger seeking admission. A friend told him that
it's easy to get in. You just have to answer a question corrcetly! Answering wrong, however,
will result in being shot!
To live a little longer, the man waits in a back alley near the entrance for people to go in. After
a while a man comes to the entrance. The door warden asks him: "Twelve?" to which he
replies "Six!" and goes in.
Another man comes to the door. "Six?" the door warden asks, to which he replies "Three!" and
goes in.
"That's too good to be true" our friend thinks, and he was right. Because, when asked "Four?",
he answered "Two!" and was found dead in the alley.
Answer
The answer is the number of letters in the word spoken by the door warden.
Can a perfect sphere of diameter 7 cms. pass through the space between the big sphere, the wall
and the floor? Support your answer with valid arguments. Don't submit just "Yes" or "No".
Submit Users BrainVista Puzzle A Add to
Answer Answer (23) Answer Friend Favourite
332
For the sake of simplicity, consider two-dimension i.e view sphere as a two dimensional circle
with diameter 40 cms.
Now, as OY > OX i.e. smaller sphere requires more space than the space available. Hence,
smaller sphere of 7 cms diameter can not pass through the space between the big sphere, the
wall and the floor.
Now, the diameter of the inscribed circle of right angle triangle is given by d = a + b - c where a
<= b < c
The maximum possible diameter of the circle which can pass through the space between the
big
333sphere, the wall and the floor is
Submit Users BrainVista Puzzle A
Add
Answer Answer (23) Answer Friend
Sarika multiplied 414 by certain number and obtained 69958 as the answer. But she found that
there is some error in the answer - both the 9s in the answer are wrong and all the other digits are
correct.
If you divide 69958 by 414, you will get 168.98. Hence, assume some three digit number and
multiply it by 414 and use 6**58 as the answer.
4 1 4
-------------
* * *
* * * 0
* * * 0 0
-------------
6 * * 5 8
It is obvious that the last digit of the assumed number must be 7.
* * 7
4 1 4
-------------
* * 8
* * 7 0
* * 8 0 0
-------------
6 * * 5 8
Now, the second last digit of the assumed number must be 4 or 9. Also, the first digit of the
assumed number must be 1 as the first digit of the answer is 6. Using trial and error for above two
conditions, the answer is
1 4 7
4 1 4
-------------
5 8 8
334
1 4 7 0
5 8 8 0 0
-------------
6 0 8 5 8
Find the least number which when divided by 35, leaves remainder 25; when divided by 45,
leaves remainder 35 and when divided by 55, leaves remainder 45.
Answer
3455
X 3 * *
----------
* 0 * 3
* 1 *
* 5 *
-------------
* 7 * * 3
Answer
A simple one.
1 1 7
335
X 3 1 9
----------
1 0 5 3
1 1 7
3 5 1
-------------
3 7 3 2 3
How long would it take you to count 1 billion orally if you could count 200 every minute and were
given a day off every four years?
As you can count 200 per minute, to count 1 billion you require
= 1,000,000,000/200 minutes
= 5,000,000 minutes
= 83,333.3333 hours
= 3,472.2222 days
= 9.512937 years
= 9 Years, 187 Days, 5 Hours, 20 minutes
Note that a day off every four year will be a Leap day. Hence, no need to consider leap year.
dFive students - Akash, Chintan, Jignesh, Mukund and Venky - appeared for an exam. There
were total five questions - two multiple choice (a, b or c) and three true/false questions. They
answered five questions each and answered as follow.
I II III IV V
--------------------------------------------------
--------------------------------------------------
Also, no two students got the same number of correct answers.
Can you tell which are the correct answers? What are their individual score?
Answer
The correct answers are b, a, True, False and False. Also, the scores are Jignesh (0),
Akash (1), Chintan (2), Venky (3) and Mukund (4).
336
As no two students got the same number of correct answers, the total number of correct answers
must be either 15 (1+2+3+4+5) or 10 (0+1+2+3+4).
Let's find out the maximum number of correct answers possible from the answers given by them.
For Question I = 2 (b or c)
For Question II = 2 (b or c)
For Question III = 4 (True)
For Question IV = 4 (True)
For Question V = 3 (True)
Thus, the maximum number of correct answers possible are 15 (2+2+4+4+3) which means that
Akash would have given all correct answers as only he answered True for questions III, IV and V.
But then Chintan and Jignesh would have exactly 3 correct answers. And also, Mukund and
Venky would have 2 correct answers. So no one got all five correct. One can also arrive at this
conclusion by trial-and-error, but that would be bit lengthy.
Now, it is clear that total number of correct answers are 10 (0+1+2+3+4). Questions III and IV
both can not be False. If so, total number of correct answers would not be 10. So the student who
got all wrong can not be Chintan, Akash and Mukund.
If Venky got all wrong, then Chintan, Jignesh and Mukund each would have atleast 2 correct
answers. It means that Akash would have to be the student with only one correct answer and the
correct answers for questions I and II would be a and a respectively. But then the total number of
correct answers would be 1 (a) + 1 (a) + 1 (False) + 4 (True) + 2 (Flase) = 9.
Thus, Jignesh is the student with all wrong answers. The correct answers are b, a, True, False
and False. Also, the scores are Jignesh (0), Akash (1), Chintan (2), Venky (3) and Mukund (4).
Eleven boys and girls wait to take their seats in the same row in a movie theater. There are
exactly 11 seats in the row.
They decided that after the first person sits down, the next person has to sit next to the first. The
third sits next to one of the first two and so on until all eleven are seated. In other words, no
person can take a seat that separates him/her from at least one other person.
How many different ways can this be accomplished? Note that the first person can choose any of
the 11 seats.
Answer
This is the type of Brain Teaser that can be solved using the method of induction.
If there is just a one person and one seat, that person has only one option.
If there are two persons and two seats, it can be accomplished in 2 different ways.
If there are three persons and three seats, it can be accomplished in 4 different ways. Remember
that no person can take a seat that separates him/her from at least one other person.
Similarly, four persons and four seats produce 8 different ways. And five persons with five seats
produce 16 different ways.
It can be seen that with each additional person and seat, the different ways increase by the power
of two. For six persons with six seats, there are 32 different ways.
337
For any number N, the different possible ways are 2(N-1)
Thus, for 11 persons and 11 seats, total different ways are 210 i.e. 1024
The secret agent X emailed a code word to his head office. They are "AIM DUE OAT TIE MOD".
But four of these five words are fake and only one contains the information.
The agent X also mailed a sentence as a clue - if I tell you any one character of the code word,
you would be able to tell the number of vowels in the code word.
Answer
If you were told any one character of MOD, then you would not be able to determine
whether the number of vowels are one or two. e.g. if you were told M, there are two
words with M - AIM with 2 vowels and MOD with 1 vowel. So you would not be able to
say the number of vowels. Same arguments can be given for characters O and D.
Hence, the word with any one of M, O or D is not a code word i.e. AIM, DUE, OAT and
MOD are not the code word. Thus, TIE is the code word.
T : two words - TIE and OAT, both with 2 vowels
I : two words - TIE and AIM, both with 2 vowels
E : two words - TIE and DUE, both with 2 vowels.
Brain Teaser No : 00361
Four men - Abraham, Bobby, Clinton and Denial - are standing in a straight line.
Answer
From (2), both the men standing next to Abraham are not fair. Also, exactly one man is fair,
handsom and unscarred. Hence, there are two cases:
Note the representation - Name (Fair, Handsome, Scarred). "Y" stands for Yes and "N" stabds for
No. Abraham (Y, Y, N) means Abraham is Fair, Handsome and Unscarred.
It is clear that either Abraham or the man at the extreme right is fair, handsome and unscarred.
338
From (4), it is deduced that Clinton is standing next to unscarred man and each of the other men
standing next to exactly one scarred man.
From (3), Bobby is the only man standing next to exactly one handsome man. But in Case 1,
Clinton is standing next to exactly one handsome man. Hence, Case 1 is not possible and Case 2
is the correct one.
Again from (3) and (4), there are 2 possibilities as shown below.
Thus, Clinton is fair, handsome and unscarred. Also, Abraham may be either fair or not fair.
An orange colored glass has Orange juice and white colored glass has Apple juice both of equal
volumes. 50ml of the orange juice is taken and poured into the white glass. After that similarly,
50ml from the white glass is poured into the orange glass.
Of the two quantities, the amount of apple juice in the orange glass and the amount of orange
juice in the white glass, which one is greater and by how much?
Answer
Solve it by taking example. Let's assume that both glasses contain 450 ml of juice each.
Now, 50ml of the orange juice is taken and poured into the White glass. Hence, orange colored
glass contains 400 ml of Orange juice and white glass contains 450 ml of Apple juice and 50 ml of
Orange juice i.e. total of 500 ml from white glass contains 450 ml of Apple juice and 50 ml of
Orange juice. It means that every 50 ml from white glass contains 45 ml of Apple juice and 5
ml of Orange juice.
Similary, 50 ml of juice from white glass is poured into orange glass. Now this 50 ml is not a pure
apple juice. It contains 45 ml of Apple juice and 5 ml of Orange juice.
Hence, Orange glass contains 405 ml of Orange juice and 45 ml of Apple juice. Similary, white
glass contains 405 ml of Apple juice and 45 ml of Orange juice.
339
Now it is clear that the amount of apple juice in the orange glass and the amount of
orange juice in the white glass are the same.
P.S. Here we assumed 450 ml as initial quantity in both the glasses just for simplicity.
You can try the same by assuming any other number. But the answer is the same.
Brain Teaser No : 00433
Can you tell at what time did they individually visit Edy?
Answer
From the given data, it is clear that at least one female visited Edy in the morning and at least one
female visited Edy in the evening. Also, from (4), Annie did not visit Edy first. It means that Annie
visited Edy at 8:00 PM
From (3), Bunnie must have visited Edy at 9:00 AM. Also, either Candy or Dina or both visited
Edy in the morning.
But from (2), only Dina must have visited Edy in the morning at 11:00 AM and hence, Candy
visited Edy at 10:00 PM.
In training for a competition, you find that swimming downstream (with the current) in a river, you
can swim 2 miles in 40 minutes, & upstream (against the current), you can swim 2 miles in 60
minutes.
You are able to swim downstream at 3 miles an hour, & upstream at 2 miles an hour. There is a
difference of 1 mile an hour, which is the river helping you in 1 direction, & slowing you in the
other direction.
Average the 2 rates, & you have the rate that you can swim in still water, which is 2.5 miles an
hour.
340
You can thus swim a mile in still water in 24 minutes.
Father's age is three years more than three times the son's age. After three years, father's age
will be ten years more than twice the son's age.
Answer
But given that after 3 years father's age will be ten years more than twice the son's age.
(3X + 6) = 2 * (X + 3) + 10
3X + 6 = 2X + 16
X = 10
Submit Users
Brai
Answer Answer (17)
Note that no persons have married more than once. Also, there are more number of
females than males. Can you tell how many females are there?
Answer
Assume that there are four sexes - male, female, X and Y. Prepare the following tree based on
the data given :
sister
| |
| |
| |
It is clear that there are altogether 13 persons - 2 males, 2 females, 4 Xs and 5 Ys.
It is given that there are more number of females than male. Hence, all Y must represent female.
Thus, there are 7 females and 6 males.
A positive integer that, when added to 1000 gives a sum which is greater than when multiplied by
1000.
Thus, sum of 1 and 1000 is greater than the multiplication of 1 and 1000.
Mr. D'souza has bought four cars - Merc, Honda, Ford, Zen - as presents for his sons' birthdays,
all of which are next week. Given the following information, what will each son get?
Alan will not get the Honda unless Barry gets the Merc and Denzil gets the Ford. Barry will not get
the Ford unless Carl gets the Zen and Alan gets the Merc. Denzil will not get the Zen unless Alan
gets the Honda and Barry gets the Merc. Alan will not get the Merc unless Carl gets the Zen and
Denzil gets the Ford. Barry will not get the Merc unless Alan gets the Zen and Denzil gets the
Ford. Alan will not get the Zen unless Barry gets the Honda and Carl gets the Merc. Carl will not
get the Zen unless Barry gets the Honda and Alan gets the Ford. Alan will not get the Ford unless
Barry gets the Zen and Denzil gets the Honda. Carl will not get the Merc unless Denzil gets the
Honda.
Answer
Let's put given 9 information in a table. The person in Bold Font will not get the corresponding
car unless the persons in Normal Font get the corresponding cars. Also, the person will Italics
will get the remaining car.
342
8 Carl Denzil Alan Barry
9 Carl Denzil ? ?
Now, let's assume that Alan gets the Merc. Then from (4), Barry gets the Honda, Denzil gets the
Ford and Carl gets the Zen. But from (7), Carl will not get the Zen unless Barry gets the Honda
and Alan gets the Ford. Thus, it contradicts the original assumption. Hence, Alan will not get the
Merc.
Let's assume that Alan gets the Honda. Then from (1), Barry gets the Merc, Denzil gets the Ford
and Carl gets the Zen. But from (5) or from (7), it contradicts the original assumption. Hence, Alan
will not get the Honda.
Let's assume that Alan gets the Ford. Then from (8), Carl gets the Merc, Denzil gets the Ford and
Barry gets the Zen - which does not contradict any of the statement.
Similaly, you can assume that Alan gets the Zen. (which is contradictory to (9))
Hence, Alan gets the Ford, Barry gets the Zen, Carl gets the Merc and Denzil gets the Honda.
Yesterday in a party, I asked Mr. Shah his birthday. With a mischievous glint in his eyes he
replied. "The day before yesterday I was 83 years old and next year I will be 86."
Can you figure out what is the Date of Birth of Mr. Shah? Assume that the current year is 2000.
Answer
Today is 1 January, 2000. The day before yesterday was 30 December, 1999 and Mr. Shah was
83 on that day. Today i.e. 1 January, 2000 - he is 84. On 31 December 2000, he will be 85 and
next year i.e. 31 December, 2001 - he will be 86. Hence, the date of birth is 31 December, 1915.
Many people do think of Leap year and date of birth as 29th February as 2000 is the Leap year
and there is difference of 3 years in Mr. Shah's age. But that is not the answer.
There are 4 mathematicians - Brahma, Sachin, Prashant and Nakul - having lunch in a hotel.
Suddenly, Brahma thinks of 2 integer numbers greater than 1 and says, "The sum of the
numbers is..." and he whispers the sum to Sachin. Then he says, "The product of the numbers
is..." and he whispers the product to Prashant. After that following conversation takes place :
Answer
As Sachin is initially confident that they (i.e. he and Prashant) don't know the numbers, we can
conclude that -
343
1) The sum must not be expressible as sum of two primes, otherwise Sachin could not have been
sure in advance that Prashant did not know the numbers.
2) The product cannot be less than 12, otherwise there would only be one choice and Prashant
would have figured that out also.
Such possible sum are - 11, 17, 23, 27, 29, 35, 37, 41, 47, 51, 53, 57, 59, 65, 67, 71, 77, 79, 83,
87, 89, 93, 95, 97, 101, 107, 113, 117, 119, 121, 123, 125, 127, 131, 135, 137, 143, 145, 147,
149, 155, 157, 161, 163, 167, 171, 173, 177, 179, 185, 187, 189, 191, 197, ....
If the sum of two numbers is 11, Sachin will think that the numbers would be (2,9), (3,8), (4,7) or
(5,6).
Sachin : "As 11 is not expressible as sum of two primes, Prashant can't know the numbers."
Here, the product would be 18(2*9), 24(3*8), 28(4*7) or 30(5*6). In all the cases except for
product 30, Prashant would know the numbers.
Hence, Prashant will be sure of the numbers if product is either 18, 24 or 28.
Sachin : "Since Prashant knows the numbers, they must be either (3,8), (4,7) or (5,6)." But he
won't be sure. Hence, the sum is not 11.
344
5+6 30 2+15=17 (possible)
3+10=13
5+6=11 (possible)
For all other numbers in the Possible Sum List, Prashant might be sure of the numbers but
Sachin won't.
Sachin : "As the sum is 17, two numbers can be either (2,15), (3,14), (4,13), (5,12), (6,11), (7,10)
or (8,9). Also, as none of them is a prime numbers pair, Prashant won't be knowing numbers
either."
Prashant : "Since Sachin is sure that both of us don't know the numbers, the sum must be one of
the Possible Sum List. Further, as the product is 52, two numbers can be either (2,26) or (4,13).
But if they were (2,26), Sachin would not have been sure in advance that I don't know the
345
numbers as 28 (2+26) is not in the Possible Sum List. Hence, two numbers are 4 and 13."
Sachin : "As Prashant now knows both the numbers, out of all possible products - 30(2,15),
42(3,14), 52(4,13), 60(5,12), 66(6,11), 70(7,10), 72(8,9) - there is one product for which list of all
possible sum contains ONLY ONE sum from the Possible Sum List. And also, no such two lists
exist. [see table above for 17] Hence, two numbers are 4 and 13."
Nakul figured out both the numbers just as we did by observing the conversation between Sachin
and Prashant.
It is interesting to note that there are no other such two numbers. We checked all the possible
sums till 500 !!!
Substitute digits for the letters to make the following subtraction problem true.
S A N T A
- C L A U S
-----------------
X M A S
Note that the leftmost letter can't be zero in any word. Also, there must be a one-to-one mapping
between digits and letters. e.g. if you substitute 3 for the letter M, no other letter can be 3 and all
other M in the puzzle must be 3.
Answer
One of the simplest brain teaser as there are total 26 possible answers.
It is obvious that S=C+1. Since A-S=S, it is clear that A=2*S or 2*s-10. Also, L and X are
interchangeable.
346
SANTA - CLAUS = XMAS
347
Oracle
3. What is a Tablespace?
6. What is schema?
Yes.
Synonyms are used to : Mask the real name and owner of an object.
349
Provide public access to an object
Provide location transparency for tables,views or program units of a
remote database.
Simplify the SQL statements for database users.
350
22. How are Indexes Update ?
Hash clusters are better choice when a table is often queried with
equality queries. For such queries the specified cluster key value
is hashed. The resulting hash key value points directly to the area
on disk that stores the specified rows.
Private Database Link, Public Database Link & Network Database Link.
Public database link is created for the special user group PUBLIC. A
public database link can be used when any user in the
associated database specifies a global object name in a SQL statement
or object definition.
351
32. What is Network Database link ?
A data block size is specified for each ORACLE database when the
database is created. A database users and allocated free database
space in ORACLE datablocks. Block size is specified in INIT.ORA file
and cann't be changed latter.
Each Index has an Index segment that stores all of its data.
The Primary function of the redo log is to record all changes made to
data.
The Information in a redo log file is used only to recover the database
from a system or media failure prevents database data from being
written to a database's data files.
Database Name
Names and locations of a database's files and redolog files.
Time stamp of database creation.
A rule defined on a column (or set of columns) in one table that allows
the insert or update of a row only if the value for the column
or set of columns (the dependent value) matches a value in a
column of a related table (the referenced value). It also
specifies the type of data manipulation allowed on referenced
data and the action to be performed on dependent data as a result of
any action on referenced data.
354
If a foreign key reference a parent key of the same table is
called self-referential integrity constraint.
SYSTEM ARCHITECTURE :
357
DATA ACCESS
100. What are the values that can be specified for OPTIMIZER MODE
Parameter ?
COST and RULE.
This value causes the optimizer to choose the rule_based approach for
all SQL statements issued to the instance regardless of the
presence of statistics.
103. What are the values that can be specified for OPTIMIZER_GOAL
parameter of the ALTER SESSION Command ?
PROGRAMMATIC CONSTRUCTS
359
110. What are the different types of PL/SQL program units that
can be defined and stored in ORACLE database ?
360
DATABASE SECURITY
124. What are the system resources that can be controlled through
Profile ?
The number of concurrent sessions the user can establish the CPU
processing time available to the user's session the CPU processing time
available to a single call to ORACLE made by a SQL statement the
amount of logical I/O available to the user's session the amout of
logical I/O available to a single call to ORACLE made by a SQL
statement the allowed amount of idle time for the user's session
the allowed amount of connect time for the user's session.
361
127. What is Statement Auditing ?
Statement auditing is the auditing of the powerful system
privileges without regard to specifically named objects.
140. What are the different modes of mounting a Database with the
Parallel Server ?
144.WhatisOn-lineRedoLog?
The On-line Redo Log is a set of tow or more on-line redo files that
record all committed changes made to the database. Whenever a
transaction is committed, the corresponding redo entries temporarily
stores in redo log buffers of the SGA are written to an on-line
redo log file by the background process LGWR. The on-line redo log
files are used in cyclical fashion.
363
147. What are the advantages of operating a database in ARCHIVELOG
mode over operating it in NO ARCHIVELOG mode ?
Complete database recovery from disk failure is possible only in
ARCHIVELOG mode.
Online database backup is possible only in ARCHIVELOG mode.
Rolling back transactions that have been explicitly rolled back or have
not been committed as indicated by the rollback segments regenerated in
step a.
Releasing any resources (locks) held by transactions in process at the
time of the failure.
Introduction to DBA
The memory structure that are used to store most queried data
from database. This helps up to improve database performance by
decreasing the amount of I/O performed against data file.
3. What is a Schema ?
The related columns of the tables are called the cluster key. The
cluster key is indexed using a cluster index and its value is stored
only once for multiple tables in the cluster.
It consists of
one or more data files.
one or more control files.
two or more redo log files.
The Database contains
multiple users/schemas
one or more rollback segments
one or more tablespaces
Data dictionary tables
User objects (table,indexes,views etc.,)
The server that access the database consists of
SGA (Database buffer, Dictionary Cache Buffers, Redo log
buffers, Shared SQL pool)
SMON (System MONito)
PMON (Process MONitor)
LGWR (LoG Write)
DBWR (Data Base Write)
ARCH (ARCHiver)
CKPT (Check Point)
RECO
Dispatcher
User Process with associated PGS
Two processes wating to update the rows of a table which are locked by
the other process then deadlock arises.
365
MEMORY MANAGEMENT
9. What is SGA ? How it is different from Ver 6.0 and Ver 7.0 ?
The data dictionary cache is stored in an area in SGA called the Shared
SQL Pool. This will allow sharing of parsed SQL statements among
concurrent users.
Data segment are the physical areas within a database block in which
the data associated with tables and clusters are stored.
13. What are the factors causing the reparsing of SQL statements in
SGA?
Database buffers are cache in the SGA used to hold the data blocks that
are read from the data segments in the database such as tables,
indexes and clusters DB_BLOCK_BUFFERS parameter in INIT.ORA decides the
size.
Change made to entries are written to the on-line redo log files. So
that they can be used in roll forward operations during database
recoveries. Before writing them into the redo log files, they will
first brought to redo log buffers in SGA and LGWR will write
into files frequently.
LOG_BUFFER parameter will decide the size.
18. How will you swap objects into a different table space for an
existing database ?
20. How will you force database to use particular rollback segment ?
22. How free extents are managed in Ver 6.0 and Ver 7.0 ?
PCTFREE parameter
We can plan the storage for a table as how much initial extents
are required, how much can be extended next, how much % should leave
free for managing row updations etc.,
30. How the space utilisation takes place within rollback segments ?
368
31. Why query fails sometimes ?
Transaction Begins.
36. How will you estimate the space required by a non-clustered tables?
Yes.
40. What is meant by Redo Log file mirrorring ? How it can be achieved?
370
43. What is a Rollback segment entry ?
It is the set of before image data blocks that contain rows that
are modified by a transaction.
Each Rollback Segment entry must be completed within one
rollback segment.
The tar command cannot be used for physical file backup, instead we can
use dd command which is less flexible and has limited recoveries.
47. List the factors that can affect the accuracy of the estimations ?
The space used transaction entries and deleted records does not become
free immediately after completion due to delayed cleanout.
DBA_FREE_SPACE
DBA_SEGMENTS
DBA_DATA_FILES.
52. What are the roles and user accounts created automatically with
the database ?
SYS user account - The DBA role will be assigned to this account.
All of the basetables and views for the database's dictionary are
store in this schema and are manipulated only by ORACLE.
SYSTEM user account - It has all the system privileges for the database
and additional tables and views that display administrative
information and internal tables and views used by oracle tools
are created using this username.
SQL * DBA - This allows DBA to monitor and control an ORACLE database.
Export (EXP) and Import (imp) utilities allow you to move existing
data in ORACLE format to and from ORACLE database.
55. What are the minimum parameters should exist in the parameter
file (init.ora) ?
372
DB_DOMAIN - It is string that specifies the network domain where
the database is created. The global database name is identified by
setting these parameters (DB_NAME & DB_DOMAIN)
Each server and background process can write an associated trace file.
When an internal error is detected by a process or user
process, it dumps information about the error to its trace. This can
be used for tuning the database.
Roles are the easiest way to grant and manage common privileges
needed by different groups of database users.
Assign each role to group of users. This will simplify the job of
assigning privileges to individual users.
58. What are the steps to switch a database's archiving mode between
NO ARCHIVELOG and ARCHIVELOG mode ?
373
60. How can we specify the Archived log file name format and
destination ?
Time the references to occur when master tables are not in use.
Peform the reference the manually immdiately locking the master
tables. We can join tables in snopshots by creating a complex
snapshots that will based on the master tables.
374
68. What are the options available to refresh snapshots ?
We cannot specify snapshot log name because oracle uses the name of
the master table in the name of the database objects that support its
snapshot log.
- Logical Backups
- Cold Backups
- Hot Backups (Archive log)
375
75. What is cold backup ? What are the elements of it ?
Taking backup of archive log files when database is open. For this
the ARCHIVELOG mode should be enabled. The following files need to
be backed up.
All data files. All Archive log, redo log files. All control files.
The name of the file which log of the export will be written.
2. What is a transaction ?
Transaction is logical unit between two commits and commit and rollback.
TRUNCATE commits after deleting entire table i.e., can not be rolled
back. Database triggers do not fire on TRUNCATE
378
6. What is correlated sub-query ?
INSTR (String1,String2(n,(m)),
INSTR returns the position of the mth occurrence of the string
2 in
string1. The search begins from nth position of string1.
Using ROWID.
CONSTRAINTS
379
14. What are the usage of SAVEPOINTS ?
CHAR pads blank spaces to the maximum length. VARCHAR2 does not pad
blank spaces. For CHAR it is 255 and 2000 for VARCHAR2.
Only one LONG columns is allowed. It is not possible to use LONG column
in WHERE or ORDER BY clause.
380
24. How to access the current value and next value from a sequence ?
Is it possible to access the current value in a session before
accessing next value ?
If changes are made to the tables which are base tables of a view will
the changes be reference on the view.
3. Name the two files that are created when you generate the form give
the filex extension ?
381
4. How do you control the constraints in forms ?
BLOCK
False.
6. Can we create two blocks with the same name in form 3.0 ?
No.
True.
8. What is a Trigger ?
1. Navigational Triggers.
2. Transaction Triggers.
Function Key
Key-function
Key-others
Key-startup
11. What is the difference between a Function Key Trigger and Key
Function Trigger ?
382
14. State the order in which these triggers are executed ?
It fires when a value in a field has been changed and the field
status is changed or new and the key has been pressed. If the
field status is valid then any further change to the value in the
field will not fire the on-validate-field trigger.
17. A query fetched 10 records How many times does a PRE-QUERY Trigger
and POST-QUERY Trigger will get executed ?
When you changes the Existing value to null, the On-validate field
trigger will fire post change trigger will not fire. At the time of
execute-query post-chage trigger will fire, on-validate field trigger
will not fire.
Post-field trigger fires whenever the control leaving from the filed.
Post-change trigger fires at the time of execute-query procedure
invoked or filed validation status changed.
383
21. When is PRE-QUERY trigger executed ?
No.
No.
25. How can you execute the user defined triggers in forms 3.0 ?
Execute_Trigger (trigger-name)
It will fires whenever SQL * Forms would normally attempt to lock a row.
Navigational Trigger.
384
31. What is the difference between restricted and unrestricted
package procedure ?
Restricted package procedure that affects the basic basic functions of
SQL * Forms. It cannot used in all triggers execpt key triggers.
a. Call - unrestricted
b. User Exit - Unrestricted
c. Call_query - Unrestricted
d. Up - Restricted
e. Execute Query - Restricted
f. Message - Restricted
g. Exit_form - Restricted
h. Post - Restricted
i. Break - Unrestricted.
No.
35. What are the unrestricted procedures used to change the popup
screen position during run time ?
Anchor-view
Resize -View
Move-View.
385
38. What is the difference between NAME_IN and COPY ?
1. Error_Code
2. Error_Text
3. Form_Failure
4. Form_Fatal
5. Message_Code
Post writes data in the form to the database but does not perform
database commit
Commit permenently writes data in the form to the database.
43. What package procedure used for invoke sql *plus from sql *forms ?
False.
True.
46. When the form is running in DEBUG mode, If you want to examine
the values of global variables and other form variables, What package
procedure command you would use in your trigger text ?
Break.
386
SYSTEM VARIABLES
1. System.block_status
2. System.current_block
3. System.current_field
4. System.current_value
5. System.cursor_block
6. System.cursor_field
7. System.field_status.
User Exits :
Page :
Unlimited.
a. True.
387
55.What is the significance of PAGE 0 in forms 3.0 ?
56. Deleting a page removes information about all the fields in that
page ?
a. True. b. False
a. True.
Popup Window :
Alert :
FORMS 4.0
Form
Menu
Library
05. BLOCK
ITEMS
Text item.
Chart item.
Check box.
Display item.
Image item.
List item.
Radio Group.
User Area item.
09. Can you change the color of the push button in design time?
No.
Basics of PL/SQL
1. What is PL/SQL ?
PL/SQL is a procedural language that has both interactive SQL
and procedural programming language constructs such as iteration,
conditional branching.
Datatypes PL/SQL
Some scalar data types such as NUMBER, VARCHAR2, DATE, CHAR, LONG,
BOOLEAN.
Some composite data types such as RECORD & TABLE.
6. What are % TYPE and % ROWTYPE ? What are the advantages of using
these over datatypes?
The advantages are : I. Need not know about variable's data type
ii. If the database definition of a column in a table changes, the
data type of a variable changes accordingly.
Cursors
There are two types of cursors, Implict Cursor and Explicit Cursor.
PL/SQL uses Implict Cursors for queries.
User defined cursors are called Explicit Cursors. They can be declared
and used.
DECLARE CURSOR cursor name, OPEN cursor name, FETCH cursor name
INTO or Record types, CLOSE cursor name.
391
14. What will happen after commit statement ?
Cursor C1 is
Select empno,
ename from emp;
Begin
open C1; loop
Fetch C1 into
eno.ename;
Exit When
C1 %notfound;-----
commit;
end loop;
end;
The cursor having query as SELECT .... FOR UPDATE gets closed
after COMMIT/ROLLBACK.
The cursor having query as SELECT.... does not get closed even
after COMMIT/ROLLBACK.
Database Triggers
If FOR EACH ROW clause is specified, then the trigger for each Row
affected by the statement.
392
18. Is it possible to use Transaction control Statements such a
ROLLBACK or COMMIT in Database Trigger ? Why ?
19. What are two virtual tables available during database trigger
execution ?
I & ii.
Exception :
25. What are the return values of functions SQLCODE and SQLERRM ?
SQLCODE returns the latest code of the error that has occured.
SQLERRM returns the relevant error message of the SQLCODE.
30. What are the modes of parameters that can be passed to a procedure ?
IN,OUT,IN-OUT parameters.
BEGIN
Executable statements.
Exception.
exception handlers
end;
34. Explain how procedures and functions are called in a PL/SQL block ?
The two parts of package are PACKAGE SPECIFICATION & PACKAGE BODY.
39. How packaged procedures and functions are called from the following?
a. Stored procedure or anonymous block
b. an application program such a PRC *C, PRO* COBOL
c. SQL *PLUS
FORMS4.0
Display items are similar to text items but store only fetched or
assigned values. Operators cannot navigate to a display item or edit
the value it contains.
16. How many maximum number of radio buttons can you assign to a
radio group?
17. can you change the default value of the radio button group at run
time?
No.
Visual Attributes.
396
19. What is a visual attribute?
Window
No.
24. List the buil-in routine for controlling window during run-time?
Find_window,
get_window_property,
hide_window,
move_window,
resize_window,
set_window_property,
show_View
Set_window_property
Canvas-View
28. Give the equivalent term in forms 4.0 for the following.
Page, Page 0?
Page - Canvas-View
Page 0 - Canvas-view null.
A content view is the "Base" view that occupies the entire content
pane of the window in which it is displayed.
A stacked view differs from a content canvas view in that it is not
the base view for the window to which it is assigned
31. List the built-in routines for the controlling canvas views
during run-time?
Find_canvas
Get-Canvas_property
Get_view_property
Hide_View
Replace_content_view
Scroll_view
Set_canvas_property
Set_view_property
Show_view
Alert
No
35. What built-in is used for showing the alert during run-time?
Show_alert.
398
36. Can you change the alert messages at run-time?
If yes, give the name of th built-in to chage the alert
messages at run-time.
Yes. Set_alert_property.
37. What is the built-in function used for finding the alert?
Find_alert
Editors
Default editor
User_defined editors
system editors.
Edit_text item
show_editor
LOV
Yes.
42. Can you attach an lov to a field at run-time? if yes, give the
build-in name.
Yes. Set_item_proprety
Show_lov
44. What is the built-in used to get and set lov properties
during run-time?
Get_lov_property
Set_lov_property
Record Group
399
46. What are the different type of a record group?
Create_group (Function)
Create_group_from_query(Function)
Delete_group(Procedure)
Add_group_column(Function)
Add_group_row(Procedure)
Delete_group_row(Procedure)
Populate_group(Function)
Populate_group_with_query(Function)
Set_group_Char_cell(procedure)
Get_group _row_count
System Variables
System.cordination_operation
System Date_threshold
System.effective_Date
System.event_window
System.suppress_working
False
Yes
400
Parameter
54. How do you pass the parameters from one form to another form?
54. What are the built-in routines is available in forms 4.0 to create
and manipulate a parameter list?
Add_parameter
Create_Parameter_list
Delete_parameter
Destroy_parameter_list
Get_parameter_attr
Get_parameter_list
set_parameter_attr
55. What are the two ways to incorporate images into a oracle
forms application?
Boilerplate Images
Image_items
57. What are the triggers associated with the image item?
Image_add
Image_and
Image_subtract
Image_xor
Image_zoom
Raise form_trigger_failure
61. What are the menu items that oracle forms 4.0 supports?
FORMS4.5
object groups
02. what are the different objects that you cannot copy or
reference in object groups?
canvas views
Most Canvas views are content canvas views a content canvas view is
the "base" view that occupies the entire content pane of the window in
which it is displayed.
Tool bar canvas views are used to create tool bars for individual
windows Horizontal tool bars are display at the top of a
window, just under its menu bar.
Vertical Tool bars are displayed along the left side of a window
402
07. Name of the functions used to get/set canvas properties?
Get_view_property, Set_view_property
Windows
Canvas views are the back ground objects on which you place the
interface items (Text items), check boxes, radio groups etc.,)
and boilerplate
objects (boxes, lines, images etc.,) that operators interact with us
they run your form . Each canvas views displayed in a window.
Modalless windows
Modal windows
More than one modelless window can be displayed at the same time,
and operators can navigate among them if your application allows them
to do so . On most GUI platforms, modelless windows can also be
layered to appear either in front of or behind other windows.
The console includes the status line and message line, and is
displayed at the bottom of the window to which it is assigned.
To specify that the console should be displayed, set the console
window form property to the name of any window in the form. To
include the console, set console window to Null.
Only one window in a form can display the console, and you cannot chage
the console assignment at runtime.
14. Can you have more than one content canvas view attached with a
window?
Yes.
403
Each window you create must have atleast one content canvas
view assigned to it. You can also create a window that has
manipulate contant canvas view. At run time only one of the content
canvas views assign to a window is displayed at a time.
When_window_activated
When_window_closed
When_window_deactivated
When_window_resized
Within this triggers, you can examine the built in system
variable system.event_window to determine the name of the window
for which the trigger fired.
Modules
18. What are the default extensions of the files careated by forms
modules?
19. What are the default extentions of the files created by menu module?
.mmb, .mmx
The default file extensions indicate the library module type and
storage format
.pll - pl/sql library module binary
Master Detail
Any event that makes a different record in the master block the
current record is a coordination causing event.
26. What are the different defaust triggers created when Master
Deletes Property is set to Non-isolated?
Master Delets Property Resulting Triggers
----------------------------------------------------
Non-Isolated(the default) On-Check-Delete-Master
On-Clear-Details
On-Populate-Details
26. Whar are the different default triggers created when Master
Deletes Property is set to Cascade?
Ans: Master Deletes Property Resulting Triggers
---------------------------------------------------
Cascading On-Clear-Details
On-Populate-Details
Pre-delete
28. What are the different default triggers created when Master
Deletes Property is set to isolated?
405
30. What are the different types of Coordinations of the Master with
the Detail block?
A user named editor has the same text editing functionality as the
default editor, but, becaue it is a named object, you can specify
editor attributes such as windows display size, position, and title.
Show editor is the generic built_in which accepts any editor name and
takes some input string and returns modified output string.
Whereas the edit_textitem built_in needs the input focus to be in the
text item before the built_in is excuted.
46. What is the basic data structure that is required for creating an
LOV?
Record Group.
48. What are the built_ins used the display the LOV?
Show_lov
List_values
49. What are the built-ins that are used to Attach an LOV
programmatically to an item?
set_item_property
get_item_property
(by setting the LOV_NAME property)
406
50. What are the built-ins that are used for setting the LOV
properties at runtime?
get_lov_property
set_lov_property
58. What are the built-ins used for Creating and deleting groups?
CREATE-GROUP (function)
CREATE_GROUP_FROM_QUERY(function)
DELETE_GROUP(procedure)
407
59.What are the built -ins used for Modifying a group's structure?
ADD-GROUP_COLUMN (function)
ADD_GROUP_ROW (procedure)
DELETE_GROUP_ROW(procedure)
60. POPULATE_GROUP(function)
POPULATE_GROUP_WITH_QUERY(function)
SET_GROUP_CHAR_CELL(procedure)
SET_GROUP_DATE_CELL(procedure)
SET_GROUP_NUMBER_CELL(procedure)
61. What are the built-ins used for Getting cell values?
GET_GROUP_CHAR_CELL (function)
GET_GROUP_DATE_CELL(function)
GET_GROUP_NUMBET_CELL(function)
GET_GROUP_ROW_COUNT(function)
GET_GROUP_SELECTION_COUNT(function)
GET_GROUP_SELECTION(function)
RESET_GROUP_SELECTION(procedure)
SET_GROUP_SELECTION(procedure)
UNSET_GROUP_SELECTION(procedure)
63. What are the built-ins used for finding Object ID function?
FIND_GROUP(function)
FIND_COLUMN(function)
II) FALSE
I) TRUE II)FALSE
I) FALSE
61. What are the built-in used for getting cell values?
Get_group_char_cell(function)
Get_group_date_cell(function)
Get_group_number_cell(function)
Get_group_row_count(function)
Get_group_selection_count(function)
Get_group_selection(function)
408
Reset_group_selection(procedure)
Set_group_selection(procedure)
Unset_group_selection(procedure)
63. What are the built-ins used for finding object ID functions?
Find_group(function)
Find_column(function)
False.
False.
parameters
67. What are the Built-ins used for sending Parameters to forms?
The maximum no of chars the parameter can store is only valid for
char parameters, which can be upto 64K. No parameters default to
23Bytes and Date parameter default to 7Bytes.
69. How do you call other Oracle Products from Oracle Forms?
In Pl/Sql, You can reference and set the values of form parameters
using bind variables syntax. Ex. PARAMETER name = '' or :block.item =
PARAMETER
Parameter name
409
71. How do you reference a parameter indirectly?
Text Parameters
Data Parameters
No.
IMAGES
76. What is the difference between boiler plat images and image items?
Boiler plate Images are static images (Either vector or bit map) that
you import from the file system or database to use a grapical elements
in your form, such as company logos and maps Image items are
special types of interface controls that store and display
either vector or bitmap images. Llike other items that store values,
image items can be either base table items(items that relate
directly to database columns) or control items. The definition of an
image item is stored as part of the form module FMB and FMX files,
but no image file is actualy associated with an image item until the
item is populate at run time.
410
WORKING WITH MULTIPLE FORMS
79. How do you create a new session while open a new form?
False
81. An open form can not be execute the call_form procedure if you
chain of called forms has been initiated by another open form?
True
82. When a form is invoked with call_form, Does oracle forms issues a
save point?
True
Mouse Operations
83. What are the various sub events a mouse double click event involves?
Double clicking the mouse consists of the mouse down, mouse up,
mouse click, mouse down & mouse up events.
System.mouse_button_pressed
System.mouse_button_shift_state
system.mouse_item
system.mouse_canvas
system.mouse_record
OLE
411
87. What is the difference between OLE Server & Ole Container?
In place activation
External activation
Visual attributes are the font, color, pattern proprities that you set
for form and menu objects that appear in your application interface.
Yes
92. What are the important difference between property clause and
visual attributes?
Form Build-ins
Issues dynamic Sql statements at run time, including server side pl/SQl
and DDL
Triggers
On-Check_delete_master
On_clear_details
On_populate_details
101. What are the difference between lov & list item?
Lov is a property where as list item ias an item. A list item can have
only one column, lov can have one or more columns.
Pop_list
Text_list
Combo box
The pop list style list item appears initially as a single field
(similar to a text item field). When the operator selects the list
icon, a list of available choices appears.
413
104. What is a text list?
The text list style list item appears as a rectangular box which
displays the fixed number of values. When the text list contains values
that can not be displayed, a vertical scroll bar appears, allowing the
operator to view and select undisplayed values.
A combo box style list item combines the features found in list and
text item. Unlike the pop list or the text list style list items, the
combo box style list item will both display fixed values and
accept one operator entered value.
Display items are similar to text items with the exception that
display items only store and display fetched or assigned
values.Display items are generaly used as boilerplate or conditional
text.
when one form invokes another form by executing open_form the first
form remains displayed,and operators can navigate between the forms as
desired. when one form invokes another form by executing
call_form,the called form is modal with respect to the calling
form.That is, any windows that belong to the calling form are
disabled, and operators cannot navigate to them until they first exit
the called form.
When one form invokes another form by executing new_form oracle form
exits the first form and releases its memory before loading the new
form calling new form completely replace the first with the second. If
there are changes pending in the first form,the operator will be
prompted to save them before the new form is loaded.
414
significantly reduce the run-time memory requirements of an
applications.
Removes the source code from the library file and generates a library
files that contains only pcode.The resulting file can be used
for final deployment, but can not be subsequently edited in the
designer.
find_timer
create_timer
delete_timer
115. what are difference between post database commit and post-form
commit?
Fires during the execute query and count query processing after
oracle forms constructs the select statement to be issued, but
before the statement is actually issued.
The pre-query trigger fires just before oracle forms issues the
select statement to the database after the operator as define the
example records by entering the query criteria in enter query mode.
415
117. What is trigger associated with the timer?
When-timer-expired.
REPORTS
Previewer.
At the client.
At the server.
416
9. What are the default parameter that appear at run time in the
parameter screen?
Read only.
The term is terminal definition file that describes the terminal form
which you are using r20run.
The term file which key is correspond to which oracle report functions.
Yes.
15. What are the sql clauses supported in the link property sheet?
16. To execute row from being displayed that still use column in the
row which property can be used?
Format trigger.
No.
417
20. What is the purpose of the product order option in the column
property sheet?
Yes.
Yes.
28. If two groups are not linked in the data model editor, What is
the hierarchy between them?
Two group that is above are the left most rank higher than the group
that is to right or below it.
29.The join defined by the default data link is an outer join yes or no?
Yes.
By using the link file property in the layout boiler plate property
sheet.
418
31. Can a repeating frame be careated without a data group as a base?
No.
Yes.
33. For a field in a repeating frame, can the source come from the
column which does not exist in the data group which forms the base for
the frame?
Yes.
Yes.
35. If yes,how?
36. What are the two repeating frame always associated with matrix
object?
Yes.
38. Does a grouping done for objects in the layout editor affect
the grouping done in the datamodel editor?
No.
39. How can a square be drawn in the layout editor of the report writer?
40. To display the page no. for each page on a report what would be
the source & logical page no. or & of physical page no.?
41. What does the term panel refer to with regard to pages?
A panel is the no. of physical pages needed to print one logical page.
419
43. What is a physical page ? & What is a logical page ?
REPORT TRIGGERS.
Before report, Before form, After form , Between page, After report.
46. Does a Before form trigger fire when the parameter form is
suppressed.
Yes.
After the query is executed but before the report is executed and
the
records are displayed.
48. Is the After report trigger fired if the report execution fails?
Yes.
Before form , After form , Before report, Between page, After report.
No.
51. What are the ways to monitor the performance of the report?
420
52. Why is it preferable to create a fewer no. of queries in the
data model.
Because for each query, report has to open a separate cursor and
has to
rebind, execute and fetch data.
56. What is the main diff. bet. Reports 2.0 & Reports 2.5?
58. How is link tool operation different bet. reports 2 & 2.5?
In Reports 2.0 the link tool has to be selected and then two fields
to be
linked are selected and the link is automatically created. In 2.5 the
first
field is selected and the link tool is then used to link the first
field to
the second field.
view by structure.
421
61.How is possible to restrict the user to a list of values while
entering
values for parameters?
By using the tables/columns button and then specifying the table and
the
column names.
While both reports 2.0 and 2.5 create the parameter, report 2.5
gives a
message that a bind parameter has been created.
No.
66. What is the diff. when Flex mode is mode on and when it is off?
When flex mode is on, reports automatically resizes the parent when
the
child is resized.
67. How can a button be used in a report to give a drill down facility?
68. What are the two ways by which data can be generated for a
parameter's
list of values?
69. What are the two panes that Appear in the design time
pl/sql interpreter?
A group that forms part of a cross product will have a thicker border.
73. Atleast how many set of data must a data model have before a data
model
can be base on it?
Four.
No.
No.
78. How can values be passed bet. precompiler exits & Oracle
call
interface?
423
79. How can I message to passed to the user from reports?
Oracle DBA
Ans : D
Ans : A
Ans : B
13. Which of the following is not an reason for the fact that most of
the processing is done at the server ?
a] To reduce network traffic. b] For application sharing,
c] To implement business rules centrally, d] None of the above
Ans : D
16. What is the difference between a LIST BOX and a COMBO BOX ?
a] In the list box, the user is restricted to selecting a value
from a
list but in a combo box
the user can type in a value which is not in the list
b] A list box is a data entry area while a combo box can be used
only
for control purposes
c] In a combo box, the user is restricted to selecting a value
from a
list but in a list box the
user can type in a value which is not in the list
d] None of the above
Ans : A
22. The system variable that records the select statement that SQL *
FORMS
most recently used
to populate a block is
a] SYSTEM.LAST_RECORD
b] SYSTEM.CURSOR_RECORD
c] SYSTEM.CURSOR_FIELD
d] SYSTEM.LAST_QUERY
Ans: D
23. Which of the following is TRUE for the ENFORCE KEY field
a] ENFORCE KEY field characterstic indicates the source of the
value
that SQL*FORMS
uses to populate the field
b] A field with the ENFORCE KEY characterstic should have the
INPUT
ALLOWED
charaterstic turned off
a] Only 1 is TRUE
b] Only 2 is TRUE
c] Both 1 and 2 are TRUE
d] Both 1 and 2 are FALSE
Ans : A
28. Which of the following is TRUE for the SYSTEM VARIABLE $$date$$
a] Can be assigned to a global variable
b] Can be assigned to any field only during design time
c] Can be assigned to any variable or field during run time
d] None of the above
Ans : B
32. Name the two files that are created when you generate a form
using
Forms 3.0
a] FMB & FMX, b] FMR & FDX, c] INP & FRM, d] None of the above
Ans : C
428
33. What is a trigger
a] A piece of logic written in PL/SQL
b] Executed at the arrival of a SQL*FORMS event
c] Both A & B
d] None of the above
Ans : C
429
40. What is a DATABLOCK
a] Set of Extents
b] Set of Segments
c] Smallest Database storage unit
d] None of the above
Ans : C
47. Which of the following does not affect the size of the SGA
a] Database buffer
b] Redolog buffer
c] Stored procedure
d] Shared pool
Ans : C
430
48. What does a COMMIT statement do to a CURSOR
a] Open the Cursor
b] Fetch the Cursor
c] Close the Cursor
d] None of the above
Ans : D
51. Declare
fvar number := null; svar number := 5
Begin
goto << fproc>>
if fvar is null then
<< fproc>>
svar := svar + 5
end if;
End;
Ans : A
Ans : C
Ans : D
Ans : C
Ans : A
Ans : B
Ans : A
Ans C
432
60. Find the ODD datatype out
a] VARCHAR2
b] RECORD
c] BOOLEAN
d] RAW
Ans : B
61. Which of the following is not correct about the "TABLE" datatype ?
a] Can contain any no of columns
b] Simulates a One-dimensional array of unlimited size
c] Column datatype of any Scalar type
d] None of the above
Ans : A
Ans C
Ans : B
Ans : C
Ans : C
433
66. Declare
a number := 5; b number := null; c number := 10;
Begin
if a > b AND a < c then
a := c * a;
end if;
End;
What will be the value of 'a' after execution ?
a] 50
b] NULL
c] 5
d] None of the above
Ans : C
67. Does the Database trigger will fire when the table is TRUNCATED ?
a] Yes
b] No
Ans : B
Ans : C
Ans : A
Select SAL from EMP E1 where 3 > ( Select count(*) from Emp E2
where E1.SAL > E2.SAL ) will retrieve
a] 3500,5000,2500
b] 5000,2850
c] 2850,5750
d] 5000,5750
Ans : A
434
72. Is it possible to modify a Datatype of a column when column contains
data ?
a] Yes
b] No
Ans B
Ans : B
Ans : C
Ans : D
Ans : C
435
77. If an UNIQUE KEY constraint on DATE column is created, will it
accept
the rows that are
inserted with SYSDATE ?
a] Will
b] Won't
Ans : B
Ans : C
79. What built-in subprogram is used to manipulate images in image
items ?
a] Zoom_out
b] Zoom_in'
c] Image_zoom
d] Zoom_image
Ans : C
Ans : A
Ans : B
Ans : A
Ans : C
436
84. How can you CALL Reports from Forms4.0 ?
a] Run_Report built_in
b] Call_Report built_in
c] Run_Product built_in
d] Call_Product built_in
Ans : C
Ans : A
Ans : D
Ans : D
Ans : B
Ans : C
437
91. What is Library in Forms 4.0 ?
a] Collection of External field
b] Collection of built_in packages
c] Collection of PL/SQl functions, procedures and packages
d] Collection of PL/SQL procedures & triggers
Ans : C
Ans : B
Ans : B
94. What type of file is used for porting Forms 4.5 applications to
various
platforms ?
a] .FMB file
b] .FMX file
c] .FMT file
d] .EXE file
Ans : C
Ans A
Ans : A
97. Can we attach the same LOV to different fields in Design time ?
a] Yes
b] No
Ans : A
438
98. How do you pass values from one form to another form ?
a] LOV
b] Parameters
c] Local variables
d] None of the above
Ans : B
99. Can you copy the PROGRAM UNIT into an Object group ?
a] Yes
b] No
Ans : B
Ans : A
Ans : C
Ans : D
Ans : A
Ans : C
439
105. What is an ALERT ?
a] Modeless window
b] Modal window
c] Both are TRUE
d] None of the above
Ans : B
Ans : A
Ans : B
Ans D
Ans : D
Ans : D
Ans : D
440
112. What is TERM ?
a] TERM is the terminal definition file that describes the
terminal
from which you are
using R20RUN ( Reports run time )
b] TERM is the terminal definition file that describes the
terminal
from which you are
using R20DES ( Reports designer )
c] There is no Parameter called TERM in Reports 2.0
d] None of the above
Ans : A
Ans : A
Ans : D
115. For a field in a repeating frame, can the source come from a
column
which does not exist in
the datagroup which forms the base of the frame ?
a] Yes
b] No
Ans : A
116. What are the different file extensions that are created by
Oracle
Reports ?
a] .RDF file & .RPX file
b] .RDX file & .RDF file
c] .REP file & .RDF file
d] None of the above
Ans : C
441
117. Is it possible to Disable the Parameter form while running the
report
?
a] Yes
b] No
Ans : A
118.What are the SQL clauses supported in the link property sheet ?
a] WHERE & START WITH
b] WHERE & HAVING
c} START WITH & HAVING
d] WHERE, START WITH & HAVING
Ans : D
Ans.: D
120. If two groups are not linked in the data model editor, what is
the
hierarchy between them?
a] There is no hierarchy between unlinked groups
b] The group that is right ranks higher than the group that is to
the
left
c] The group that is above or leftmost ranks higher than the
group
that is to right or below
it
d] None of the above
Ans : C
Ans : B
Ans : B
442
123. ENQUEUE_RESOURCES parameter information is derived from
a] PROCESS or DDL_LOCKS & DML_LOCKS
b] LOG BUFFER
c] DB_BLOCK_SIZE
d] DB_BLOCK_BUFFERS
Ans : A
Ans : B
Ans : A
Ans : A
Ans : B
129. NOARCHIEVELOG parameter is used to enable the database in
Archieve
mode
a] TRUE
b] FALSE
Ans : B
Ans : B
443
131. It is very difficult to grant and manage common priveleges
needed by
different groups of
database users using roles
a] TRUE
b] FALSE
Ans : B
Ans : D
Ans : A
Ans : A
444
J2EE
1. What exception is thrown when Servlet initialization fails ?
(a) IOException
(b) ServletException
(c) RemoteException
ANS: (b)
-------------------------------------------------------------------
ANS: (c)
-------------------------------------------------------------------
(a) forward executes on the client while sendRedirect() executes on the server.
(b) forward executes on the server while sendRedirect() executes on the client.
(c) The two methods perform identically.
ANS: (b)
-------------------------------------------------------------------
445
4. Why beans are used in J2EE architecture in stead of writing all the code in JSPs ?
(a) Allows separation of roles between web developers and application developers
(b) Allows integration with Content Management tools
ANS: (a)
-------------------------------------------------------------------
ANS: I think answer is (e). I am not sure whether response from database is slow just
because we include the database access code in JSP page.
-------------------------------------------------------------------
-------------------------------------------------------------------
7. At what stage, the life cycle of a CMP bean can be assumed to be started ?
-------------------------------------------------------------------
-------------------------------------------------------------------
446
9. In JSP, how can you know what HTTP method (GET or POST) is used by client
request ?
ANS: (a)
-------------------------------------------------------------------
ANS: (d)
-------------------------------------------------------------------
(a) Start()
(b) Run()
(c) Servive()
(d) init()
ANS: (d)
-------------------------------------------------------------------
12. The time between Command Execution and Response is called ______
(a) Granularity
(b) Latency
(c) Lag time
ANS: (c)
EXPLANATION:
Latency:
447
Latency is a measure of the temporal delay. Typically, in xDSL, latency refers to the
delay in time between the sending of a unit of data at the originating end of a connection
and the reception of that unit at the destination end.
In a computer system, latency is often used to mean any delay or waiting that increases
real or perceived response time beyond the response time desired. Within a computer,
latency can be removed or "hidden" by such techniques as prefetching (anticipating the
need for data input requests) and multithreading, or using parallelism across multiple
execution threads.
In networking, the amount of time it takes a packet to travel from source to destination.
Together, latency and bandwidth define the speed and capacity of a network.
Granularity:
The extent to which a system contains separate components (like granules). The more
components in a system -- or the greater the granularity -- the more flexible it is.
Granularity is a term often used in parallel processing to indicate independent processes
that could be distributed to multiple CPUs. Fine granularity is illustrated by execution of
statements or small loop iterations as separate processes; coarse granularity involves
subroutines or sets of subroutines as separate processes. The more processes, the "finer"
the granularity and the more overhead required to keep track of them. Granularity can
also be related to the temporal duration of a "task" at work. It is not only the number of
processes but also how much work each process does, relative to the time of
synchronization, that determines the overhead and reduces speedup figures.
Lag Time:
Lag Time is the amount of time between making an online request or command and
receiving a response. A primary goal of advertising network efficiency is to minimize lag
time.
-------------------------------------------------------------------
-------------------------------------------------------------------
ANS: (c)
EXPLANATION:
448
JSP Syntax :
<jsp:plugin
type="bean|applet"
code="classFileName"
codebase="classFileDirectoryName"
[ name="instanceName" ]
[ archive="URIToArchive, ..." ]
[ align="bottom|top|middle|left|right" ]
[ height="displayPixels" ]
[ width="displayPixels" ]
[ hspace="leftRightPixels" ]
[ vspace="topBottomPixels" ]
[ jreversion="JREVersionNumber | 1.1" ]
[ nspluginurl="URLToPlugin" ]
[ iepluginurl="URLToPlugin" ] >
[ <jsp:params>
[ <jsp:param name="parameterName" value="parameterValue" /> ]+
</jsp:params> ]
</jsp:plugin>
Description :
The <jsp:plugin> tag is replaced by either an <object> or <embed> tag, whichever is
most appropriate for the client Web browser (the <object> tag is for browsers that use
HTML 4.0).
The <jsp:params> element sends parameter names and values to an applet or Bean at
startup. The <jsp:fallback> element provides a message for the user if the plugin does not
start. If the plugin starts but the applet or Bean does not, the plugin usually displays a
popup window explaining the error to the user.
The <jsp:plugin> tag takes most of its attributes from the HTML <applet> and <object>
tags (<applet> is defined in HTML 3.2 and <object> in HTML 4.0). You may want to
refer to the official HTML specifications in which these tags are introduced:
Attributes :
type="bean|applet"
449
The type of object the plugin will execute. You must specify either bean or applet, as this
attribute has no default value.
code="classFileName"
The name of the Java class file that the plugin will execute. You must include the .class
extension in the name following code. The filename is relative to the directory named in
the codebase attribute.
codebase="classFileDirectoryName"
The absolute or relative path to the directory that contains the applet's code. If you do not
supply a value, the path of the JSP file that calls <jsp:plugin> is used.
name="instanceName"
A name for the Bean or applet instance, which makes it possible for applets or Beans
called by the same JSP file to communicate with each other.
archive="URIToArchive, ..."
A comma-separated list of paths that locate archive files to be preloaded with a class
loader located in the directory named in codebase. The archive files are loaded securely,
often over a network, and typically improve the applet's performance.
align="bottom|top|middle|left|right"
The positioning of the image displayed by the applet or Bean relative to the line in the
JSP result page that corresponds to the line in the JSP file containing the <jsp:plugin> tag.
The results of the different values are listed below:
bottom Aligns the bottom of the image with the baseline of the text line.
top Aligns the top of the image with the top of the text line.
middle Aligns the vertical center of the image with the baseline of the text line.
left Floats the image to the left margin and flows text along the image's right side.
right Floats the image to the right margin and flows text along the image's left side.
height="displayPixels" width="displayPixels"
The initial height and width, in pixels, of the image the applet or Bean displays, not
counting any windows or dialog boxes the applet or Bean brings up.
hspace="leftRightPixels" vspace="topBottomPixels"
The amount of space, in pixels, to the left and right (or top and bottom) of the image the
applet or Bean displays. Must be a small nonzero number.
450
jreversion="JREVersionNumber|1.1"
The version of the Java Runtime Environment (JRE) the applet or Bean requires. The
default value is 1.1.
nspluginurl="URLToPlugin"
The URL where the user can download the JRE plugin for Netscape Navigator. The value
is a full URL, with a protocol name, optional port number, and domain name.
iepluginurl="URLToPlugin"
The URL where the user can download the JRE plugin for Internet Explorer. The value is
a full URL, with a protocol name, optional port number, and domain name.
The parameters and values that you want to pass to the applet or Bean. To specify more
than one name and value, use multiple <jsp:param> tags within the <jsp:params>
element. Applets read parameters with the java.applet.Applet.getParameter method.
A text message to display for the user if the plugin cannot be started.
Example:
The <jsp:plugin> directive takes care of generating all the HTML code necessary to
embed and activate a Java applet.
Consider the following example:
-----------
<html> <head> </head> <body>
<jsp:params>
<jsp:param name="x" value="10"/>
<jsp:param name="y" value="25"/>
</jsp:params>
451
<jsp:fallback>Oops! Something bad happened and I can't display this
applet</jsp:fallback>
</jsp:plugin>
</body>
</html>
-----------
The code above sets up the applet contained in "NewsTicker.class", and passes it a bunch
of name-value pairs of parameters. The <jsp:param> tag is used to pass these parameters
to the applet, while the <jsp:fallback> directive contains error text, in the event that the
applet cannot be found or displayed.
When JSP compiles and renders the page, the code above is automatically converted to its
HTML equivalent.
<NOEMBED>
Oops! Something bad happened and I can't display this applet
</NOEMBED>
</EMBED>
</OBJECT>
</body>
</html>
-----------
-------------------------------------------------------------------
452
ANS:
<jsp:forward> transfers the control to the mentioned destination page.
<jsp:include> tag substitutes the output of the destination page. Control remains on the
same page.
-------------------------------------------------------------------
ANS: (a)
-------------------------------------------------------------------
(a) javax.ejb.EntityBean
(b) javax.ejb.rmi
(c) javax.ejb.EJBHome
(d) javax.ejb.EJBObject
-------------------------------------------------------------------
18. Generally Servlets are used for complete HTML generation. If you want to generate
partial HTMLs that include some static text (This should not be hard coded in Servlets)
as well as some dynamic text, what method do you use ?
(Note: I don't remember the question word to word. But it is similar to what I have given)
-------------------------------------------------------------------
19. Which of the following can not be used as the scope when using a JavaBean with
JSP?
(a) session
(b) application
453
(c) request
(d) response
ANS: (d)
-------------------------------------------------------------------
-------------------------------------------------------------------
ANS: (c)
EXPLANATION:
A temporary servlet is started when a request arrives and shut down after the response is
generated.
A permanent servlet is loaded when the server is started and lives until the server is shut
down.
* This is useful when startup costs are high, such as a servlet that establishes a connection
to a database.
* Also useful for permanent server-side service, such as an RMI server.
* Provides faster response to client requests when this is crucial.
-------------------------------------------------------------------
22. Although it is not commonly done, what will you do if you want to have multiple
instances of Servlet in memory and if they have to share the execution of a user request ?
454
(Note: I don't remember the question & answers word to word. But it is similar to what I
have given)
-------------------------------------------------------------------
23. In WebLogic 5.1, how can you make a JSP application work
-------------------------------------------------------------------
___________________________________________________________________
In the init(ServletConfig) method of Servlet life cycle, what method can be used to access
the ServletConfig object ?
(a) getServletInfo()
(b) getInitParameters()
(c) getServletConfig()
ANS: (c)
___________________________________________________________________
The Page directive in JSP is defined as follows:
<%@ page language="java" session="false" isErrorPage="false" %>
Then which of the implicit objects won't be available ?
(a) session, request
(b) exception, request
(c) exception, config
(d) session, exception
ANS: I think answer is (d)
___________________________________________________________________
ejbCreate() method of CMP bean returns
(a) null
(b) Primary Key class
(c) Home Object
(d) Remote Object
ANS: (a)
Explanation: ejbCreate() method of BMP bean returns the Primary Key, where as
ejbCreate() method of CMP bean returns null.
___________________________________________________________________
How can a EJB pass it's reference to another EJB ?
___________________________________________________________________
Which of the following is correct syntax for an Abstract class ?
(a) abstract double area() { }
455
(b) abstract double area()
(c) abstract double area();
(d) abstract double area(); { }
ANS: (c)
___________________________________________________________________
A JSP page is opened in a particular Session. A button is present in that JSP page onclick
of which a new Window gets opened.
(a) The Session is not valid in the new Window
(b) The Session is valid in the new Window
ANS: I think the answer is (b)
___________________________________________________________________
Which of the following JSP expressions are valid ?
(a) <%= "Sorry"+"for the"+"break" %>
(b) <%= "Sorry"+"for the"+"break"; %>
(c) <%= "Sorry" %>
(d) <%= "Sorry"; %>
ANS:
___________________________________________________________________
A class can be converted to a thread by implementing the interface __________
(a) Thread
(b) Runnable
ANS: (b)
___________________________________________________________________
What is the output of following block of program ?
boolean var = false;
if(var = true) {
System.out.println("TRUE");
} else {
System.out.println("FALSE");
}
(a) TRUE
(b) FALSE
(c) Compilation Error
(d) Run-time Error
ANS: (a)
EXPLANATION: The code compiles and runs fine and the 'if' test succeeds because 'var'
is set to 'true' (rather than tested for 'true') in the 'if' argument.
___________________________________________________________________
Which is not allowed in EJB programming ?
(a) Thread Management
(b) Transient Fields
(c) Listening on a Socket
ANS:
___________________________________________________________________
456
What happens if Database Updation code is written in ejbPassivate() method and if this
method is called ?
(a) Exception is thrown
(b) Successfully executes the Database Updation code
(c) Compilation error occurs indicating that Database Updation code should not be
written in ejbPassivate()
(d) ejbStore() method is called
ANS:
___________________________________________________________________
A Vector is declared as follows. What happens if the code tried to add 6 th element to this
Vector
new vector(5,10)
(a) The element will be successfully added
(b) ArrayIndexOutOfBounds Exception
(c) The Vector allocates space to accommodate up to 15 elements
ANS: (a) and (c)
EXPLANATION: The 1 st argument in the constructor is the initial size of Vector and the
2 nd argument in the constructor is the growth in size (for each allocation)
This Vector is created with 5 elements and when an extra element (6 th one) is tried to be
added, the vector grows in size by 10.
___________________________________________________________________
Which is the data structure used to store sorted map elements ?
(a) HashSet
(b) Hashmap
(c) Map
(d) TreeMap
ANS: I think the answer is (d)
___________________________________________________________________
SessionListerner defines following methods
(a) sessionCreated, sessionReplaced
(b) sessionCreated, sessionDestroyed
(c) sessionDestroyed, sessionReplaced
ANS:
___________________________________________________________________
Which of the following is true ?
(a) Stateless session beans doesn't preserve any state across method calls
(b) Stateful session beans can be accesses by multiple users at the same time
ANS: (a)
___________________________________________________________________
Stateful Session beans contain
(a) Home Interface
(b) Remote Interface
(c) Bean Class
(d) All
ANS: (d)
___________________________________________________________________
457
What is the Life Cycle of Session bean ?
___________________________________________________________________
Stateless session bean is instantiated by
(a) newInstance()
(b) create()
ANS:
___________________________________________________________________
A servlet implements Single Thread model
public class BasicServlet extends HttpServlet implements SingleThreadModel {
int number = 0;
public void service(HttpServletRequest req, HttpServletResponse res) {
}
}
Which is thread safe ?
(a) Only the variable num
(b) Only the HttpServletRequest object req
(c) Both the variable num & the HttpServletRequest object req
___________________________________________________________________
If you are trying to call an EJB that is timed out, what will happen ?
(a) Exception
(b) It gets executed
___________________________________________________________________
A method is defined in a class as :
void processUser(int i) { }
If this method is overriden in a sub class,_____
(a) the new method should return int
(b) the new method can return any type of values
(c) the argument list of new method should exactly match that of overriden method
(d) the return type of new method should exactly match that of overriden method
ANS: (c) & (d)
___________________________________________________________________
In a JSP page, a statement is declared as follows:
<%! String strTemp = request.getParameter("Name"); %>
And below that, an _expression appears as:
<% System.out.println("The Name of person is: "+strTemp); %>
What is the output of this _expression, if this JSP page is invoked in browser using URL :
http://localhost:8080/JSP/TrialPage.jsp?Name=Chetana
(Assume that this URL is correct)
(a) The Name of person is: Chetana
(b) The Name of person is:
(c) The Name of person is: null
(d) None
ANS: (a)
___________________________________________________________________
458
Without the use of Cartesian product, how many joining conditions are required to join 4
tables ?
(a) 1
(b) 2
(c) 3
(d) 4
ANS:
___________________________________________________________________
What is the output of following piece of code ?
int x = 2;
switch (x) {
case 1:System.out.println("1");
case 2:
case 3:System.out.println("3");
case 4:
case 5:System.out.println("5");
}
(a) No output
(b) 3 and 5
(c) 1, 3 and 5
(d) 3
ANS: (b)
----------------------------------------------------
EJB
----------------------------------------------------
(a) Used to identify the entity bean based on EJB type, Home Interface and Container
Context.
(b) Used to identify the entity bean based on EJB type, Remote Interface and Container
Context.
(c) The definition of Primary Key class can be deferred till deployment
--------------------
--------------------
459
3) In CMP of Entity beans
--------------------
--------------------
--------------------
(a) EJBException
(b) RemoteException
--------------------
(a) NullPointerException
(b) ArrayOutOfBoundsException
(c) CreateException
(d) ObjectNotFoundException
(e) All the above
(f) None of the above
--------------------
----------------------------------------------------
460
----------------------------------------------------
JSP and Mislleneous
----------------------------------------------------
ANS: (a)
--------------------
(a) next()
(b) first()
(c) a & b
(d) No methods
--------------------
(a) RoundRobin
(b) FIFO
(c) LIFO
ANS: (a)
WebLogic uses a Round-Robin strategy as default algorithm for forwarding the HTTP
requests inside a cluster. Weight-based and random algorithms are also available.
--------------------
(a) 1
(b) 2
(c) Any Number
(d) 10
ANS: (a)
461
--------------------
--------------------
(a) distributable
(d) distributed="true"
(c) both a & b
--------------------
(a) YES
(b) NO
--------------------
8) Empty JSP Tag definitions are given in Deployment Descriptor. Then which of the
following syntaxes are correct ?
--------------------
----------------------------------------------------
462
----------------------------------------------------
JAVA
----------------------------------------------------
class Trial {
String _member;
void method1() {
for(int i=0;i<2048;i++) {
_member += "test";
}
}
void method2() {
String temp;
for(int i=0;i<2048;i++) {
temp += "test";
}
_member = temp;
}
(a) method1()
(b) method2()
(c) Both method1() and method2() takes same time for execution
ANS: (b)
Accessing method variables requires less overhead than accessing class variables.
--------------------
2) Integer.parseInt("12a") returns
(a) Exception
(b) 1
(c) 0
463
(d) -1
ANS: (a)
--------------------
ANS: (b)
String is a class defined in java.lang and in java all classes are passed by reference.
--------------------
--------------------
class Test {
public static void main(String args[]) {
for(int i=0;i<2;i++) {
System.out.println(i--);
}
}
}
ANS: (a)
--------------------
6) 't' is the reference to a class that extends THREAD. Then how to suspend the execution
of this thread ?
(a) t.yield()
464
(b) yield(t)
(c) yield()
(d) yield(100) where 100 is the milli seconds of time
--------------------
--------------------
(a) 1
(b) 2
(c) 3
(d) 4
ANS: (c)
Strings are immutable. So, for each String operation, one new object is generated.
--------------------
--------------------
--------------------
(a) finally()
(b) finalize()
(c) final()
--------------------
465
--------------------
--------------------
14) If we want to read a very big text file with so many mega bytes of data, what shall we
use ?
(a) FileInputStream
(b) InputStreamReader
(c) BufferedReader
--------------------
--------------------
--------------------
17) A program given using try, catch and finally and it is asked to find out which
statements get executed ?
--------------------
18) What code, if written, below the (//code here) will display 0.
class Test {
public static void main(String argv[]) {
int i=0;
//code here
}
}
(a) System.out.println(i++)
(b) System.out.println(i+'0')
(c) System.out.println(i--)
466
(d) System.out.println(i)
ANS: (a),(c),(d)
The option (b) displays the ASCII value of '0'. So, the output in this case is: 48
--------------------
19) What is the better way of writing the Constructor with 2 parameters in the following
code:
class Test {
int x,y;
Test(int a) {
x=a;
}
Test(int a, int b) {
x=a;
y=b;
}
}
----------------------------------------------------
--------------------
--------------------
2) A java program on nested (inner) loops and it is asked what is the output of the
program.
467
--------------------
--------------------
--------------------
5) If the cookies are disabled, how can you maintain the Session.
--------------------
6) If there are strict timelines and if you want to get high performance for JSP to DB
access, what method you suggest ?
--------------------
--------------------
--------------------
--------------------
468
10) In CMP bean, which method executes only once in life time
(a) setEntityContext()
(b) create()
(c) remove()
(d) find()
--------------------
--------------------
12) A question on Threads in Java, whether we need to mention the word "Daemon"
explicitly to make a thread as Daemon.
--------------------
(a) TRANSACTION_UNREPEATABLE_READ
(b) TRANSACTION_REPEATABLE_READ
(c) TRANSACTION_COMMIT_READ
(d) TRANSACTION_UNCOMMIT_READ
(I don't know answer and also I am not sure of options. but the options are something
similar to this.)
--------------------
14) Question on EJB Home Object, Remote Object and what functionalities will be
performed by each.
--------------------
469
15) What is the difference between Server and Container
--------------------
(a) SELECT
(b) INSERT
(c) UPDATE
(d) DELETE
--------------------
17) A question on where the garbage collection is done. I think the answer is : "finalize()"
method
--------------------
18) A question properties of Primary key in Entity Beans (I don't remember the options
exactly.)
EJB containers pools stateless session beans and reuses them to service many
clients. Stateful session beans can be passivated and reused for other clients.
But this involves I/O bottlenecks. Because a stateful session bean caches client
conversation in memory, a bean failure may result in loosing the entire client
conversation. Therefore, while writing a stateful session bean the bean
developer has to keep the bean failure and client conversation loss in mind.
470
In case of stateless session beans, client specific data has to be pushed to the
bean for each method invocation which will result in increase in the network
traffic. This can be avoided in a number of ways like persisting the client
specific data in database or in JNDI. But this also results in I/O performance
bottlenecks.
Stateful session beans remembers the previous request and responses. But
stateless beans do not. stateful does not have pooling concept, whereas the
stateless bean instances are pooled
-------------------------------------------------------------------
BMP: Programmers has to write a code that implements Tx behaviour to the bean class.
Tuned CMP entity beans offer better performance than BMP entity beans. Moving
towards the CMP based approach provides database independence since it does not
contain any database storage APIs within it. Since the container performs
database operations on behalf of the CMP entity bean, they are harder to debug.
BMP beans offers more control and flexibility that CMP beans.
Diff 1) In BMP you will take care of all the connection and you write the SQL
code inside the bean whereas in CMP the container will take care of it
Diff 2) The BMP is not portable across all DB's.whereas the CMP is
-------------------------------------------------------------------
471
-------------------------------------------------------------------
With Forward, request & response would be passed to the destination URL which
should be relative (means that the destination URL shud be within a servlet
context). Also, after executing forward method, the control will return back to
the same method from where the forward method was called. All the opposite to
the above points apply to sendRedirect.
(OR)The forward will redirect in the application server itself. It does not come
to the client. whereas Response.sendredirect() will come to the client and go
back ...ie. URL appending will happen.
-------------------------------------------------------------------
(5)What is Synchornize?
-------------------------------------------------------------------
For Deadlock avoidance use Simplest algorithm where each process tells max number
of resources it will ever need. As process runs, it requests resources but never
exceeds max number of resources. System schedules processes and allocates resoures
in a way that ensures that no deadlock results.
-------------------------------------------------------------------
472
-------------------------------------------------------------------
Pass By Reference means the passing the address itself rather than passing the
value. Passby Value means passing a copy of the value to be passed.
-------------------------------------------------------------------
-------------------------------------------------------------------
DOM parser is one which makes the entire XML passed as a tree Structure and
will have it in memory. Any modification can be done to the XML.
SAX parser is one which triggers predefined events when the parser
encounters the tags in XML. Event-driven parser. Entire XML will not be stored
in memory. Bit faster than DOM. NO modifications can be done to the XML.
-------------------------------------------------------------------
Map is Interface and Hashmap is class that implements that and its not
serialized HashMap is non serialized and Hashtable is serialized
-------------------------------------------------------------------
473
-------------------------------------------------------------------
-------------------------------------------------------------------
-------------------------------------------------------------------
Session beans -> Associated with a client and keeps states for a client
Entity Beans -> Represents some entity in persistent storage such as a database
-------------------------------------------------------------------
First version 1.0 contained session beans, entity beans were not included.
Entity beans were added to version 1.1 which came out during year 1999.
Current release is EJB version 1.2
-------------------------------------------------------------------
16)Services of EJB?
474
Database management :
–Database connection pooling
–DataSource, offered by the J2EE server. Needed to access connection pool of the server.
–Database access is configured to the J2EE server -> easy to change database / database
driver
Transaction management :
–Distributed transactions
–J2EE server offers transaction monitor which can be accessed by the client.
Security management :
–Authetication
–Authorization
–encryption
Distribution/replication offers
–Load balancing, load can be divided into separate servers.
–Failover, if one server fails, others can keep on processing normally.
–Performance, one server is not so heavy loaded. Also, for example Weblogic has thread
pools for improving performance in one server.
-------------------------------------------------------------------
Server should have replica for the case of failure of one server:
–Replication is invisible to the programmer
-------------------------------------------------------------------
475
18)Why not to use free J2EE servers?
-------------------------------------------------------------------
19) Alternative:Tuxedo
Tuxedo is a middleware that offers scalability services and transaction monitors.
C or C++ based.
Can be used with Java client by classes in JOLT package offered by BEA.
-------------------------------------------------------------------
DataSource:
–Object that can be used to achieve database connection from the connection pool.
–Can be accessed by the interface DataSource
Transaction monitor:
–Can be accessed by the interface UserTransaction.
-------------------------------------------------------------------
Naming service is needed to locate beans home interfaces or other objects (DataSource,
UserTransaction):
–For example, jndi name of the DataSource
476
–jndi name: java:comp/env/propertyName
-------------------------------------------------------------------
-------------------------------------------------------------------
-------------------------------------------------------------------
24)Entity Beans
477
-------------------------------------------------------------------
Entity beans are effective when application wants to access one row at a time.
If many rows needs to be fetched, using session beans can be better alternative
ava class (for example, Integer).
Entity beans are efficient when working with one row at a time
Cause a lot of network trafic.
Session Beans are efficient when client wants to access database directry.
–fetching/updating multiple rows from the database
-------------------------------------------------------------------
478
Container Types :
The deployment process installs J2EE application components in the following
types of J2EE containers. The J2EE components and container addressed in this
tutorial are shown in Figure 5.
An Enterprise JavaBeans (EJB) container manages the execution of all
enterprise beans for one J2EE application. Enterprise beans and their
container run on the J2EE server.
A web container manages the execution of all JSP page and servlet components
for one J2EE application. Web components and their container run on the J2EE
server.
An application client container manages the execution of all application
client components for one J2EE application. Application clients and their
container run on the client machine.
An applet container is the web browser and Java Plug-in combination running on
the client machine.
-------------------------------------------------------------------
479
PL\SQL
What is PL/SQL and what is it used for?
PL/SQL is Oracle's Procedural Language extension to SQL. PL/SQL's language syntax, structure and data
types are similar to that of ADA. The PL/SQL language includes object oriented programming techniques
such as encapsulation, function overloading, information hiding (all but inheritance). PL/SQL is commonly
used to write data-centric programs to manipulate data in an Oracle database.
Many Oracle applications are based on PL/SQL and it would be difficult of Oracle to ever
desupport PL/SQL. In fact, all indications are that PL/SQL still has a bright future ahead of it.
Many enhancements are still being made to PL/SQL. For example, Oracle 9iDB supports native
compilation of Pl/SQL code to binaries.
PL/SQL and Java appeal to different people in different job roles. The following table briefly
describes the difference between these two language environments:
PL/SQL:
Java:
This is done via a standalone utility that transforms the PL/SQL source code into portable binary
object code (somewhat larger than the original). This way you can distribute software without
having to worry about exposing your proprietary algorithms and methods. SQL*Plus and
SQL*DBA will still understand and know how to execute such scripts. Just be careful, there is no
"decode" command available.
481
Can one print to the screen from PL/SQL?
One can use the DBMS_OUTPUT package to write information to an output buffer. This buffer can be
displayed on the screen from SQL*Plus if you issue the SET SERVEROUTPUT ON; command. For
example:
set serveroutput on
begin
dbms_output.put_line('Look Ma, I can print from PL/SQL!!!');
end;
/
DBMS_OUTPUT is useful for debugging PL/SQL programs. However, if you print too much, the
output buffer will overflow. In that case, set the buffer size to a larger value, eg.: set serveroutput
on size 200000
If you forget to set serveroutput on type SET SERVEROUTPUT ON once you remember, and
then EXEC NULL;. If you haven't cleared the DBMS_OUTPUT buffer with the disable or enable
procedure, SQL*Plus will display the entire contents of the buffer when it executes this dummy
PL/SQL block.
DECLARE
fileHandler UTL_FILE.FILE_TYPE;
BEGIN
fileHandler := UTL_FILE.FOPEN('/tmp', 'myfile', 'w');
UTL_FILE.PUTF(fileHandler, 'Look ma, I''m writing to a
file!!!\n');
UTL_FILE.FCLOSE(fileHandler);
EXCEPTION
WHEN utl_file.invalid_path THEN
raise_application_error(-20000, 'ERROR: Invalid path for
file or path not in INIT.ORA.');
END;
/
Can one call DDL statements from PL/SQL?
One can call DDL statements like CREATE, DROP, TRUNCATE, etc. from PL/SQL by using the
"EXECUTE IMMEDATE" statement. Users running Oracle versions below 8i can look at the DBMS_SQL
package (see FAQ about Dynamic SQL).
begin
EXECUTE IMMEDIATE 'CREATE TABLE X(A DATE)';
end;
NOTE: The DDL statement in quotes should not be terminated with a semicolon.
Can one use dynamic SQL statements from PL/SQL?
Starting from Oracle8i one can use the "EXECUTE IMMEDIATE" statement to execute dynamic SQL and
PL/SQL statements (statements created at run-time). Look at these examples. Note that statements are NOT
terminated by semicolons:
EXECUTE IMMEDIATE 'CREATE TABLE x (a NUMBER)';
482
-- Using bind variables...
sql_stmt := 'INSERT INTO dept VALUES (:1, :2, :3)';
EXECUTE IMMEDIATE sql_stmt USING dept_id, dept_name, location;
-- Returning a cursor...
sql_stmt := 'SELECT * FROM emp WHERE empno = :id';
EXECUTE IMMEDIATE sql_stmt INTO emp_rec USING emp_id;
One can also use the older DBMS_SQL package (V2.1 and above) to execute dynamic statements. Look at
these examples:
CREATE OR REPLACE PROCEDURE DYNSQL AS
cur integer;
rc integer;
BEGIN
cur := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(cur, 'CREATE TABLE X (Y DATE)',
DBMS_SQL.NATIVE);
rc := DBMS_SQL.EXECUTE(cur);
DBMS_SQL.CLOSE_CURSOR(cur);
END;
/
More complex DBMS_SQL example using bind variables:
CREATE OR REPLACE PROCEDURE DEPARTMENTS(NO IN DEPT.DEPTNO%TYPE)
AS
v_cursor integer;
v_dname char(20);
v_rows integer;
BEGIN
v_cursor := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(v_cursor, 'select dname from dept where deptno
> :x', DBMS_SQL.V7);
DBMS_SQL.BIND_VARIABLE(v_cursor, ':x', no);
DBMS_SQL.DEFINE_COLUMN_CHAR(v_cursor, 1, v_dname, 20);
v_rows := DBMS_SQL.EXECUTE(v_cursor);
loop
if DBMS_SQL.FETCH_ROWS(v_cursor) = 0 then
exit;
end if;
DBMS_SQL.COLUMN_VALUE_CHAR(v_cursor, 1, v_dname);
DBMS_OUTPUT.PUT_LINE('Deptartment name: '||v_dname);
end loop;
DBMS_SQL.CLOSE_CURSOR(v_cursor);
EXCEPTION
when others then
DBMS_SQL.CLOSE_CURSOR(v_cursor);
raise_application_error(-20000, 'Unknown Exception
Raised: '||sqlcode||' '||sqlerrm);
END;
/
What is the difference between %TYPE and %ROWTYPE?
The %TYPE and %ROWTYPE constructs provide data independence, reduces maintenance costs, and
allows programs to adapt as the database changes to meet new business needs.
%ROWTYPE is used to declare a record with the same types as found in the specified database
table, view or cursor. Example:
483
DECLARE
v_EmpRecord emp%ROWTYPE;
%TYPE is used to declare a field with the same type as that of a specified table's column.
Example:
DECLARE
v_EmpNo emp.empno%TYPE;
What is the result of comparing NULL with NULL?
NULL is neither equal to NULL, nor it is not equal to NULL. Any comparison to NULL is evaluated to
NULL. Look at this code example to convince yourself.
declare
a number := NULL;
b number := NULL;
begin
if a=b then
dbms_output.put_line('True, NULL = NULL');
elsif a<>b then
dbms_output.put_line('False, NULL <> NULL');
else
dbms_output.put_line('Undefined NULL is neither = nor <> to
NULL');
end if;
end;
How does one get the value of a sequence into a PL/SQL variable?
As you might know, one cannot use sequences directly from PL/SQL. Oracle (for some silly reason)
prohibits this:
i := sq_sequence.NEXTVAL;
However, one can use embedded SQL statements to obtain sequence values:
select sq_sequence.NEXTVAL into :i from dual;
In Oracle8 one can call external 3GL code in a dynamically linked library (DLL or shared object).
One just write a library in C/ C++ to do whatever is required. Defining this C/C++ function to
PL/SQL makes it executable. Look at this External Procedure example.
To fix this problem one can easily rewrite code like this:
I can SELECT from SQL*Plus but not from PL/SQL. What is wrong?
PL/SQL respect object privileges given directly to the user, but does not observe privileges given through
roles. The consequence is that a SQL statement can work in SQL*Plus, but will give an error in PL/SQL.
Choose one of the following solutions:
• Grant direct access on the tables to your user. Do not use roles!
• GRANT select ON scott.emp TO my_user;
485
What is a mutating and constraining table?
"Mutating" means "changing". A mutating table is a table that is currently being modified by an update,
delete, or insert statement. When a trigger tries to reference a table that is in state of flux (being changed), it
is considered "mutating" and raises an error since Oracle should not return data that has not yet reached its
final state.
Another way this error can occur is if the trigger has statements to change the primary, foreign or
unique key columns of the table off which it fires. If you must have triggers on tables that have
referential constraints, the workaround is to enforce the referential integrity through triggers as
well.
• A row-level trigger cannot query or modify a mutating table. (Of course, NEW and OLD still can
be accessed by the trigger) .
• A statement-level trigger cannot query or modify a mutating table if the trigger is fired as the
result of a CASCADE delete.
• Etc.
486
Where can one find more info about PL/SQL?
• Oracle FAQ: PL/SQL code examples
• Oracle FAQ: PL/SQL Books
• PLNet.org - An open source repository for PL/SQL developers
• RevealNet PL/SQL Pipeline - A free community for Oracle developers worldwide
• The PL/SQL Cellar - Free Oracle PL/SQL scripts including a bitwise operations package and
message digest algorithms
• PLSolutions.com - PL/Solutions provides consulting and training services for the Oracle
PL/SQL language and PL/Vision
• The DMOZ PL/SQL Directory
487
Oracle SQL FAQ
What is SQL and where does it come from?
Structured Query Language (SQL) is a language that provides an interface to relational database systems.
SQL was developed by IBM in the 1970s for use in System R, and is a de facto standard, as well as an ISO
and ANSI standard. SQL is often pronounced SEQUEL.
In common usage SQL also encompasses DML (Data Manipulation Language), for INSERTs,
UPDATEs, DELETEs and DDL (Data Definition Language), used for creating and modifying
tables and other database structures.
The development of SQL is governed by standards. A major revision to the SQL standard was
completed in 1992, called SQL2. SQL3 support object extensions and are (partially?)
implemented in Oracle8 and 9.
What are the difference between DDL, DML and DCL commands?
DDL is Data Definition Language statements. Some examples:
488
• COMMIT - save work done
• SAVEPOINT - identify a point in a transaction to which you can later roll back
• ROLLBACK - restore database to original since the last COMMIT
• SET TRANSACTION - Change transaction options like what rollback segment to use
How does one escape special characters when building SQL queries?
The LIKE keyword allows for string searches. The '_' wild card character is used to match exactly one
character, '%' is used to match zero or more occurrences of any characters. These characters can be escaped
in SQL. Example:
SELECT name FROM emp WHERE id LIKE '%\_%' ESCAPE '\';
Method 1:
Note 2: If you are comparing NOT-NULL columns, use the NVL function. Remember that NULL is
not equal to NULL. This should not be a problem as all key columns should be NOT NULL by
definition.
If you don't want to go through the floor and ceiling math, try this method (contributed by Erik
Wile):
select to_char(to_date('00:00:00','HH24:MI:SS') +
(date1 - date2), 'HH24:MI:SS') time_difference
from ...
Note that this query only uses the time portion of the date and ignores the date itself. It will thus
never return a value bigger than 23:59:59.
NOW NOW_PLUS_30_SECS
-------------------- --------------------
03-JUL-2002 16:47:23 03-JUL-2002 16:47:53
How does one count different data values in a column?
Use this simple query to count the number of data values in a column:
select my_table_column, count(*)
from my_table
group by my_table_column;
A more sophisticated example...
select dept, sum( decode(sex,'M',1,0)) MALE,
490
sum( decode(sex,'F',1,0)) FEMALE,
count(decode(sex,'M',1,'F',1)) TOTAL
from my_emp_table
group by dept;
How does one count/sum RANGES of data values in a column?
A value x will be between values y and z if GREATEST(x, y) = LEAST(x, z). Look at this example:
select f2,
sum(decode(greatest(f1,59), least(f1,100), 1, 0)) "Range
60-100",
sum(decode(greatest(f1,30), least(f1, 59), 1, 0)) "Range
30-59",
sum(decode(greatest(f1, 0), least(f1, 29), 1, 0)) "Range
00-29"
from my_table
group by f2;
For equal size ranges it might be easier to calculate it with DECODE(TRUNC(value/range), 0, rate_0, 1,
rate_1, ...). Eg.
select ename "Name", sal "Salary",
decode( trunc(f2/1000, 0), 0, 0.0,
1, 0.1,
2, 0.2,
3, 0.31) "Tax rate"
from my_table;
Can one retrieve only the Nth row from a table?
Shaik Khaleel provided this solution to select the Nth row from a table:
SELECT * FROM (
SELECT ENAME,ROWNUM RN FROM EMP WHERE ROWNUM < 101 )
WHERE RN = 100;
Note: Note: In this first it select only one more than the required row, then it selects the required one. Its far
better than using MINUS operation.
SELECT f1 FROM t1
WHERE rowid = (
SELECT rowid FROM t1
WHERE rownum <= 10
MINUS
SELECT rowid FROM t1
WHERE rownum < 10);
Alternatively...
SELECT * FROM emp WHERE rownum=1 AND rowid NOT IN
(SELECT rowid FROM emp WHERE rownum < 10);
Please note, there is no explicit row order in a relational database. However, this query is quite fun and may
even help in the odd situation.
Can one retrieve only rows X to Y from a table?
Shaik Khaleel provided this solution to the problem:
SELECT * FROM (
SELECT ENAME,ROWNUM RN FROM EMP WHERE ROWNUM < 101
) WHERE RN between 91 and 100 ;
Note: the 101 is just one greater than the maximum row of the required rows (means x= 90, y=100, so the
inner values is y+1).
491
Another solution is to use the MINUS operation. For example, to display rows 5 to 7, construct a
query like this:
SELECT *
FROM tableX
WHERE rowid in (
SELECT rowid FROM tableX
WHERE rownum <= 7
MINUS
SELECT rowid FROM tableX
WHERE rownum < 5);
Please note, there is no explicit row order in a relational database. However, this query is quite fun and may
even help in the odd situation.
How does one select EVERY Nth row from a table?
One can easily select all even, odd, or Nth rows from a table using SQL queries like this:
SELECT *
FROM emp
WHERE (ROWID,0) IN (SELECT ROWID, MOD(ROWNUM,4)
FROM emp);
Method 2: Use dynamic views (available from Oracle7.2):
SELECT *
FROM ( SELECT rownum rn, empno, ename
FROM emp
) temp
WHERE MOD(temp.ROWNUM,4) = 0;
Please note, there is no explicit row order in a relational database. However, these queries are quite fun and
may even help in the odd situation.
How does one select the TOP N rows from a table?
Form Oracle8i one can have an inner-query with an ORDER BY clause. Look at this example:
SELECT *
FROM (SELECT * FROM my_table ORDER BY col_name_1 DESC)
WHERE ROWNUM < 10;
Use this workaround with prior releases:
SELECT *
FROM my_table a
WHERE 10 >= (SELECT COUNT(DISTINCT maxcol)
FROM my_table b
WHERE b.maxcol >= a.maxcol)
ORDER BY maxcol DESC;
How does one code a tree-structured query?
Tree-structured queries are definitely non-relational (enough to kill Codd and make him roll in his grave).
Also, this feature is not often found in other database offerings.
The SCOTT/TIGER database schema contains a table EMP with a self-referencing relation
(EMPNO and MGR columns). This table is perfect for tesing and demonstrating tree-structured
queries as the MGR column contains the employee number of the "current" employee's boss.
The LEVEL pseudo-column is an indication of how deep in the tree one is. Oracle can handle
queries with a depth of up to 255 levels. Look at this example:
492
select LEVEL, EMPNO, ENAME, MGR
from EMP
connect by prior EMPNO = MGR
start with MGR is NULL;
One can produce an indented report by using the level number to substring or lpad() a series of spaces, and
concatenate that to the string. Look at this example:
select lpad(' ', LEVEL * 2) || ENAME ........
One uses the "start with" clause to specify the start of the tree. More than one record can match the starting
condition. One disadvantage of having a "connect by prior" clause is that you cannot perform a join to other
tables. The "connect by prior" clause is rarely implemented in the other database offerings. Trying to do this
programmatically is difficult as one has to do the top level query first, then, for each of the records open a
cursor to look for child nodes.
One way of working around this is to use PL/SQL, open the driving cursor with the "connect by
prior" statement, and the select matching records from other tables on a row-by-row basis,
inserting the results into a temporary table for later retrieval.
Some examples:
493
A, decode(A, B, 'A NOT GREATER THAN B', 'A GREATER
THAN B'),
'A NOT GREATER THAN B')...
Note: The decode function is not ANSI SQL and is rarely implemented in other RDBMS offerings. It is one
of the good things about Oracle, but use it sparingly if portability is required.
From Oracle 8i one can also use CASE statements in SQL. Look at this example:
SELECT ename, CASE WHEN sal>1000 THEN 'Over paid' ELSE 'Under
paid' END
FROM emp;
How can one dump/ examine the exact content of a database column?
SELECT DUMP(col1)
FROM tab1
WHERE cond1 = val1;
DUMP(COL1)
-------------------------------------
Typ=96 Len=4: 65,66,67,32
For this example the type is 96, indicating CHAR, and the last byte in the column is 32, which is the ASCII
code for a space. This tells us that this column is blank-padded.
Can one drop a column from a table?
From Oracle8i one can DROP a column from a table. Look at this sample script, demonstrating the
ALTER TABLE table_name DROP COLUMN column_name; command.
Other workarounds:
You can use the above technique to prevent sequence number loss before a SHUTDOWN
ABORT, or any other operation that would cause gaps in sequence values.
495
VB 6.0 .. revisited
1024
2,048
32,000
255.
496
9. What is frx?
Field, Form
21. With in the form we want to check all the text box
control are typed or not? How?
end if
next
64
3. What is Inprocess and Out of Process?
Generic Variable:
Specific Variable:
499
Binding Procedure Early and Late Binding ( Can be
Remove from the Memory).
7. What are properties available in Clip Board?
8. What is Dll?
If Tabstrip1.SelectedItem.Index = 1 Then
…..
End if
12. What is the diff between the Create Object and Get
object?
No.
Vbrun300.dll
501
26. Can We create CGI scripts in VB?
Yes.
Screen.MousePointer = VBHourGlass/VBNormal.
Datagrid – Editable.
Flexigrid – Non-Editable. (Generally used for Read
only purpose.)
Data_Validate, Data_Error.
502
4 types of locks. They are
1. Batch Optimistic
2. Optimistic
3. Pessimistic
4. ReadOnly
"Call ProcedureName}"
Set Rs = Qy.OpenresultSet
Txt(1)=Rs.RdoColumns(0)
Only in DbOpenTables.
Syntax: rs.index = "empno"
rs.seek "=" , 10
If with our setting the rs.index then run time error
will occur.
This will call the top most error where the error is
handled.
17. To connect the Data Control with Back end What are
all the properties to be set?
Dim x as RDOError
X(0).Des
X(1).Number
DateSerial(year(Now),Month(Now)+1,1)
Default Cursor – 0
ODBC Cursor (Client side) – 1
ServerSide Cursors (More Network traffic) - 2
505
25. Diff types of Lock Types?
RdConcurReadOnly 0 (Default)
RdConcurLock 1 (Pessimistic Locking)
RdConcurRowver 2 (Optimistic Lociking)
RdConcurValues 3
RdConcurBatch 4
Methods Events
Static + Keyset
Direction RdparamInput
RdparamInputOutput
RdParamOutput
Name
Type
Value
506
.
***********************************************************************
****************
ASP –
1. <SCRIPT LANGUAGE="VBScript" RUNAT=Server>
a = 1
</SCRIPT>
<SCRIPT LANGUAGE="VBScript">
a = 2
</SCRIPT>
<%
Response.Write a
%>
In the sample code shown above, what will be written
to the
screen?
A. 1
B. 2
C. 1, 2
D. 1&2
E. Nothing.
2. <%
Set Application("Thing") =
Server.CreateObject("THINGDOER.thingy")
%>
The above code appears in the global.asa file. What
would it
accomplish?
A. 0
B. 1
C. 2
507
D. 8
E. 9
A. ADO
B. RDODB
C. ADODB
D. RDS
E. OLEDB
A. Properties
B. Records
C. Fields
D. Errors
E. Parameters
9. <%
intA = 3
sStrA = "Hello World"
sStrB = "Hello World" + intA
Response.Write sStrB
%>
508
A. Type mismatch error
B. "Hello World, Hello World, Hello World"
C. 0
D. "Hello World 3"
E. "Hello World"
A. C:\InetPUb
B. C:\InetPUb\WWWroot
C. C:\InetPUb\wwwroot\MAT
D. Error
A. Server
B. Response
C. Request
D. ObjectContext
509
15. IsClientConnected is a property of
A. Server
B. Response
C. Request
D. Sesssion
POST METHOD:
The POST method generates a FORM collection, which is
sent as a HTTP request body. All the values typed in
the form will be stored in the FORM collection.
GET METHOD:
The GET method sends information by appending it to
the URL (with a question mark) and stored as
A Querystring collection. The Querystring collection
is passed to the server as name/value pair.
The length of the URL should be less than 255
characters.
Response.Write
512
· Ad Rotator component – a way to manage
advertisements on the web site.
· Content Linker component – a technique to direct
users through a set of pages on a web site by creating
a list of URLs and description of the next and
previous pages.
· Browser Capabilities component – allows to customize
the page to the ability of the browser viewing it.
· Database Access component – allows to access data
from the database
ASP – Grade C
A. Request.Cookies("FavoriteFlavors").HasItems
B. Request.Cookies("FavoriteFlavors").Collection.Count
C. Request.Cookies("FavoriteFlavors").Dictionary
D. Request.Cookies("FavoriteFlavors").HasKeys
E. Request.Cookies("FavoriteFlavors").Count
A. Jscript
B. JavaScript
C. JAVA
D. VBScript
E. ECMAScript
A. ADO
B. RDO
C. RDS
D. OLEDB
E. None of the above.
A. Application only.
B. Session only.
C. Server only.
D. Application and Session only.
E. Application, Session, and Server.
A. FTP service
B. SMTP service
514
C. IIS administrator
D. Exchange Server
E. IPX/SPX protocol
A. objBrowser =
Server.CreateObject("MSWC.BrowserType")
B. Set objBrowser =
Server.CreateObject("MSWC.BrowserType")
C. var objBrowser =
Server.CreateObject("MSWC.BrowserType")
D. var objBrowser = CreateObject("MSWC.BrowserType")
E. var objBrowser = Server.CreateObject("BrowserType")
A. 20 Sec
B. 30 Sec
C. 60 Sec
D. 90 Sec
A. 10
B. 20
C. 30
D. 40
VBScript
516
JavaScript
REDIM
Up to 60 dimensions.
ASP OBJECTS
· Request Object
· Response Object
· Server Object
· Session Object
· Application Object
517
Gets information from the user. It has five
collections by which values can be accessed. They are:
Querystring, Form, Cookies, Server Variables &
ClientCertificate
ASP - Grade A
1. <%
strName="John Smith"
%>
Referring to the above, if you want to pass the
contents of
the strName variable in a hyperlink, which line of
code would you
use?
A. Contenttype=Application/Brush
B. Contenttype=Image/JPG
C. Contenttype=Application/paint
D. Contenttype=Image/WMF
A. Key()
521
B. CompareMode
C. Item ()
D. Exists ()
E. Count
A. TextStream
B. Dictionary Object
C. Err Object
D. FileSystemObject
E. All are available from scrrun.dll.
17. What are the browsers that can access ASP pages?
1) Global.asa
2) Server-side Includes
3) Jscript scripts tagged within <SCRIPT> tags
4) HTML together with scripts tagged within <% … %>
delimiters
5) VBScripts tagged within <SCRIPT> tags
523
28. What is Querystring collection?
This collection stores any values that are provided in
the URL. This can be generated by three methods:
· By clicking on an anchor tag <A>
· By sending a form to the server by the GET method
· Through user-typed HTTP address
525
-------------------------------------------------------------------------------------
1)3 main differences between flexgrid control and dbgrid(Data bound Grid) control
-------------------------------------------------------------------------------------
The Microsoft FlexGrid (MSFlexGrid) control displays and operates on tabular data.
It allows complete flexibility to sort, merge, and format tables containing strings and
pictures.
When bound to a Data control, MSFlexGrid displays read-only data.Adaptation to
existing Visual Basic code for the data-bound grid (DBGrid).
dbgrid id A spreadsheet-like bound control that displays a series of rows and columns
representing records and fields from a Recordset object.
The data grids are bound controls; that is, they require a data source that actually
connects to
a database and retrieves their data. And it seems that the root of the problem with DBGrid
is that there's no data source that can be readily included along with the DBGrid control.
In Visual Basic, the solution is simply to include the Data Control on the same form as
DBGrid.
But the Data Control is an intrinsic control; it's unavailable to anything outside of the
Visual
Basic environment itself.
and VB 6.0 has a new set of data controls (DataGrid, DataList, DataCombo,
MSHFlexGrid, MSFlexGrid)
that once again are bound controls. Unlike DBGrid, though, they support OLE DB, and
therefore
rely on the an ADO Data Source (and in particular the ActiveX Data Objects Data
Control, or ADO
DC) for data access. Unlike the Data Control, the ADO DC is a custom control (that is, an
.OCX)
that can be added to any project. In short, if you add ADO DC to your project along with
the
DataGrid control.
-------------------------------------------------------------------------------------
2)ActiveX and Types of ActiveX Components in VB ?
-------------------------------------------------------------------------------------
Standard EXE
ActiveX EXE
ActiveX DLL
ActiveX document
ActiveX Control
Project Group
-------------------------------------------------------------------------------------
3)diff between inprocess and out of process ?
-------------------------------------------------------------------------------------
526
An in-process component is implemented as a DLL, and runs in the same process space
as its client
app, enabling the most efficient communication between client and component.Each
client app that
uses the component starts a new instance of it.
An out of process component is implemented as an EXE, and unlike a dll, runs in its own
process
space. As a result, exe's are slower then dll's because communications between client and
component must be marshalled across process boundaries. A single instance of an out of
process
component can service many clients.
-------------------------------------------------------------------------------------
3)Advantage of ActiveX Dll over Active Exe ?
-------------------------------------------------------------------------------------
ACTIVEX DLL:
=============
An in-process component, or ActiveX DLL, runs in another application’s process.
In-process components are used by applications or other in-process components.
this allows you to wrap up common functionality (like an ActiveX Exe).
ACTIVEX EXE:
=============
An out-of-process component, or ActiveX EXE, runs in its own address space.
The client is usually an application running in another process.The code running in an
ActiveX
Exe is running in a separate process space. You would usually use this in N-Tier
programming.
An ActiveX EXE runs out of process while an ActiveX DLL runs in the same process
space as VB app.
Also, and ActiveX EXE can be run independent of your application if desired.
-------------------------------------------------------------------------------------
4)single thread and multithread thread aprtments
-------------------------------------------------------------------------------------
All components created with Visual Basic use the apartment model, whether they’re
single-threaded
or multithreaded. A single-threaded component has only one apartment, which contains
all the
objects the component provides.
527
This means that a single-threaded DLL created with Visual Basic is safe to use with a
multithreaded client. However, there’s a performance trade-off for this safety. Calls from
all client threads except one are marshaled, just as if they were out-of-process calls.
-------------------------------------------------------------------------------------
5)What is a Component?
-------------------------------------------------------------------------------------
If you compile an ActiveX dll, it becomes a component. If you compile an ActiveX
Control,
it becomes both a component and a control. Component is a general term used to
describe code
that's grouped by functionality. More specifically, a component in COM terms is a
compiled
collection of properties/methods and events. Typically a component is loaded into your
project
via the References whereas an ActiveX Control is loaded into your project via
"components".
-------------------------------------------------------------------------------------
6)What is meant by "Early Binding" and "Late Binding"? Which is better?
-------------------------------------------------------------------------------------
Early binding and late binding refer to the method used to bind an interface's properties
and
methods to an object reference (variable). Early binding uses type library information at
design
time to reference procedures, while late binding handles this at run time. Late binding
handles this by interrogating the reference before each call to insure that it supports a
particular method. Since every call to a late bound object actually requires two calls
("Do you do this?" followed by "Okay, do it then"), late binding is much less efficient
than
early binding. Except where early binding is not supported (ASP, scripting, etc.), late
binding
should only be used in very special cases.
It is a common misconception that any code using the CreateObject function instead of
Set = New is using late binding. This is not the case. The type declaration of the object
variable determines whether it is late or early bound, as in the following:
Dim A As Foo
Dim B As Foo
Dim C As Object
Dim D As Object
528
Set D = New Foo 'Late Bound
-------------------------------------------------------------------------------------
7)Advantages of disconnected recordsets
-------------------------------------------------------------------------------------
A disconnected Recordset, as its name implies, is a Recordset that lacks a connection.
This may seem a bit confusing at first - how can a Recordset lack a connection to a data
store?
- but will hopefully become more clear as the article progresses.
seen that a Recordset that does not have a database connection can be very useful as a
tool in
your programming. It can save you time and effort and make your code more scalable.
rst.LockType = adLockBatchOptimistic
rst.CursorLocation = adUseClient
However, we've recently discovered that these steps aren't necessary. VB automatically
assigns
batch optimistic locking to newly created, connectionless recordsets. And, of course,
without a
connection, a recordset can't have any other cursor but a client-side one. To create one of
these
structures, then, the only thing you need do is create the object variable instance. After
that,
you can simply begin adding fields to the construct.
To add fields, you use the Fields collection's Append method. This method requires two
parameters
, the field name and the field data type. So, to create a connectionless recordset with two
fields,you'd use code similar to:
529
Additional, optional Append method parameters include DefinedSize and Attrib. The
DefinedSize
argument takes the size of the field. Fill the Attrib parameter with constants that define
additional field characteristics, such as whether it will allow null values or is updatable.
Since, in our technique, we want the fields to mirror the structure of the original
recordset,
we'll simply use existing values for these parameters.
Disconnected Recordsets, first available with ADO 2.0, are the most commonly used
mechanism to
retrieve a Recordset and open a connection for only the necessary amount of time, thus
increasing
scalability. They are call disconnected because the connection to the database is closed.
The collections, properties, and methods of a disconnected Recordset are still available
even
though the connection is closed. This frees up server resources, given that the number of
open
connections is limited and database locking is a non-issue.
-------------------------------------------------------------------------------------
8)Benefit of wrapping database calls into MTS transactions?
-------------------------------------------------------------------------------------
If database calls are made within the context of a transaction, aborting the transaction will
undo and changes that occur within that transaction. This removes the possibility of
stranded,
or partial data.
Transaction that uses the Microsoft® Transaction Server (MTS) environment. MSMQ
implicitly
uses the current MTS transaction if one is available.
BENIFTIS OF USING MTS :
***********************
Database Pooling, Transactional operations, Deployment, Security, Remote Execution
This allows MTS to reuse database connections. Database connections are put to ?sleep?
As
opposed to being created and destroyed and are activated upon request.
-------------------------------------------------------------------------------------
9)How to register a component?
-------------------------------------------------------------------------------------
Compiling the component, running REGSVR32 MyDLL.dll
-------------------------------------------------------------------------------------
10)Controls which do not have events ?
-------------------------------------------------------------------------------------
Shape and line controls are useful for drawing graphical elements on
the surface of a form. These controls don't support any events; they
are strictly for decorative purposes.
530
EXTRA INFO::
*************
The image, shape and line controls are considered to be lightweight controls;
that is, they support only a subset of the properties, methods, and events
found in the picture box. Because of this, they typically require less system
resources and load faster than the picture box control.
-------------------------------------------------------------------------------------
11)Control Categories
-------------------------------------------------------------------------------------
a)Intrinsic controls:
**********************
such as the command button and frame controls.
These controls are contained inside the Visual Basic .exe file. Intrinsic controls are
always
included in the toolbox
b)ActiveX controls:
**********************
which exist as separate files with a .ocx file name extension. These
include controls that are available in all editions of Visual Basic
(DataCombo, DataList controls, and so on) and those that are available
only in the Professional and Enterprise editions (such as Listview,
Toolbar, Animation, and Tabbed Dialog). Many third-party ActiveX controls
are also available.
c)Insertable Objects:
**********************
such as a Microsoft Excel Worksheet object containing a list of all
your company's employees, or a Microsoft Project Calendar object containing the
scheduling information for a project. Since these can be added to the toolbox,
they can be considered controls.Some of these objects also support Automation
(formerly called OLE Automation),which allows you to program another application's
objects from within a Visual Basic application.
-------------------------------------------------------------------------------------
12)DIFF between Image and Picture box controls
-------------------------------------------------------------------------------------
The sizing behavior of the image control differs from that of the picture box. It has a
Stretch
property while the picture box has an AutoSize property. Setting the AutoSize property to
True
causes a picture box to resize to the dimensions of the picture; setting it to False causes
the
picture to be cropped (only a portion of the picture is visible). When set to False (the
default)
531
, the Stretch property of the image control causes it to resize to the dimensions of the
picture.
Setting the Stretch property to True causes the picture to resize to the size of the image
control, which may cause the picture to appear distorted.
-------------------------------------------------------------------------------------
13)Default property of datacontrol ?...
-------------------------------------------------------------------------------------
connect property......(not sure..)
-------------------------------------------------------------------------------------
14)Define the scope of Public, Private, Friend procedures?
-------------------------------------------------------------------------------------
The set of public variables, methods, properties, and events described in a class module
define
the interface for an object. The interface consists of the object members that are available
to
a programmer who's using the object from code.<=====>
You can create private variables, methods, properties, and events that are used by other
procedures within the class module but are not part of the object's public interface.
Additionally, constants user-defined types, and Declare statements within a class module
must always be private.<====>
The Friend keyword makes a procedure private to the project: The procedure is available
to any code running within the project, but it is not available to a referencing project.
-------------------------------------------------------------------------------------
15)Describe Database Connection pooling relative to MTS ?
-------------------------------------------------------------------------------------
This allows MTS to reuse database connections. Database connections are put to ?sleep?
as opposed
to being created and destroyed and are activated upon request.
Object pooling is an important design concept required for high-performance
applications.
A performance optimization based on using collections of preallocated resources, such as
objects
or database connections. Pooling results in more efficient resource allocation.
-------------------------------------------------------------------------------------
16)Difference between a function and a subroutine ?
-------------------------------------------------------------------------------------
A function accepts any number of parameters (possibly zero), does something with them,
and
returns a value.
A subroutine is performs an action, but doesn't return a value.
A function call has the following syntax ::function (arg1, arg2, ...)
where: function -->Is the name of the function. arg1, arg2, ... Are the arguments.
532
A subroutine call has the following syntax ::subroutine (arg1, arg2, ...
{outputfield|'format'})
where: subroutine -->Is the name of the subroutine. arg1, arg2, ... Are the arguments.
{outputfield|'format'} Is the name of the output field or its format.
In addition, on some platforms, the functions are available immediately; whereas, the
subroutines
are available in a special subroutine library that you must access.
-------------------------------------------------------------------------------------
17)Difference between Linked Object and Embedded Object?
-------------------------------------------------------------------------------------
Embedding objects -
*******************
When you embed an object, a copy of the object is inserted into the
destination document. There's no link to the original file. When you change information
in the
source document, no changes will be reflected in the destination document. The actual
data for
the object is stored within the destination file. To make changes to the embedded object,
double
click it and it will launch the original application the source file was in.
Linking objects -
*****************
Information is updated when you modify the original source file when you use a linked
object.
This dynamic updating is very handy for things such as the aforementioned monthly
report.
You can open up the Excel spreadsheet that is referenced within your Word
document.Make changes
to the spreadsheet, close Excel, and when you open your Word document... viola! The
changes are
already there. If that object is linked to ten other Word files, the changes are already in
those
ten files, too!
actually linking or embedding an object is fast and easy.
-------------------------------------------------------------------------------------
18)Difference between listbox and combo box?
-------------------------------------------------------------------------------------
A LISTBOX CONTROL displays a list of items from which the user can
select one or more. If the number of items exceeds the number that can
be displayed, a scroll bar is automatically added to the ListBox control.
A COMBOX CONTROL combines the features of a text box and a list box.
This control allows the user to select an item either by typing text
into the combo box, or by selecting it from the list.
533
DIFF::Generally, a combo box is appropriate when there is a list of
suggested choices, and a list box is appropriate when you want to limit
input to what is on the list. A combo box contains an edit field, so
choices not on the list can be typed in this field.
-------------------------------------------------------------------------------------
19)Difference between Dynaset and Snapshot?
-------------------------------------------------------------------------------------
All Recordset objects are constructed using records (rows) and fields (columns). There
are five types of Recordset objects:
Table-type Recordset ::
********************
representation in code of a base table that you can use to add, change,
or delete records from a single database table (Microsoft Jet workspaces only).
Dynaset-type Recordset ::
**********************
the result of a query that can have updatable records. A dynaset-type
Recordset object is a dynamic set of records that you can use to add,
change, or delete records from an underlying database table or tables.
A dynaset-type Recordset object can contain fields from one or more
tables in a database. This type corresponds to an ODBC keyset cursor.
Snapshot-type Recordset ::
**********************
a static copy of a set of records that you can use to find data or
generate reports. A snapshot-type Recordset object can contain fields
from one or more tables in a database but can't be updated. This type
corresponds to an ODBC static cursor.
Forward-only-type Recordset::
***************************
identical to a snapshot except that no cursor is provided. You can only
scroll forward through records. This improves performance in situations
where you only need to make a single pass through a result set. This
type corresponds to an ODBC forward-only cursor.
Dynamic-type Recordset ::
**********************
a query result set from one or more base tables in which you can add,
change, or delete records from a row-returning query. Further, records
other users add, delete, or edit in the base tables also appear in your
Recordset. This type corresponds to an ODBC dynamic cursor (ODBCDirect
workspaces only).
-------------------------------------------------------------------------------------
534
20)Difference Listindex and Tab index?
-------------------------------------------------------------------------------------
LIST INDEX::
Returns or sets theindex of the currently selected item in the control.
Not available at design time.Default LIST INDEX IS -1 for ComboBox, DirListBox, and
DriveListBox
controls
TAB INDEX::
Returns or sets thetab order of most objects within their parent form.
Visual Basic automatically renumbers the TabIndex of other controls to
reflect insertions and deletions. You can make changes atdesign time
using theProperties window or atrun time in code.The TabIndex property
isn't affected by the ZOrder method.
-------------------------------------------------------------------------------------
21)Difference modal and moduless window?
-------------------------------------------------------------------------------------
MODAL forms are forms which require user input before any other actions
can be taken place. In other words, a modal form has exclusive focus in
that application until it is dismissed. When showing a modal form, the
controls outside this modal form will not take user interaction until
the form is closed. The internal MsgBox and InputBox forms are examples
of modal forms. To show a form modally, use the syntax:
MODELESS forms are those which are shown but do not require immediate
user input. MDI child forms are always modeless. To show a form modeless,
use the syntax:: MyForm.SHOW
-------------------------------------------------------------------------------------
22)Difference Object and Class?
-------------------------------------------------------------------------------------
Classes and objects are separate but related concepts. Every object belongs to a class
and every class contains one or more related objects.1)A Class is static. All of the
attributes of a class are fixed before,during, and after the execution of a program.
The attributes of a class don't change.The class to which an object belongs is also
(usually)
static. If a particular object belongs to a certain class at the time that it is created then
it almost certainly will still belong to that class right up until the time that it is destroyed.
2)An Object on the other hand has a limited lifespan. Objects are created and eventually
destroyed. Also during that lifetime, the attributes of the object may undergo significant
change.So basically the difference between a class and an object is that a class is a
general
concept while objects are the specific and real instances that embody that concept. When
creating
535
an object oriented program we define the classes and the relationships between the
classes
. We then execute the program to create, update, and destroy the objects which are the
specific
realization of these classes.
-------------------------------------------------------------------------------------
23)Difference Query unload and unload in form?
-------------------------------------------------------------------------------------
Occurs before a form or application closes. When an MDIForm object closes, the
QueryUnload
event occurs first for the MDI form and then in all MDI child forms. If no form cancels
the
QueryUnload event, the Unload event occurs first in all other forms and then in an MDI
form.
When a child form or a Form object closes, the QueryUnload event in that form occurs
before
the form's Unload event.
-------------------------------------------------------------------------------------
24)Difference Declaration and Instantiation an object?
-------------------------------------------------------------------------------------
Dim obj as OBJ.CLASS with either
Set obj = New OBJ.CLASS or
Set obj = CreateObject(?OBJ.CLASS?) or
Set obj = GetObject( ,? OBJ.CLASS?)
or
Dim obj as New OBJ.CLASS
If this object is a form, you can add set myform = nothing and Form_Unload()
event.Maintain a
habit of remove the object by using set object = nothing which will benefit at last.
Visual Basic is supposed to automatically release objects when they go out of scope. To
free
up some memory usage, you can set the object to nothing.
-------------------------------------------------------------------------------------
25)Draw and explain Sequence Modal of DAO
-------------------------------------------------------------------------------------
Connection,Container,Database,DBEngine,Document,Error,Field,Group,Index Parameter
Property,QueryDef,Recordset,Relation,TableDef,User,Workspace
-------------------------------------------------------------------------------------
536
26)Version |Year |Significant Changes and New Features
-------------------------------------------------------------------------------------
1 1991 initial release, with drag and drop GUI creation
2 1992 ODBC, object variables
3 1993 Access Engine, OLE 2.0, Crystal Reports, new tools and controls
4 1995 classes, OCXs
5 1997 compiler, ActiveX controls
6 1998 web support, windowless controls, designers, data sources
.NET 2001 XML, SOAP, inheritance, structured exception handling
-------------------------------------------------------------------------------------
27)How can objects on different threads communicate with one another?
-------------------------------------------------------------------------------------
Processes communicate with one another through messages, using Microsoft's Remote
Procedure
Call (RPC) technology to pass information to one another.There is no difference to the
caller
between a call coming from a process on a remote machine and a call coming from
another process
on the same machine.
Multithreaded applications must avoid two threading problems: deadlocks and races.A
deadlock
occurs when each thread is waiting for the other to do something
-------------------------------------------------------------------------------------
28)How can you force new objects to be created on new threads?
-------------------------------------------------------------------------------------
The CreateThread function creates a thread to execute within the virtual address space
of the calling process.
To create a thread that runs in the virtual address space of another process Creating a new
thread is as easy as declaring it and supplying it with a delegate to the method where the
thread is to start. When you are ready to begin execution on the thread, call the
Thread.Start
Method. There are special considerations involved when working with multiple threads
of execution.
// C#
537
System.Threading.Thread myThread;
Instantiate the thread with the appropriate delegate for the starting point of the thread.
Use the
AddressOf operator to create the delegate in Visual Basic, or create a new ThreadStart
object in C#.
*******************
' Visual Basic
myThread = New System.Threading.Thread(AddressOf myStartingMethod)
// C#
myThread = new System.Threading.Thread(new
System.Threading.ThreadStart(myStartingMethod));
call the Thread.Start method to start the thread.
*******************
' Visual Basic
myThread.Start()
// C#
myThread.Start();
-------------------------------------------------------------------------------------
29)How does a DCOM component know where to instantiate itself?
-------------------------------------------------------------------------------------
To create a remote instance of a script component, call the CreateObject method, passing
it the name of the remote computer as a parameter.
If the remotable attribute of a script component's <registration> element has been set to
"true,"
the script component can be instantiated remotely from another computer using
Distributed COM (DCOM).
Both computers must have basic DCOM installed. Note The ability to use CreateObject
for instantiating
remote script components requires Visual Basic 6.0 or later or VBScript 5.0 or later.
The following Visual Basic example shows how to do this on a computer named
"myserver":
1. You can specify the machine on which you want to create the remote server object in
DCOM config ('dcomcnfg').
2. You can specify the machine name when instantiating the remote server object.
In C you can do this with a call to CoGetClassObject or CoCreateInstanceEx (instead of
CoCreateInstance,
538
which does not allow you to specify the name of the machine).
In VB you can specify the name in one of the parameters in the call to CreateObject
-------------------------------------------------------------------------------------
30)What type of multi-threading does VB6 implement?
-------------------------------------------------------------------------------------
Apartment model threading
-------------------------------------------------------------------------------------
31)How to register a component?
-------------------------------------------------------------------------------------
Compiling the component, running REGSVR32 MyDLL.dll
-------------------------------------------------------------------------------------
32)What is Database Connection pooling (relative to MTS)
-------------------------------------------------------------------------------------
This allows MTS to reuse database connections. Database connections are
put to "sleep" As opposed to being created and destroyed and are activated upon request.
-------------------------------------------------------------------------------------
33)What is the tool used to configure the port range and protocols for DCOM
communications?
-------------------------------------------------------------------------------------
DCOMCONFIG.EXE
-------------------------------------------------------------------------------------
34)What is a Type Library and what is it's purpose ?
-------------------------------------------------------------------------------------
The type library may represent another Visual Basic project, or any other executable
component that exposes a type library.
Visual Basic creates type library information for the classes you create, provides type
libraries for the objects it includes, and lets you access the type libraries provided
by other applications.
-------------------------------------------------------------------------------------
35)What are binary and project compatibility?
-------------------------------------------------------------------------------------
Visual Basic’s Version Compatibility feature is a way of enhancing your components
while
maintaining backward compatibility with programs that were compiled using earlier
versions.
The Version Compatibility box, located on the Component tab of the Project Properties
dialog box,
contains three options:
,sandhya2_001(Re)
539
No Compatibility:
*****************
Each time you compile the component, new type library information is generated,
including new
class IDs and new interface IDs. There is no relation between versions of a component,
and
programs compiled to use one version cannot use subsequent versions.
Project Compatibility:
**********************
Each time you compile the component the type library identifier is kept, so that your test
projects can maintain their references to the component project. All class IDs from the
previous
version are maintained; interface IDs are changed only for classes that are no longer
binary-compatible with their earlier counterparts.
Note This is a change in Project Compatibility from Visual Basic 5.0, where all class
IDs and
interface IDs in the project changed if any one class was no longer binary-compatible.
Binary Compatibility:
*********************
When you compile the project, if any binary-incompatible changes are detected you will
be presented
with a warning dialog. If you choose to accept the warning, the component will retain the
type
library identifier and the class IDs. Interface IDs are changed only for classes that are no
longer binary-compatible. This is the same behavior as Project Compatibility.
If, however, you choose to ignore the warning, the component will also maintain the
interface IDs
.This option is only available when the compiler determines that the change was in the
procedure ID or signature of a method.
Note:: When people talk about Version Compatibility, they’re usually referring to Binary
Compatibility.
-------------------------------------------------------------------------------------
38)How to set a shortcut key for label?
-------------------------------------------------------------------------------------
object.KeyLabel(keycode) [= string]
You would probably create the menu item as follows:
.Add "keyFile", , , "E&xit", , vbAltMask + vbCtrlMask, vbKeyEnd
The default key label for vbKeyEnd is "End". Thus, the shortcut string will be created
by default as "Ctrl+Alt+End".
540
-------------------------------------------------------------------------------------
39)Name the four different cursor and locking types in ADO and describe them briefly ?
-------------------------------------------------------------------------------------
CURSORS::
*********
The cursor types are listed from least to most resource intensive.
Forward Only - Fastest, can only move forward in recordset
Static - Can move to any record in the recordset. Data is static and never changes.
KeySet - Changes are detectable, records that are deleted by other users are unavailable,
and records created by other users are not detected
Dynamic - All changes are visible.
LOCKING TYPES::
****************
LockPessimistic - Locks the row once after any edits occur.
LockOptimistic - Locks the row only when Update is called.
LockBatchOptimistic - Allows Batch Updates.
LockReadOnly - Read only. Cannot alter the data.
-------------------------------------------------------------------------------------
40)Name the different compatibility types when creating a COM component.
-------------------------------------------------------------------------------------
No Compatibility - New GUID (Globally Unique Identifier) created, references from
other components will not work
Project Compatibility - Default for a new component <Not as critical to mention this
one>
Binary Compatibility - GUID does not change references from other components will
work
-------------------------------------------------------------------------------------
41)Why is it important to use source control software for source code?
-------------------------------------------------------------------------------------
Modification history. Code ownership: Multiple people cannot modify the same code at
the same time.
-------------------------------------------------------------------------------------
42)List the ADO objects?
-------------------------------------------------------------------------------------
Connection - Connects to a data source; contains the Errors collection
Command - Executes commands to the data source. The only object that can accept
parameters for a stored procedure
Recordset - The set of data returned from the database.
Under the ADO Command Object, The Parameters collection. collection is responsible
for input to stored procedures?
-------------------------------------------------------------------------------------
541
43)What two methods are called from the ObjectContext object to inform MTS that the
transaction was successful or unsuccessful?
-------------------------------------------------------------------------------------
SetComplete and SetAbort.
-------------------------------------------------------------------------------------
44)What is the benefit of wrapping database calls into MTS transactions?
-------------------------------------------------------------------------------------
Aborting the transaction will undo and changes that occur within that transaction.
This removes the possibility of stranded, or partial data
-------------------------------------------------------------------------------------
45)Describe and In Process vs. Out of Process component. Which is faster?
-------------------------------------------------------------------------------------
An in-process component is implemented as a DLL, and runs in the same process space
as
its client app, enabling the most efficient communication between client and component.
Each client app that uses the component starts a new instance of it.
-------------------------------------------------------------------------------------
46)How would you declare and raise custom events in a class?
-------------------------------------------------------------------------------------
a) Public Event OnVarChange();
b) RaiseEvent OnVarChange[(arg1, arg2, ... , argn)]
-------------------------------------------------------------------------------------
47)What is the difference between a Property Let and Property Set procedure?
-------------------------------------------------------------------------------------
Let - for simple variable
Set - for object
-------------------------------------------------------------------------------------
48)What is the difference between ANSI and UNICODE strings when passed as
arguments to a DLL?
-------------------------------------------------------------------------------------
ANSI - one byte for a char
UNICODE - two bytes per char - works only on NT
-------------------------------------------------------------------------------------
49)What is the difference in passing values ByRef or ByVal to a procedure?
-------------------------------------------------------------------------------------
ByRef -pass the address (for string -address of address of first byte)
BY REF IS VERY USEFULL When the contents itself are being modified, when there is
large data.
Multiple arguments are needed to be returned, instead they can be passed as reference.
542
ByVal -pass the value (for string -it is the address of first byte)
-------------------------------------------------------------------------------------
50)What is the purpose of the DoEvents command?
-------------------------------------------------------------------------------------
Fields execution so that the operating system can process other events. Returns number of
open
forms. Useful for things like ‘cancel search’ in windows
-------------------------------------------------------------------------------------
51)Name and define the logical tiers in a traditional 3-tiered architecture?
-------------------------------------------------------------------------------------
Presentation logic - front end (HTML, Visual Basic forms)
Business Logic - Applications and components that encapsulate business logic
Data end - databases to store data
-------------------------------------------------------------------------------------
52)What is the difference between a PictureBox and Image control?
-------------------------------------------------------------------------------------
Image Control - Use this to display a picture. Use it over the PictureBox because it takes
less operating system resources
PictureBox- While it can display pictures, it also acts as an area on which you can print
text and graphics.
Use it for home-grown graphics or print previews
-------------------------------------------------------------------------------------
53)Under which circumstance does a VB application ignore a Timer event?
-------------------------------------------------------------------------------------
When the system is really busy doing something else and when DoEvents is being
executed
-------------------------------------------------------------------------------------
54)What does the NewIndex property return?
-------------------------------------------------------------------------------------
Used to retrieve the index of the item most recently added to a ListBox or ComboBox
control
-------------------------------------------------------------------------------------
55)What is the purpose of the ClipControls property on a form or container?
-------------------------------------------------------------------------------------
Returns or sets a value that determines whether graphics methods in Paint events repaint
the
entire object or only newly exposed areas. Also determines whether the Microsoft
Windows
543
operating environment creates a clipping region that excludes non-graphical controls
contained
by the object. Read-only at run time.
-------------------------------------------------------------------------------------
56)What is the purpose of the AutoRedraw property on a form or container?
-------------------------------------------------------------------------------------
Setting AutoRedraw to True automatically redraws the output from these methods in a
Form object
or PictureBox control when, for example, the object is resized or redisplayed after being
hidden by another object
-------------------------------------------------------------------------------------
57)Have you ever used Collections? Collection Classes?
-------------------------------------------------------------------------------------
A collection is a set of Repository objects that are all connected to a common source
object via a relationship collection.
A collection provides a way to connect a group of dependent objects with an object that
‘contains’ them. For example, an Invoice object might have a collection of LineItem
objects.
-------------------------------------------------------------------------------------
58)What version control systems have you used?
-------------------------------------------------------------------------------------
TLIB 16-Bit add-in
-------------------------------------------------------------------------------------
59)? How about any other database engines?
-------------------------------------------------------------------------------------
Apollo OLE DB ,Apollo Server ,Apollo SQL ,FUNCky ,R&R Report Writer
-------------------------------------------------------------------------------------
36)What kind of components can you use as DCOM servers?
-------------------------------------------------------------------------------------
actve-x components, Com
-------------------------------------------------------------------------------------
544
SQL * PLUS
2. User can have 100 many number of variables per sql command.
3. User can have 500 many number of lines (assuming 80 characters per line)
per sql command.
5. Start command is used to run the contents of the specified command file.
6. The intersect operator is used to get only those rows that returned by both the
query.
7. The Grand command is used to set the System privileges, Object privileges.
10. The to-char function is used to convert the number datatype to a value of
varchar2
datatype.
545
11. The Truncate command is used to remove all rows in a Table or Cluster
instantly.
Note : We can not truncate rows from a table which is part of a cluster.
We cannot truncate rows from a table which has a referenced
integrity constraint.
12. The Cluster is a schema object that contains one or more tables that have
one
or more columns in common.
13. The Create Role command is used to set a set of privileges that can be
granted to users
or to other roles.
* To collect statistics about the object used by the optimizer and store them
in the data
dictionary.
* To delete statistics about the object from the data dictionary.
* To validate the structure of the object.
* To identify migrated and chained rows of the table or cluster.
a] 255
b] 21
c] 16
2. A number of columns in a table ranges from 1 to ____
a] 255
b] 254
c] 030
d] None of the above
546
3. The maximum number of components in the Decode expression , including
searches, results and default is
a] No limitation
b] 255
a] Synonym
b] Data block
c] View
d] None of the above
a] Between.. And
b] Equal operator
c] Set operator
d] Like
6. __________ returns only one copy of each set of duplicate rows selected.
a] Unique
b] Distinct
c] Group By
d] None of the above
a] Lock table
b] For update of
c] Object privileges
d] Row share
a] Where clause
b] Having Clause
c] Distinct
d] Exists
547
9. The ________ option is used to return rows in a hierarchial order
10. The ________ function is used to return the number of bytes in the internal
representation of expression
a] Length
b] Vsize
c] LengthLB
ORACLE * FORMS TEST PAPER
1. The _______ built-in is used to Exits the current form and enter the indicated
form
Ans: NEW_FORM
Ans: Stacked
3. The ________ package contains constructs that provides ways to write and
read
information to and from files
Ans: Text_IO
4. On MS-Windows the lookup path for icon files is defined by the _______
environment
variable in the ORACLE.INI file
Ans: TK21_ICONS
5. If user receive an error in the ORA-3100 to ORA-3199 range when you try to
log on to
Developer/2000 product, there may not be enough real-mode memory to
establish a
Communication buffer with an Oracle server.______________ solves this
problem by
reserving memory for server communications.
548
Ans: NETINIT7.EXE
7. The ____________ property is used When queried records have been marked
for inserts
, updates, specifies that only columns whose values were actually changed
which should
be included in the SQL UPDATE statement that is sent to the database
during a
COMMIT.
8. The _________ property specifies whether Oracle Forms should validate the
value of
the text item against the values in the attached LOV.
11.The ______ built-in is used to write data in the Forms to the Database, but
does not
perform a database Commit.
Ans: Post.
12. Two types of Windows are _________________________
13. The _____________ built-in is used to copy the values of each item in the
record with
the next lower sequence number to the corresponding item in the current
record.
549
14. An _______ is a container for a group of objects that can be used to copy or
reference
them in another module.
a] When-New-Item-Instance
b] When-validate-Item
c] Key-Next-Item Ans: F,A,C,D,B,E.
d] Post-change
e] Post-Text-Item
f] Pre-Text-Item
a] When-New-Record-Instance
b] Pre-Record
c] Post-Record
d] When-Validate-Item
e] When-Create-record Ans: E,B,A,D,C.
18. Oracle Forms performs the following steps when the ______ trigger fails
19. The _____ command is used to Execute the indicated Operating System
Command.
Ans: Host.
Ans: 255.
550
21. Oracle uses work areas called ______ to execute SQL Statement and store
processing
Information.
551
ORACLE QUESTIONS & ANSWERS
Questions Answers
What is a Database ? A Database can be one of the two definitions:
Note:-
A DBMS must be able to reliably manage a large
amount of data in a multi-user environment so
that many users can concurrently access the same
data.
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
554
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
555
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
556
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
557
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
558
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
559
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
560
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
561
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
562
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
563
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
564
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
565
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
566
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
567
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
568
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
569
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
570
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
571
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
572
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
573
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
574
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
575
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
576
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
577
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
578
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
579
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
580
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
581
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
582
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
583
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
584
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
585
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
586
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
587
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
588
No Oracle Questions & Answers
1 What are the different modules of FORMS 4.5 ?
Form, Menu and Library modules.
2 What are the differences between FORMS 3.0 and FORMS 4.5 ?
FORMS 3.0 FORMS 4.5
1] Mode Character GUI
2] System Variables 20 42
3] Session Single Multiple
4] Blocks, Canvas 255 No limit
5] Triggers 75 121
6] Items types - 10
7] Relation Design Time Run Time
( Using
SET_RELATION_PROPERTY )
8] Inheritance Not Available Available
9] Property Class - DO - - DO -
10] Object Groups - DO - - DO -
11] Library - DO - - DO -
12] Attached Libraries - DO - - DO -
13] Visual Attributes - DO - - DO -
3 What is the maximum limit for creating BLOCKS and CANVAS in FORMS 4.5 ?
NO LIMIT
4 In a MULTI RECORD BLOCK can we have an item displayed once ?
Yes, By setting the ITEMS DISPLAYED property for the respective item in the
Properties Window.
5 After creation of the block can we create a BUTTON PALETTE ?
No.
6 What are the different types of triggers that will be created for MASTER DELETES
properties such as a] ISOLATED, b] NON - ISOLATED, c] CASCADING ?
CASCADING On-Clear-Details
On-Populate-Details
Pre-Delete
ISOLATED On-Clear-Details
On-Populate-Details
7 What is the difference between creating a MASTER-DETAIL relationship in NEW
BLOCK window and creating relations after creation of the blocks ?
When you create the relation in the NEW BLOCK window, Oracle forms also alters the
properties of the FOREIGN KEY items(s) in the DETAIL BLOCK by doing the
589
1. What is a View ? Why is it required to define a View ?
A View is a database object that is a logical representation of a table. It is
derived from a table but has no storage space of its own and often may be used
in the same manner as a table.
Advantage: 1. Security 2. Complex query can be replaced.
590
A PACKAGED PROCEDURE is a built-in PL/SQL procedure that is
available in all forms. Each packaged procedure executes a SQL*FORMS
function, such as moving to a field or executing a query.
8. What is a CURSOR ?
A work area in memory where ORACLE stores the current SQL statement.
For a query , the area in memory also includes column headings and one row
retrieved by the SELECT statement.
591
11. How to write a SQL statement that should have a best RESPONSE TIME ?
Use the ___________________ in the optimizer hint inorder to obtain a
best response time. Use “FIRST_ROW” - Cost based Optimizer Hint.
Yes, Using the PL/SQL tables. PL/SQL tables are temporary array like
objects used in a PL/SQL block. PL/SQL tables can have one column and a
primary key. The column data type can belong to any scalar data type, but
the primary key must only belong to the type binary_integer.
Size - UNLIMITED.
592
17. What is ROWID ? What are its components ?
ROWID is the logical address of a row, and it is unique within the
database.The ROWID is broken into three sections: left,middle,, and right
(corresponding to 00001F20,000C, AND 0001, just shown). The numbering
is in hexadecimal notation.
The left section is the block in the file, the middle is the row sequence
number within the block(numbering starts with 0, not 1), and the right is the file
number within the database. Note that the file numbers are uniquewithin the
whole database. The tablespace they are in is not relevant to the ROWID.
Syntax: TRANSLATE(string,if,then)
TRANSLATE looks at each character in string, and then checks if to see if
that character is there, if it is, TRANSLATE notes the position in if where it found
the character, and then looks the same position in then. Whatever character it
finds there it substitutes the character in string
Eg: TRANSLATE(‘RAMESH’,’RAM’,’SUR’) - SURESH(Result)
594
28. Difference between a STORED PROCEDURE and a STORED FUNCTION ?
Unlike procedures, FUNCTIONS returns a VALUE to the caller. This value
is returned thro’ the RETURN command/keyword within the function.
Functions don’t use the IN, OUT | IN OUT arguments, which are available
for PROCEDURES.
595
33. How to know what all CONSTRAINTS are present in a table ?
Using the USER_CONSTRAINTS view we can get the type of constaints
declared on a table.
Use ALL_CONSTRAINTS to list the constraints on all of the tables that the
user have access. DBA_CONSTRAINTS lists all of the constraints in the
database.
35. What does BUFFER RECORDS option and ARRAY SIZE parameter ?
ARRAY SIZE - Specifies the minimum no. of records that get fetched each
time forms goes to the database.
BUFFER RECORDS - Specifies the minimum no of records that should be
placed in memory when records are fetched from the database. Even if you
specify a low value of 3, the minimum per form is slightly over 300.
36. During VALIDATION WHAT CHECKS are done with respective to FIELDS /
ITEMS ?
1] Data type, 2] Maximum length, 3] Fixed length, 4] Required and
5] Range Low value / Range High value.
37. What is the difference between PRIMARY KEY and UNIQUE KEY ?
The UNIQUE KEY column restricts entry of duplicate values but entry of
NULL value is allowed.
In case of PRIMARY KEY columns entry of duplicate as well as NULL
value is restricted.
596
This trigger fires, as soon as Oracle Forms determines thro’ validation that
the record should be processed by the next post or commit as an INSERT or
UPDATE
597
45. What will EXPLAIN PLAN give ?
It is an utility that shows how Oracle will access data for a given query.
Use EXPLAIN PLAN to determine the effective way to write queries and decide
whether to INDEX CERTAIN COLUMNS or TO USE CLUSTERS.
It shows :
1] The type of query processed; SELECT, INSERT,UPDATE
or DELETE.
2] The cost assigned by the COST BASED OPTIMIZER if it
is in use.
3] The steps that are necessary to return the data.
4] The internal operations that were performed for each step.
5] The object accessed for each step.
598
ROW EXCLUSIVE locks are similar to ROW SHARE but they prohibit shared
locking, so only one user user may access the table at the same time.
54. How do you analyse which resources has locked for what ?
Use MONITOR SESSION.
599
61. What is an CONCATENATED INDEX ?
A CONCATENATED INDEX is one that is created on more than one
column of a table. It can be used to guarentee that those columns are unique for
every row in the table and to speed access to rows via those columns
64. Give one example where you will use DATABASE TRIGGERS ?
For AUDITING purposes we use database triggers.
65. Do you have any idea about ROW-CHAINING ? How will you resolve the
issue if there is row-
chaining in a table ?
When a row NO LONGER FITS WITHIN THE DATABLOCK, it is stored in
more than one database block, and that therefore have several row pieces.
Resolving: Use ANALYZE to identify chained rows and also provides statistics on
the chained rows. Eg: ANALYZE ledger LIST CHAINED ROWS INTO
CHAINED_ROWS:
(CHAINED_ROWS is a user defined table)
For creating chained_rows run the UTLCHAIN.SQL script.
600
66. What is an OPTIIMIZER ?
OPTIMIZER is an utility used to determine how to access data requested
in the query by the USER or APPLICATION PROGRAM. The output of an
optimizer is EXECUTION PLAN.
69. The KEYWORD comes into the mind immediately when we talk about
security ?????? in ORACLE 7.0 ?
GRANT.
Syntax GRANT privileges( SELECT,INSERT,UPDATE,DELETE,ALTER,INDEX)
ON object TO
user WITH GRANT OPTION;
601
75. Difference between SQL and PL/SQL ?
SQL is the ANSI industry standard language, used to manipulate
information in a relational database.
PL/SQL is the procedural language extension to Oracle’s SQL language.
SQL PL/SQL
1. It is flexible, Powerful and easy to 1. PL/SQL block can contain any no. of
learn. SQL statements combined with the
following :
2. It is a non-procedural language. It a] Flow of control statements such as
a] Processes set of records rather IF..THEN, ELSE, EXIT and GOTO.
than just one at a time and b] Repetition statements such as FOR
b] Provides automatic navigation to .. LOOP and WHILE .. LOOP.
the data. c] Assignment statements such as X :=
Y+Z
3. It provides commands for avariety of
tasks including : 2. PL/SQL allows you to logically group
a] Querying data a set of statements and send them to
b] Creating,Updating and Replacing the RDBMS as a single block.
objects and Inserting, Updating
and Deleting rows. 3. Procedural capabilities.
76. How to fetch description of a code in the base table block where code is a
base table field and
the description is a non-base table field ?
Use SELECT with INTO clause to fetch the decription value into the NON-
BASE table field.
602
EQUI JOIN returns rows from both the tables provided they both have the
same column_name in the where clause. The symbol (=) represents the EQUI
JOIN.
For OUTER JOIN see previous answer.
82. Explain with example how to use a select statement with GROUP BY
HAVING clause ? (or)
Where and when is the HAVING clause used and what does it have ?
The HAVING clause is coded after the GROUP BY clause in the query
that is summarizing results by one or more grouping columns. The HAVING
clause behaves the same as
603
the WHERE clause except that it is used to specify the conditions each returned
group must satisfy. If one row in the group fails the condition of the HAVNG
clause, the entire group is not returned as part of the result.
Ex: SELECT MAX(CUSTID), REPID FROM CUSTOMER GROUP BY REPID
HAVING COUNT(*) > 2;
604
.NET Framework
1. Introduction
1.1 What is .NET?
That's difficult to sum up in a sentence. According to Microsoft, .NET is a
"revolutionary new platform, built on open Internet protocols and standards, with
tools and services that meld computing and communications in new ways".
A more practical definition would be that .NET is a new environment for developing
and running software applications, featuring ease of development of web-based
services, rich standard run-time services available to components written in a
variety of programming languages, and inter-language and inter-machine
interoperability.
Note that when the term ".NET" is used in this FAQ it refers only to the new .NET
runtime and associated technologies. This is sometimes called the ".NET
Framework". This FAQ does NOT cover any of the various other existing and new
products/technologies that Microsoft are attaching the .NET name to (e.g. SQL
Server.NET).
605
• Microsoft Visual C# .NET Standard 2003: This is a cheap (around $100) version
of Visual Studio limited to one language and also with limited wizard support.
For example, there's no wizard support for class libraries or custom UI controls.
Useful for beginners to learn with, or for savvy developers who can work around
the deficiencies in the supplied wizards. As well as C#, there are VB.NET and
C++ versions.
• Microsoft Visual Studio.NET Professional 2003: If you have a license for Visual
Studio 6.0, you can get the upgrade. You can also upgrade from VS.NET 2002
for a token $30. Visual Studio.NET includes support for all the MS languages
(C#, C++, VB.NET) and has extensive wizard support.
At the top end of the price spectrum are the Visual Studio.NET 2003 Enterprise
and Enterprise Architect editions. These offer extra features such as Visual
Sourcesafe (version control), and performance and analysis tools. Check out the
Visual Studio.NET Feature Comparison at
http://msdn.microsoft.com/vstudio/howtobuy/choosing.asp.
2. Basic terminology
2.1 What is the CLR?
CLR = Common Language Runtime. The CLR is a set of standard resources that (in
theory) any .NET program can take advantage of, regardless of programming language.
Robert Schmidt (Microsoft) lists the following CLR resources in his MSDN PDC# article:
• Object-oriented programming model (inheritance, polymorphism, exception
handling, garbage collection)
• Security model
• Type system
• All .NET base classes
• Many .NET framework classes
• Development, debugging, and profiling tools
• Execution and code management
• IL-to-native translators and optimizers
606
What this means is that in the .NET world, different programming languages will be
more equal in capability than they have ever been before, although clearly not all
languages will support all CLR services.
2.2 What is the CTS?
CTS = Common Type System. This is the range of types that the .NET runtime
understands, and therefore that .NET applications can use. However note that not
all .NET languages will support all the types in the CTS. The CTS is a superset of
the CLS.
607
2.7 What is reflection?
All .NET compilers produce metadata about the types defined in the modules they
produce. This metadata is packaged along with the module (modules in turn are
packaged together in assemblies), and can be accessed by a mechanism called
reflection. The System.Reflection namespace contains classes that can be used to
interrogate the types for a module/assembly.
Using reflection to access .NET metadata is very similar to using ITypeLib/ITypeInfo
to access type library data in COM, and it is used for similar purposes - e.g.
determining data type sizes for marshaling data across context/process/machine
boundaries.
Reflection can also be used to dynamically invoke methods (see
System.Type.InvokeMember), or even create types dynamically at run-time (see
System.Reflection.Emit.TypeBuilder).
3. Assemblies
3.1 What is an assembly?
An assembly is sometimes described as a logical .EXE or .DLL, and can be an
application (with a main entry point) or a library. An assembly consists of one or
more files (dlls, exes, html files etc), and represents a group of resources, type
definitions, and implementations of those types. An assembly may also contain
references to other assemblies. These resources, types and references are
described in a block of data called a manifest. The manifest is part of the assembly,
thus making the assembly self-describing.
An important aspect of assemblies is that they are part of the identity of a type. The
identity of a type is the assembly that houses it combined with the type name. This
means, for example, that if assembly A exports a type called T, and assembly B
exports a type called T, the .NET runtime sees these as two completely different
types. Furthermore, don't get confused between assemblies and namespaces -
namespaces are merely a hierarchical way of organising type names. To the
runtime, type names are type names, regardless of whether namespaces are used
to organise the names. It's the assembly plus the typename (regardless of whether
the type name belongs to a namespace) that uniquely indentifies a type to the
runtime.
Assemblies are also important in .NET with respect to security - many of the
security restrictions are enforced at the assembly boundary.
Finally, assemblies are the unit of versioning in .NET - more on this below.
608
3.3 What is the difference between a private assembly and a shared
assembly?
• Location and visibility: A private assembly is normally used by a single
application, and is stored in the application's directory, or a sub-directory
beneath. A shared assembly is normally stored in the global assembly cache,
which is a repository of assemblies maintained by the .NET runtime. Shared
assemblies are usually libraries of code which many applications will find useful,
e.g. the .NET framework classes.
4. Application Domains
4.1 What is an Application Domain?
An AppDomain can be thought of as a lightweight process. Multiple AppDomains
can exist inside a Win32 process. The primary purpose of the AppDomain is to
isolate an application from other applications.
Win32 processes provide isolation by having distinct memory address spaces. This
is effective, but it is expensive and doesn't scale well. The .NET runtime enforces
AppDomain isolation by keeping control over the use of memory - all memory in the
AppDomain is managed by the .NET runtime, so the runtime can ensure that
AppDomains do not access each other's memory.
609
public class CAppDomainInfo : MarshalByRefObject
{
public string GetAppDomainInfo()
{
return "AppDomain = " +
AppDomain.CurrentDomain.FriendlyName;
}
5. Garbage Collection
5.1 What is garbage collection?
Garbage collection is a system whereby a run-time component takes responsibility
for managing the lifetime of objects and the heap memory that they occupy. This
concept is not new to .NET - Java and many other languages/runtimes have used
garbage collection for some time.
5.2 Is it true that objects don't always get destroyed immediately when the
last reference goes away?
Yes. The garbage collector offers no guarantees about the time when an object will
be destroyed and its memory reclaimed.
There is an interesting thread in the archives, started by Chris Sells, about the
implications of non-deterministic destruction of objects in C#:
http://discuss.develop.com/archives/wa.exe?A2=ind0007&L=DOTNET&P
=R24819
In October 2000, Microsoft's Brian Harry posted a lengthy analysis of the problem:
http://discuss.develop.com/archives/wa.exe?A2=ind0010A&L=DOTNET&
P=R28572
Chris Sells' response to Brian's posting is here:
http://discuss.develop.com/archives/wa.exe?A2=ind0010C&L=DOTNET&
P=R983
610
5.3 Why doesn't the .NET runtime offer deterministic destruction?
Because of the garbage collection algorithm. The .NET garbage collector works by
periodically running through a list of all the objects that are currently being
referenced by an application. All the objects that it doesn't find during this search
are ready to be destroyed and the memory reclaimed. The implication of this
algorithm is that the runtime doesn't get notified immediately when the final
reference on an object goes away - it only finds out during the next sweep of the
heap.
Futhermore, this type of algorithm works best by performing the garbage collection
sweep as rarely as possible. Normally heap exhaustion is the trigger for a collection
sweep.
5.6 I've heard that Finalize methods should be avoided. Should I implement
Finalize on my class?
An object with a Finalize method is more work for the garbage collector than an
object without one. Also there are no guarantees about the order in which objects
are Finalized, so there are issues surrounding access to other objects from the
Finalize method. Finally, there is no guarantee that a Finalize method will get called
on an object, so it should never be relied upon to do clean-up of an object's
resources.
Microsoft recommend the following pattern:
public class CTest : IDisposable
{
public void Dispose()
{
... // Cleanup activities
GC.SuppressFinalize(this);
}
612
5.7 Do I have any control over the garbage collection algorithm?
A little. For example, the System.GC class exposes a Collect method - this forces
the garbage collector to collect all unreferenced objects immediately.
5.8 How can I find out what the garbage collector is doing?
Lots of interesting statistics are exported from the .NET runtime via the '.NET CLR
xxx' performance counters. Use Performance Monitor to view them.
6. Serialization
6.1 What is serialization?
Serialization is the process of converting an object into a stream of bytes.
Deserialization is the opposite process of creating an object from a stream of bytes.
Serialization/Deserialization is mostly used to transport objects (e.g. during
remoting), or to persist objects (e.g. to a file or database).
6.2 Does the .NET Framework have in-built support for serialization?
There are two separate mechanisms provided by the .NET class library -
XmlSerializer and SoapFormatter/BinaryFormatter. Microsoft uses XmlSerializer for
Web Services, and uses SoapFormatter/BinaryFormatter for remoting. Both are
available for use in your own code.
7. Attributes
7.1 What are attributes?
There are at least two types of .NET attribute. The first type I will refer to as a
metadata attribute - it allows some data to be attached to a class or method. This
data becomes part of the metadata for the class, and (like other class metadata)
can be accessed via reflection. An example of a metadata attribute is [serializable],
which can be attached to a class and means that instances of the class can be
serialized.
[serializable] public class CTest {}
The other type of attribute is a context attribute. Context attributes use a similar
syntax to metadata attributes but they are fundamentally different. Context attributes
provide an interception mechanism whereby instance activation and method calls
can be pre- and/or post-processed. If you've come across Keith Brown's universal
delegator you'll be familiar with this idea.
class CApp
{
public static void Main()
{
object[] atts =
typeof(CTest).GetCustomAttributes(true);
614
foreach( object att in atts )
if( att is InspiredByAttribute )
Console.WriteLine( "Class
CTest was inspired by {0}",
((InspiredByAttribute)att).InspiredBy );
}
}
Code Groups:
8.7 I'm having some trouble with CAS. How can I diagnose my problem?
Caspol has a couple of options that might help. First, you can ask caspol to tell you
what code group an assembly belongs to, using caspol -rsg. Similarly, you can ask
what permissions are being applied to a particular assembly using caspol -rsp.
8.8 I can't be bothered with all this CAS stuff. Can I turn it off?
Yes, as long as you are an administrator. Just run:
caspol -s off
616
9. Intermediate Language (IL)
9.1 Can I look at the IL for an assembly?
Yes. MS supply a tool called Ildasm which can be used to view the metadata and IL
for an assembly.
[
object,
uuid(EA013F93-487A-4403-86EC-FD9FEE5E6206),
helpstring("ICppName Interface"),
pointer_default(unique),
oleautomation
]
618
uuid(F5E4C61D-D93A-4295-A4B4-2453D4A4484D),
version(1.0),
helpstring("cppcomserver 1.0 Type Library")
]
library CPPCOMSERVERLib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
[
uuid(600CE6D9-5ED7-4B4D-BB49-
E8D5D5096F70),
helpstring("CppName Class")
]
coclass CppName
{
[default] interface ICppName;
};
};
When you've built the component, you should get a typelibrary. Run the TLBIMP
utility on the typelibary, like this:
tlbimp cppcomserver.tlb
If successful, you will get a message like this:
Typelib imported successfully to CPPCOMSERVERLib.dll
You now need a .NET client - let's use C#. Create a .cs file containing the following
code:
using System;
using CPPCOMSERVERLib;
619
can be developed. Also, for COM to 'see' the .NET component, the .NET component
must be registered in the registry.
Here's a simple example. Create a C# file called testcomserver.cs and put the
following in it:
using System;
namespace AndyMc
{
[ClassInterface(ClassInterfaceType.AutoDual)]
public class CSharpCOMServer
{
public CSharpCOMServer() {}
public void SetName( string name )
{ m_name = name; }
public string GetName() { return
m_name; }
private string m_name;
}
}
Then compile the .cs file as follows:
csc /target:library testcomserver.cs
You should get a dll, which you register like this:
regasm testcomserver.dll /tlb:testcomserver.tlb
/codebase
Now you need to create a client to test your .NET COM component. VBScript will do
- put the following in a file called comclient.vbs:
Dim dotNetObj
Set dotNetObj = CreateObject("AndyMc.CSharpCOMServer")
dotNetObj.SetName ("bob")
MsgBox "Name is " & dotNetObj.GetName()
and run the script like this:
wscript comclient.vbs
And hey presto you should get a message box displayed with the text "Name is
bob".
An alternative to the approach above it to use the dm.net moniker developed by
Jason Whittington and Don Box. Go to
http://staff.develop.com/jasonw/clr/readme.htm to check it out.
11. Miscellaneous
11.1 How does .NET remoting work?
.NET remoting involves sending messages along channels. Two of the standard
channels are HTTP and TCP. TCP is intended for LANs only - HTTP can be used for
LANs or WANs (internet).
Support is provided for multiple message serializarion formats. Examples are SOAP
(XML-based) and binary. By default, the HTTP channel uses SOAP (via the .NET
runtime Serialization SOAP Formatter), and the TCP channel uses binary (via the
620
.NET runtime Serialization Binary Formatter). But either channel can use either
serialization format.
There are a number of styles of remote access:
• SingleCall. Each incoming request from a client is serviced by a new object.
The object is thrown away when the request has finished.
• Singleton. All incoming requests from clients are processed by a single server
object.
• Client-activated object. This is the old stateful (D)COM model whereby the
client receives a reference to the remote object and holds that reference (thus
keeping the remote object alive) until it is finished with it.
Distributed garbage collection of objects is managed by a system called 'leased
based lifetime'. Each object has a lease time, and when that time expires the object
is disconnected from the .NET runtime remoting infrastructure. Objects have a
default renew time - the lease is renewed when a successful call is made from the
client to the object. The client can also explicitly renew the lease.
If you're interested in using XML-RPC as an alternative to SOAP, take a look at
Charles Cook's XML-RPC.Net site at
http://www.cookcomputing.com/xmlrpc/xmlrpc.shtml.
11.2 How can I get at the Win32 API from a .NET program?
Use P/Invoke. This uses similar technology to COM Interop, but is used to access
static DLL entry points instead of COM objects. Here is an example of C# calling the
Win32 MessageBox function:
using System;
using System.Runtime.InteropServices;
class MainApp
{
[DllImport("user32.dll", EntryPoint="MessageBox",
SetLastError=true, CharSet=CharSet.Auto)]
public static extern int MessageBox(int hWnd,
String strMessage, String strCaption, uint uiType);
621
12. Class Library
12.1 File I/O
Similar to text files, except wrap the FileStream object with a BinaryReader/Writer
object instead of a StreamReader/Writer object.
12.2 Text Processing
622
12.3 Internet
while( reader.Read() )
{
if( reader.NodeType == XmlNodeType.Element &&
reader.Name == "PERSON" )
{
reader.Read(); // Skip to the child text
Console.WriteLine( reader.Value );
}
}
Yes, there is extensive support for multi-threading. New threads can be spawned,
and there is a system-provided threadpool which applications can use.
624
m_thread = new Thread( new
ThreadStart(ThreadMain) );
m_thread.Start();
}
There are several options. First, you can use your own communication mechanism
to tell the ThreadStart method to finish. Alternatively the Thread class has in-built
support for instructing the thread to stop. The two principle methods are
Thread.Interrupt() and Thread.Abort(). The former will cause a
ThreadInterruptedException to be thrown on the thread when it next goes into a
WaitJoinSleep state. In other words, Thread.Interrupt is a polite way of asking the
thread to stop when it is no longer doing any useful work. In contrast, Thread.Abort()
throws a ThreadAbortException regardless of what the thread is doing.
Furthermore, the ThreadAbortException cannot normally be caught (though the
ThreadStart's finally method will be executed). Thread.Abort() is a heavy-handed
mechanism which should not normally be required.
12.5.5 How do I know when my thread pool work item has completed?
There is no way to query the thread pool for this information. You must put code into
the WaitCallback method to signal that it has completed. Events are useful for this.
Each object has a concurrency lock (critical section) associated with it. The
System.Threading.Monitor.Enter/Exit methods are used to acquire and release this
lock. For example, instances of the following class only allow one thread at a time to
enter method f():
class C
{
public void f()
{
try
{
Monitor.Enter(this);
...
}
finally
{
Monitor.Exit(this);
}
}
}
C# has a 'lock' keyword which provides a convenient shorthand for the code above:
class C
{
public void f()
{
lock(this)
{
...
}
}
}
Note that calling Monitor.Enter(myObject) does NOT mean that all access to
myObject is serialized. It means that the synchronisation lock associated with
myObject has been acquired, and no other thread can acquire that lock until
Monitor.Exit(o) is called. In other words, this class is functionally equivalent to the
classes above:
626
class C
{
public void f()
{
lock( m_object )
{
...
}
}
Yes, in the System.Diagnostics namespace. There are two main classes that deal
with tracing - Debug and Trace. They both work in a similar way - the difference is
that tracing from the Debug class only works in builds that have the DEBUG symbol
defined, whereas tracing from the Trace class only works in builds that have the
TRACE symbol defined. Typically this means that you should use
System.Diagnostics.Trace.WriteLine for tracing that you want to work in debug and
release builds, and System.Diagnostics.Debug.WriteLine for tracing that you want to
work only in debug builds.
Yes. The Debug and Trace classes both have a Listeners property, which is a
collection of sinks that receive the tracing that you send via Debug.WriteLine and
Trace.WriteLine respectively. By default the Listeners collection contains a single
sink, which is an instance of the DefaultTraceListener class. This sends output to
the Win32 OutputDebugString() function and also the
System.Diagnostics.Debugger.Log() method. This is useful when debugging, but if
you're trying to trace a problem at a customer site, redirecting the output to a file is
more appropriate. Fortunately, the TextWriterTraceListener class is provided for this
purpose.
Here's how to use the TextWriterTraceListener class to redirect Trace output to a
file:
Trace.Listeners.Clear();
FileStream fs = new FileStream( @"c:\log.txt",
FileMode.Create, FileAccess.Write );
Trace.Listeners.Add( new TextWriterTraceListener( fs
) );
627
12.6.3 Can I customise the trace output?
Yes. You can write your own TraceListener-derived class, and direct all output
through it. Here's a simple example, which derives from TextWriterTraceListener
(and therefore has in-built support for writing to files, as shown above) and adds
timing information and the thread ID for each trace line:
class MyListener : TextWriterTraceListener
{
public MyListener( Stream s ) : base(s)
{
}
13.3 Weblogs
The following Weblogs ('blogs') have regular .NET content:
• The .NET Guy (Brad Wilson)
• Charles Cook: Developer of XML-RPC.NET.
• Gwyn Cole: Co-author of Developing WMI solutions.
• Chris Brumme
• Brad Abrams
• Don Box
• John Lam
• Peter Drayton: Co-author of C# Essentials and C# in a Nutshell.
• Ingo Rammer: Author of Advanced .NET remoting.
• Drew Marsh
• Tomas Restrepo
• Justin Rudd
• Simon Fell: Developer of PocketSOAP.
• Richard Caetano
629
• sellsbrothers.com: Windows Developer News: Not really a blog, but includes
regular .NET-related news.
13.4 Sample code & utilities
Lutz Roeder has some great utilities and libraries at
http://www.aisto.com/roeder/dotnet/
Peter Drayton's .NET Goodies page is at http://www.razorsoft.net/
Don Box & Jason Whittington's dm.net COM moniker at
http://staff.develop.com/jasonw/clr/readme.htm
Mike Woodring has some .NET samples at
http://staff.develop.com/woodring/dotnet/
Charles Cook's XML-RPC.Net library is available at
http://www.cookcomputing.com/.
630
Interview Tips
Before you take up the interview
• Read your updated bio-data line by line like you review a document or review a
piece of code. The onsite team might have reformatted your bio-data to showcase
your strengths with respect to the position you will be slotted at. Hence ask the onsite
team to send a copy of the bio-data that has been given to the client
• Talk to the onsite team before you take the interview. They will be in a position to brief
you about the position that you will slotted in and your role and responsibilities
• Know the names of the person(s) who will be interviewing you. Also, if you are not
clear about the pronunciation, ask the onsite team for the same. It is important that
you greet the interviewer(s) using their first names like “Good Morning Tom” or “Hi
Michael”.
• Talk about your undergraduate and post-graduate degrees. Explain in brief the
stream of your specialization (like graduate in Electrical Engineering and post
graduation in Computer Science)
• Say when you joined TCS and how long you are associated with TCS. If you have
prior work experience, then mention about TCS first and then about your prior work
experience
Next, the interviewers might ask you describe the projects you have worked on.
• You need to have the bio-data with you. Go through each of the projects in the same
sequence as in your bio-data. Explain in brief the following about each of the
projects. (Some sample replies are also given for reference).
• The application
631
• The technical architecture
“Client platform – Windows NT, Middle tier and Database tier – “Sun Solaris”
etc.
Roles Responsibilities
Team Member Coding, preparing test specs, Testing (development)
Apply fixes, test fixes (maintenance)
632
Roles Responsibilities
Module Leader Preparing Design documents (High and Low level design)
Planning with respect to the module
Review of deliverables
Ensuring Quality related activities with respect to the module or
completed before the delivery
Any other tasks done by you as a Module leader
Lead Analyst Gathering user requirements
Performing analysis of user requirements
Design of application and technical architecture
Data/ Process/ Object Modeling etc
Any other tasks done by you as a analyst
Project Leader Project planning
Resource allocation to the modules
Project Monitoring
Status reporting to the clients and TCS management
Review
Configuration Management
Quality related activities with respect to the project
Writing proposals etc
Production Support Analyzing bugs
Applying fixes
Testing the fix
Regression Testing
Maintenance and Analyzing bugs and enhancements
Enhancement Support Applying fixes and enhancements
Testing the fixes and enhancements
Regression Testing
Please note that the responsibilities are not cast in stone. You might have assumed more
responsibilities in a particular role. For example, as a module leader, you might have been part of
the requirements gathering team. If such is the case, then make it a point to mention it.
• Be aware of the QMS processes of TCS and those followed in your project. Explain
in brief about the process being asked about. Do not talk about the whole QMS
processes
“Code, Code review, Code rework, Test, Test Results review”, etc. The whole
thing is about Do Review Rework Do …
633
Other Questions
• Most of the interviews will be along the above lines. However, some times the
interviewer might ask some technical questions on the topic of your expertise, so be
prepared for the same. Please be brief and to the point in your replies to these
questions.
Are you aware of the differences between Java and Java Script”
“Quick learner”,
• There might questions on how you keep yourself updated of changes in technology
• Also, they might ask for your opinion on various topics like which is better
Finally
• The interviewer might ask you if you have any questions or you would like to know
anything. It is better to answer “No thanks, the Onsite person/ team has already
briefed me”. In case the onsite person/ team was not able to reply to your roles and
responsibilities, then you may ask the interviewer for the same
634
Whether you will get a vacation if you are going long-term
Any other questions that are related to TCS’ HR procedures and policies
Please note that the BRM or the Onsite person/ Team can answer all questions related to
TCS and hence please put such questions to these people before the scheduled interview.
Do and Don’ts
• Do’s
Talk to the onsite person/ Team or BRM before the scheduled interview
Be brief in your replies. Explain in detail only when the interviewer asks you
to elaborate it.
If you do not able to hear a question, say “Sorry, can you please repeat the
question again” or “Beg you pardon, could you repeat the question again
please”
• Don’ts
Avoid Indian words “Accha, Teek Hai, Lekin, Han Han...” etc
Avoid use of the same words to confirm that you have understood what has
been asked, like “Yes, yes, yes, yes, …” or “Yeah, Yeah, Yeah, …”
After you have answered a question if the interviewer pauses and does not
ask the next question then wait for the next question. Do not keep talking.
Remember the questions that you should not be asking the interviewer (i.e.
the questions under the bullet “Finally”)
“Be Brief and do not answer or say anything that has not been asked for”
635