Question Bank
Question Bank
Question Bank
30 C & Data
Structures
25 C++ & OOP
Concepts
20 Databases
15
Operating
10 Systems
Java
5
Networking
0
Order of Importance
Other Topics
C & Data Structures
20 0x100
35 0x780
60 NULL
The example above shows a linear linked list with 3 nodes. Each node
in the linked list contains a data member and a pointer member. As we
can see from the diagram the pointer member of the first node
contains the address of the second (next) node. Similarly the pointer
member of the second node contains the address of the third (next)
node. There are no more nodes and hence the pointer member of the
third (last) node in the list is NULL. All you need to know is the starting
address of the first node in the linked list. You can traverse all the
other nodes easily by following the pointer links.
p = &number;
q = &p;
number p q
You can now create the executable with the following command
$ cc –o result program.o /* This creates the executable result */
$ ./result /* We are now running the executable result */
#include <stdio.h>
int main( )
{
printf ( “\n *\n”);
printf ( “ * *\n”);
printf ( “ * * *\n”);
printf ( “ * * * *\n”);
printf ( “ * * * * *\n”);
}
9. Compare and contrast iteration Vs recursion
10. Things to keep in mind when you are posed with a coding
question
For code questions you will be given sufficient time to think and
write the code. Don’t be in a hurry to immediately start righting
the code. Think for sometime as to how you are going to
implement. First list out the steps of the algorithm that you are
going to implement. Then think about the boundary conditions
that you need to take care. This will let the interviewer know that
you are working methodically. Once you are clear with the steps
for implementing the algorithm writing the code is straight
forward task. Also documentation is an important process when
you write code. Even in your interview ensure that you place
some comment statements explaining the code statements. If
there is paucity of time then you may ask the interviewer if you
can skip the comment statements. Sometimes they themselves
may advice you that you can just explain and there is no need
for the comment statements. Follow your interviewer’s
instructions carefully in any case.
Let us answer this question with the help of a table. Again the
question can come in different forms so you need to have a
proper understanding of the table to answer the question.
Steps
if ( str == NULL )
{
printf ( “The string parameter is null\n” );
return 0;
}
/* Traverse the string in a loop */
14. Can you improvise upon the basic algorithm (where you will
be checking from 2 upto square root of the number) for
finding a prime number ?
int main()
{
int i,k,l,irt;
char chk;
do
{
system(“clear”);
printf("enter the number : ");
scanf("%d",&i);
system(“clear”);
irt=sqrt(i)+1;
k=i%2;
if (k==0)
{
printf("\n%d is not a prime",i);
printf("\n\n 2 is the first factor");
}
else
for(l=3;l<irt;l+=2)
{
k=i%l;
if(k==0)
{
printf("\n%d is not a prime",i);
printf("\n\n%d is the firstfactor",l);
break;
}
}
#include <stdio.h>
#include <math.h>
int main()
{
int i,k,l,irt,m,count;
system("clear");
printf("Determine prime numbers upto : ");
scanf("%d",&m);
system("clear");
count=0;
for(i=2;i<m;i++)
{
k=i%2;
if (k!=0)
{
irt=sqrt(i)+1;
for(l=3;l<irt;l+=2)
{
k=i%l;
if(k==0)break;
}
}
if (k!=0)
{
printf("%d\t",i);
count++;
if ((count%100)==0)printf("\n\n");
}
}
printf("\n total number of prime numbers : %d ",count);
}
#include <stdio.h>
#include <math.h>
int main()
{
int i,k,l,irt,fact;
system("clear");
printf("enter the number : ");
scanf("%d",&i);
system("clear");
printf(" The factors of %d are: \n", i);
irt=sqrt(i)+1;
for(l=1;l<irt;l++)
{
k=i%l;
if(k==0)
{
fact=i/l;
printf("\n%d \t%d ",l,fact);
}
}
return 0;
}
17. Implement the recursive version of the Fibonacci series
if (n == 0)
return 0;
if (n == 1)
return 1;
#include <stdio.h>
int main( )
{
int x,y, z;
x=2;
y=5;
z= x+++y;
printf("%d %d %d", x, y z);
return 0;
}
3 5 7
22. What is the output of the following code snippet ? Show the stack
contents during the execution.
#include <stdio.h>
int giValue = 5;
void fnReverse()
{
if (giValue > 0) {
giValue--;
fnReverse();
}
printf("%d\t", giValue);
}
int main()
{
fnReverse();
return 0;
}
Since there are no local variables and function parameters there will
be nothing in the stack except the return address. giValue is a
global variables and hence it will be defined in the data segment
and not in the stack. Since each time we call fnReverse we are
decrementing the global variable giValue when we finally print the
value of giValue the output will be :
One
24. The char has 1 byte boundary , short has 2 byte boundary,
int has 4 byte boundary. What is the total no. of bytes consumed
by the following structure:
struct st {
char a;
char b;
short c;
int z[2];
char d;
short f;
int q;
};
If you add all the bytes as per the data types in the structure
then the total number of bytes consumed by the structure will be
1 + 1 + 2 + 2 * 4 + 1 + 2 + 4= 19 bytes
a b c
z[0]
z[1]
d f
#include <stdio.h>
#define swap(a,b) temp=a; a=b; b=temp;
int main( )
{
int i, j, temp;
i=5;
j=10;
temp=0;
if( i & j)
swap( i, j );
printf( "%d %d %d", i, j, temp);
}
The output is : 10 0 0
#include <stdio.h>
int main()
{
int i=3;
while(i>=0)
printf("%d",i--);
return(0);
}
int main()
{
int s[]={1,2,3,4,5,6};
printf("%d",&s[5]-&s[0]);
return 0;
}
8 &s[5] = 20
&s[0] = 0
12
&s[5] - &s[0] = 20 – 0 = 20
16
20
28. What is the task of the C preprocessor ?
Convert 10 to Binary
2 10
2 5 0
2 2 1
0
1
Convert 50 to hexadecimal
16 50
3 2
0x32 is the hexadecimal equivalent of decimal 50
0*2^0+1*2^1+0*2^2+1*2^3=0+2+0+8=
10
2 * 16 ^ 0 + 3 * 16 ^ 1 = 2 + 48 = 50
or simply
funcptr ();
#include <stdio.h>
int main()
{
int ivalue = 5;
fnReverse(ivalue);
return 0;
}
35. What is a sparse file ?
$ ls -l sparse.file
$ du -h sparse.file
8K sparse.file
36. In the Linked list shown below how can I delete node C
while I provide only the starting address of node C ?
A B C D
STACK
( Function parameters & Local Variable)
TEXT
( Contains the program code )
/* file1.c */
/* file2.c */
41. What is the difference between const char *p, char const
*p, const char * const p ?
char * const p
43. What is the most efficient way to count the bits that are set
in a value ?
#include <stdio.h>
#include <errno.h>
#include <string.h>
int main()
{
FILE *fp;
char c, *p;
int count = 0;
char buffer[1000];
fp = fopen("file1", "r");
if ( fp == NULL )
{
printf("\n File could not be opened in read mode");
exit(1);
}
c = fgetc(fp);
while ( c != EOF )
{
buffer[count++] = c;
c = fgetc(fp);
}
buffer[count] = '\0';
p = strtok(buffer, ",");
while ( p != NULL )
{
printf("\n The string is %s", p);
p = strtok(NULL, ",");
}
return 0;
}
int main()
{
int A[NUM_ROWS][NUM_COLS] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int B[NUM_ROWS][NUM_COLS] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 };
int C[NUM_ROWS][NUM_COLS] = { 0 };
int i, j;
printf("\n");
matrix_multiply(A,B,C);
for ( i = 0; i < NUM_ROWS; i++ )
{
for ( j = 0; j < NUM_COLS; j++ )
{
printf("A[%d][%d] = %d\t", i, j, C[i][j]);
}
printf("\n");
}
printf("\n");
return 0;
}
For e.g., strlen, strcpy, strcmp, toupper, fopen etc. are library
functions
System calls on the other hand are the means available for the
programmer to interact with the operating system which in turn
talks to the hardware and get things done. The open system call
is a good example. It helps in opening an existing file and can
even create one if there is no such file. Thus we can specify
various attributes in the open system call for various
functionality. Ultimately it opens a file stored in the disk by
interacting with the hardware through the operating system.
For e.g., open, read, write, fork etc. are system calls
Also there is global variable called errno which gets set to a pre-
defined number (depending on the failure). After the system call
is executed we can examine this global variable errno and also
print the string corresponding to the value contained in errno
variable. To illustrate the mechanism of how to use errno to
know if the system call is successful (or) not we provide a small
program below.
#include <stdio.h>
#include <errno.h>
#include <string.h>
extern int errno;
int main()
{
FILE *fp;
char c, *p;
int count = 0;
char buffer[1000];
We are using the library function which in turn uses the system
call open. When we did not have a file by name “file1” in the
current directory this is the output from the program.
********************************************************
$ ./a.out
48. Suppose you have a doubly linked list in which a singly linked list
is embedded what will be the issues ?
A B C D
Here the problem is the doubly linked list is broken in the reverse
direction. We can traverse all the way to the last node in the
forward direction but not in the reverse. Again insertion between
Nodes B & C means that we have to have a pointer save the
previous node address. Deletion of nodes B, C have to be handled in
a special manner.
50. How will you find if a number is even or odd in just one
statement ( without using if statement )
#include <stdio.h>
int main()
{
int a, b, temp;
b = ( a = 20, a + 10 );
printf(“a = %d and b = %d (before)\n”, a ,b );
temp = a, a = b, b = temp;
printf(“a = %d and b = %d (after)\n”, a ,b );
return 0;
}
#include <stdio.h>
int main()
{
int a= 10, b = 2, c = 15;
a = a && b || c;
b = a ||b && c;
c = a && b && c;
printf(“%d %d %d”, a, b, c );
}
1 1 1
Examination of character (
Examination of character a
Examination of character +
Examination of character b
Examination of character )
Examination of character *
It is an operator and stack is empty. So push it into the stack
*
Examination of character c
Output the character
Output Postfix Expression = ab+c
There is no change in the stack contents
Examination of character /
Now there is already an operator * at the top of the stack.
Since / has equal priority to * we have to pop out * on to the
output expression and then push / into the stack
Now the output postfix expression = ab+c*
And the stack status is shown below
Examination of character d
Output the character
Output Postfix Expression = ab+c*d
There is no change in the stack contents
Examination of character -
Now there is already an operator / at the top of the stack.
Since – has lower priority to / we have to pop out / on to the
output expression and then push - into the stack
Now the output postfix expression = ab+c*d/
And the stack status is shown below
__
Examination of character e
Output the character
Output Postfix Expression = ab+c*d/e
There is no change in the stack contents
Examination of character +
Now there is already an operator - at the top of the stack.
Since – has equal priority to + we have to pop out - on to the
output expression and then push + into the stack
Now the output postfix expression = ab+c*d/e-
And the stack status is shown below
Examination of character f
Output the character
Output Postfix Expression = ab+c*d/e-f
There is no change in the stack contents
Examination of character /
Now there is already an operator + at the top of the stack.
Since / has greater priority than + we have to push / onto the
stack
Now the output postfix expression = ab+c*d/e-f
And the stack status is shown below
Examination of character (
Push it into stack
And the stack status is shown below
Examination of character g
Output the character
Output Postfix Expression = ab+c*d/e-fg
There is no change in the stack contents
Examination of character -
Push it into the stack. All operators till we come across the
right parenthesis will be pushed into the stack
Output Postfix Expression = ab+c*d/e-fg
And the stack status is shown below
_
Examination of character h
Output the character
Output Postfix Expression = ab+c*d/e-fgh
There is no change in the stack contents
Examination of character )
Examination of character *
Now there is already an operator / at the top of the stack.
Since * has equal priority to / we have to pop out / on to the
output expression and then push * into the stack
Output postfix expression = ab+c*d/e-fgh-/
And the stack status is shown below
+
Examination of character k
Output the character
Output Postfix Expression = ab+c*d/e-fgh-/k
There is no change in the stack contents
union unode
{
char c;
int i;
};
int main()
{
struct node node1;
union unode u;
printf("\n %d \t %d", sizeof(struct node), sizeof(node1));
printf("\n %d \t %d", sizeof(union unode), sizeof(u));
u.c = 'A';
printf("\n %c \t %d", u.c, u.i);
u.i = 65;
printf("\n %d \t %c\n", u.i, u.c);
return 0;
}
The output is :
20 20
4 4
A <undefined value>
65 A
Since the fields of the union are int and char the size will be
allocated
to hold the biggest (int) and hence the size of the union is 4 bytes.
When we assign the value ‘A’ to u.c only the LSB will be assigned
with the ascii value for A (65). We don’t know what will be there in
the other 3 bytes. Hence we have specified as undefined value. On
the other hand when we assign the value 65 to u.i the entire 4 bytes
gets initialized as follows : Hex (values) => 00 00 00 41 => 65
(Decimal). When we read it as a character it reads only the LSB byte
which is 65. This should explain why we get a proper value when we
assign an integer but not when we assign a character.
56. How would you figure out if your machine is Big Endian or
Little Endian ?
0 0x01
1 0x02
2 0x03
3 0x04
From the memory map we can figure out how the bytes will be
interpreted for Little Endian and Big Endian.
For little endian the LSB will correspond to the lowest address and it
will proceed in that order. So we interpret the value of the integer in
hex as 0x04030201
For big endian the lowest address will correspond to the MSB and so
on. Hence the value will be interpreted as 0x01020304
int main()
{
int *p;
char buffer[4] = { 0x01, 0x02, 0x03, 0x04 };
p = (int *) buffer;
As we can see when we print the value of p in hex the LSB is the
littlest. Had our computer been Big Endian then p in hex will be
1020304
#include <stdio.h>
#include <string.h>
#define SIZE 80
len1 = strlen(string1);
len2 = strlen(string2);
len = (len1<len2)?len1:len2;
for ( i=0; i<len; i++ )
{
if ( string1[i] > string2[i] )
return 1;
else if ( string1[i] < string2[i] )
return -1;
else
continue;
}
if ( len1 == len2 )
return 0;
else if ( len1 > len2 )
return 1;
else
return -1;
}
int main()
{
int result;
char string1[SIZE];
char string2[SIZE];
printf("\n Enter string 1 :");
scanf("%s", string1);
printf("\n Enter string 2 :");
scanf("%s", string2);
result = strcmp(string1, string2);
if ( result == 0 )
printf("\nBoth the strings are equal.");
else if ( result == 1 )
printf("\n String1 %s is greater than String2 %s",
string1, string2);
else
printf("\n String1 %s is lesser than String2 %s",
string1, string2);
return 0;
}
Step 1
Null Null
Step 2
25
25
Null 90
Null 90
Null Null
Null Null
Step 3
25
Null 90
28 Null
Step 4
25
90
12
28 Null
Step 5
25
The final shape of the tree after all the insertions will be
90
12
10
11 15 28 0
61. Write a program that accepts user input and creates the
nodes in a binary search tree
struct bsearchtreenode
{
int data;
struct bsearchtreenode *left;
struct bsearchtreenode *right;
};
int main()
{
int value;
BSTNodeptr root = NULL;
printf("\n Enter value of node to insert in BST (-1 to end) :
");
scanf("%d", &value);
while ( value != -1 )
{
insert(&root, value);
printf("\n Enter value of node to insert in BST (-1 to
end) : ");
scanf("%d", &value);
}
inorder_traversal(root);
return 0;
}
struct node
{
int data;
struct node *next;
};
$ gdb ./a.out
GNU gdb Red Hat Linux (6.5-16.el5rh)
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General
Public License, and you are
welcome to change it and/or distribute copies of it under
certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show
warranty" for details.
This GDB was configured as "i386-redhat-linux-
gnu"...Using host libthread_db library
"/lib/libthread_db.so.1".
(gdb)
(gdb)run
Starting program:
/home/staff/aitec/cir/v_bhaskaran/cprgms/a.out
(gdb) p root
( We are trying to see if root has been assigned the null
value )
(gdb) backtrace
#0 insert (root=0xbfc5ddac, value=25) at samp56.c:17
#1 0x08048523 in main () at samp56.c:77
(gdb)
10. Once you are done you can quit the debugger by
typing quit at the gdb prompt
(gdb) quit
The program is running. Exit anyway? (y or n) y
$
a = a ^ b;
b = b ^ a;
a = a ^ b;
static struct {
unsigned a:5;
unsigned b:5;
unsigned c:5;
unsigned d:5;
unsigned e:5;
unsigned f:5;
unsigned g:5;
unsigned h:5;
unsigned i:5;
} v = { 1, 2, 3, 4, 5, 6, 7, 63, 9 };
static struct {
unsigned a:5;
unsigned b:5;
unsigned c:5;
unsigned d:5;
unsigned e:5;
unsigned f:5;
unsigned g:5;
unsigned :0;
unsigned i:5;
} v = { 1, 2, 3, 4, 5, 6, 7, 8 };
68. Write a program, that accepts a integer from the user and
print the integer with reverse digits. For eg: rev(1234) = 4321
Example
A
B D
C
E F
83. Assume I have a linked list containing all of the alphabets from
“A” to “Z”. I want to find the letter “Q” in the list. How do you
perform the search to find “Q” ?
84. Given two strings like x=”hello” and y=”open”, remove any
character from string x which is also used in string y, thus
making the result x=”hll”.
int (*x)[10];
• Bubble Sort
• Selection Sort
• Insertion Sort
int fn (int v)
{
if(v==1 || v==0) return 1;
if(v%2==0) return fn(v/2)+2;
else return fn(v-1)+3;
}
void main()
{
int x=5;
printf(“%d,%d,%dn”,x,x< <2,x>>2);
}
void main()
{
int x=5, y=10;
swap (x,y);
printf(“%d %dn”,x,y);
swap2(x,y);
printf(“%d %dn”,x,y);
}
main()
{
char *ptr = ” Cisco Systems”;
*ptr++; printf(“%s\n”,ptr);
ptr++;
printf(“%s\n”,ptr);
}
main()
{
char *p1=“name”;
char *p2;
p2=(char*)malloc(20);
memset (p2, 0, 20);
while(*p2++ = *p1++);
printf(“%s\n”,p2);
}
int x;
int modifyvalue()
{
return(x+=10);
}
int changevalue(int x)
{
return(x+=1);
}
void main()
{
int x=10;
x++;
changevalue(x);
x++;
modifyvalue( );
printf("First output : %d\n",x);
x++;
changevalue(x);
printf("Second output : %d\n",x);
modifyvalue( );
printf("Third output: %d\n",x);
}
104. Which uses less memory ? and why ?
105. What are the techniques you will be using for debugging ?
110. How will find out if a given number is even or odd without
using the conditional operator ?
void main()
{
float a= 0.7;
if (a < 0.7)
printf("c");
else
printf("c++");
}
void main()
{
float a= 0.8;
if (a < 0.8)
printf("c");
else
printf("c++");
}
For the first program it prints “c” as the output but for the
second program it prints “c++” as the output. Why is it
so ?
#include <stdio.h>
#define SQR(X) X * X
int main()
{
float y;
y = 225.0/SQR(15);
printf(“\n The value of y = %f”, y );
}
memcpy ?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char *s;
s=(char *) malloc (100);
s="hello";
free(s);
printf("Program to illustrate memory allocation and
deallocation\n");
return 0;
}
Segmentation fault
#include <stdio.h>
enum {false,true};
int main()
{
int i=1;
do
{
printf("%d\n",i);
i++;
if(i < 15)
continue;
}while(false);
return 0;
}
#include <stdio.h>
int main()
{
int cnt = 5, a = 100;
do
{
printf ("a = %d count = %d\n", a, cnt);
a = a/cnt;
} while (cnt --);
return 0;
}
a = 100 count = 5
a = 20 count = 4
a = 5 count = 3
a = 1 count = 2
a = 0 count = 1
a = 0 count = 0
Floating point exception
( Floating point exception is due to division by 0 error )
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
char *string1;
const char string2[20] = "Amrita University";
/* Usage of strcpy */
free(string1);
/* Usage of strdup */
string1 = strdup(string2);
printf("\nstring1 = %s", string1);
printf("\nstring2 = %s\n", string2);
free(string1);
return 0;
}
struct sample
{
char a;
int b;
short c;
char d;
};
a
b
c d
a d c
b
130. I have the following situation. I need to compile code
depending on the environment. if it is Unix environment I
will
compile some code. If it is Windows then I would like to
compile some other piece of code. How can we achieve this
?
#define Unix_Platform
#ifdef ( Unix_Platform )
/* statements to be compiled for Unix */
#else
/* statements to be compiled for WINDOWS */
#endif
int main()
{
int i = 3;
int *j;
int **k;
j = &i;
k = &j;
a) Address, 3, 3
b) Address, Address, 3
c) 3, 3, 3
d) Compiler Error
e) None of the above
Address, Address, 3
#include <stdio.h>
#include <string.h>
int main()
{
int a,b,c,d;
char *p=0;
int *q=0;
float *r=0;
double *s=0;
a=(int)(p+1);
b=(int)(q+1);
c=(int)(r+1);
d=(int)(s+1);
printf("%d %d %d %d",a,b,c,d);
return 0;
}
a) Compiler Error
b) 1, 1, 1, 1
c) 1, 2, 2, 4
d) 1, 4, 4, 8
e) None of the above
1448
#include <stdio.h>
#include <string.h>
int main()
{
char *ptr1=NULL;
char *ptr2=0;
strcpy(ptr1,"c");
strcpy(ptr2,"questions");
printf("\n%s %s",ptr1,ptr2);
return 0;
}
a)c questions
b)c (null)
c)(null) (null)
d)Compiler Error
e)None of the above
#include <stdio.h>
#include <string.h>
int main()
{
register int a=25;
int *p;
p=&a;
printf("%d ",*p);
return 0;
}
a) Segmentation Fault
b) Linker Error
c) Compiler Error
d) 25
e) None of the above
#include <stdio.h>
#define x 5+2
int main()
{
int i;
i=x*x*x;
printf("%d",i);
return 0;
}
a) Compiler Error
b) 27
c) 343
d) 133
e) None of the above
#define x (5+2)
#include <stdio.h>
int main()
{
int i=4,x;
x=i++ + i++ + i++;
#include <stdio.h>
int main()
{
int i=5,j=2;
if(++i>j++||i++>j++)
printf("%d",i+j);
return 0;
}
a) 7
b) 11
c) 8
d) 9
e) Compiler Error
9 ( Self explanatory )
#include <stdio.h>
int main()
{
char str[250];
scanf("%[^\n]",str);
printf("%s",str);
return 0;
}
a) Segmentation Fault
b) Compiler Error
c) It accepts only the new line character
d) It accepts all characters except the newline
e) It accepts all characters except blanks, tabs and newline
#include <stdio.h>
int main()
{
char str[250];
scanf("%s",str);
printf("%s",str);
return 0;
}
#include <stdio.h>
void main()
{
int a[2][4]={3,6,9,12,15,18,21,24};
printf("%d %d %d",*(a[1]+2),*(*(a+1)+2),2[1[a]]);
return 0;
}
21 21 21
The pointers in the program make it look scary. Also it is a bit more
complicated since it involves 2 dimensional arrays. The memory order
for 2 dimensional arrays looks like
A[0][0]
A[0][1]
A[0][2]
A[0][3]
A[1][0]
A[1][1]
A[1][2]
A[1][3]
#include <stdio.h>
void main()
{
enum color{
RED,GREEN=-20,BLUE,YELLOW
};
enum color x;
x=YELLOW;
printf("%d",x);
x=RED;
printf("\t%d",x);
return 0;
}
-18 0
( Enumeration constants normally start from 0. But once
we provide a default all subsequent values will be based on
the default )
int main()
{
const int x=25;
int * const p=&x;
*p=2*x;
printf("%d",x);
}
a) 25
b) 0
c) Compiler Error
d) 50
e) None of the above
void main()
{
int i=11;
int const * p=&i;
p++;
printf("%d",*p);
}
a) 11
b) 12
c) Compiler Error
d) Garbage Value
e) None of the above
200 11
int main()
{
int a=15,b=10,c=0;
if( a>b>c )
printf("True");
else
printf("False");
}
#include <stdio.h>
struct marks
{
int p:3;
int c:3;
int m:2;
};
int main()
{
struct marks s={2,-6,5};
printf("%d %d %d",s.p,s.c,s.m);
return 0;
}
a) 2 -6 1
b) Compiler Error
c) Segmentation Fault
d) 2 2 1
e) None of the above
#include <stdio.h>
#include <string.h>
int main()
{
printf("%d %d",sizeof("string"),strlen("string"));
return 0;
}
7 6
sizeof will also take into account the null character (‘\0’)
where as strlen will only account for the actual number of
characters in the string
#include <stdio.h>
int main()
{
int a = -12;
a = a >> 3;
printf("%d", a);
return 0;
}
-2
#include <stdio.h>
#define aaa char *
typedef char * bbb;
int main()
{
bbb a, b;
aaa c, d;
return 0;
}
#include <stdio.h>
int main()
{
int x, y, z;
x = 5;
y = 10;
z = x > y ? x : y;
printf("\n %d", z);
return 0;
}
Why do we pass the address of start for the insert & delete
functions and just the start for the traverse_node function ?
#include <stdio.h>
int main()
{
int a, b, c;
a = 2;
b = 3;
c = a+++++b;
printf("\n The value of c = %d", c);
return 0;
}
a) 6
b) 5
c) 7
d) Compiler Error
e) None of the above
Compiler Error
#include <stdio.h>
int main()
{
int number;
char c;
int total = 0;
do
{
printf("\n Enter the number :");
scanf("%d", &number);
total = total + number;
printf("Do you have any more numbers ( y or n )?
:");
scanf("%c", &c);
} while ( c == 'y' );
return 0;
}
#include <stdio.h>
int main()
{
int number;
char c;
int total = 0;
do
{
printf("\n Enter the number :");
scanf("%d", &number);
total = total + number;
if ( (c = getchar())== ‘\n’); /* empty statement
*/
printf("Do you have any more numbers ( y or n )?
:");
scanf("%c", &c);
} while ( c == 'y' );
return 0;
}
#include <stdio.h>
int main()
{
static char *p = malloc(10);
strcpy(p, "Hello World");
printf("\n p = %s", p);
return 0;
}
a) p = “Hello World”
b) p = “Hello Wor”
c) p = “Hello Worl”
d) Segmentation Fault
e) Compilation Error
Compiler error
#include <stdio.h>
int main()
{
int i;
char a[] = "string constant";
char *p = "string literals";
a) p = string constant
b) p = string literals
c) compilation error
d) segmentation fault
e) None of the above
Segmentation Fault
#include <stdio.h>
#include <stddef.h>
struct node
{
char a;
short int b;
char c;
int d;
float e;
char g;
double h;
};
int main()
{
struct node node1;
printf("\n size of struct node = %d", sizeof(struct
node));
printf("\n size of node1 = %d", sizeof(node1));
return 0;
}
#include <stdio.h>
int main()
{
int *ip;
printf("\n Before the function call : %p", ip);
f(ip);
printf("\n After the function call : %p", ip);
return 0;
}
int main()
{
char *s1 = "Hello, ";
char *s2 = "world!";
char *s3 = strcat(s1, s2);
printf("\n s3 = %s", s3);
return 0;
}
a) s3 = Hello, world!
b) s3 = Hello,
c) s3 = world!
d) Compiler error
e) Segmentation fault
Segmentation fault
#include <stdio.h>
char *itoa(int n)
{
char retbuf[20];
sprintf(retbuf, "%d", n);
return retbuf;
}
int main()
{
int n = 100;
char *p;
p = itoa(n);
printf("\n p = %s", p);
printf("\n p = %p", p);
return 0;
}
There is a problem with the program. In the function itoa
we define character array retbuf. That being local to
function it will go out of scope when the function exits.
There is a simple fix though. We can make the character
array as static so that will make it remain in scope. The
redefined function itoa is shown below :
char *itoa(int n)
{
static char retbuf[20];
sprintf(retbuf, "%d", n);
return retbuf;
}
161. Write a function to free the nodes in the linked list. Assume
that you are only provided with the head pointer for the
list
struct node
{
int data;
struct node *next;
};
typedef struct node NODE;
typedef NODE *NODEPTR;
#include <stdio.h>
int main()
{
char c = 'a';
printf("\n Size of a = %d", sizeof('a'));
printf("\n Size of c = %d", sizeof(c));
return 0;
}
#include <stdio.h>
int main()
{
int x, y;
do
{
printf("\n Enter a value for x : ");
y = scanf("%d", &x);
printf(“\n Number of items scanned : %d”, y);
} while ( x != -1 );
return 0;
}
#include <stdio.h>
int main()
{
char *answer;
printf("Type something:\n");
gets(answer);
printf("You typed \"%s\"\n", answer);
return 0;
}
a) compilation error
b) You typed “Type something”
c) <empty> /* No output */
d) Segmentation fault
e) None of the above
gets fgets
There can be a buffer Here we specify the buffer
overflow since we do not size and hence there cannot
specify the characters that be a overflow
are to be written to the
buffer
The new line character The newline character also is
does not form part of the part of the string. We need to
string explicitly remove the new
line character
For e.g., gets(char *buffer) fgets(char *buffer, MAX, fp)
where buffer is a character where buffer is a character
array or dynamic data array or dynamic data
structure allocated by structure allocated by
malloc malloc, MAX is the size of
buffer and fp is the file
pointer
#include <stdio.h>
int main()
{
char buffer[80];
printf("\n Enter a sentence :");
scanf("%[
\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
123456789]", buffer);
printf("\n The sentence entered by you is %s",
buffer);
return 0;
}
From the program it is clear that scanf will accept all
lowercase alphabets, uppercase alphabets, digits, spaces
and tabs.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_SIZE 100
int main()
{
FILE *fp;
char buffer[MAX_SIZE];
int count = 0;
char *p;
#include <stdio.h>
#include <string.h>
char message1[60] = "Four score and seven years ago ...";
char message2[60] = "abcdefghijklmnopqrstuvwxyz";
char temp[60];
main()
{
printf("\nmessage1[] before memset():\t%s",
message1);
memset(message1 + 5, `@', 10);
printf("\nmessage1[] after memset():\t%s", message1);
strcpy(temp, message2);
printf("\n\nOriginal message: %s", temp);
memcpy(temp + 4, temp + 16, 10);
printf("\nAfter memcpy() without overlap:\t%s", temp);
strcpy(temp, message2);
memcpy(temp + 6, temp + 4, 10);
printf("\nAfter memcpy() with overlap:\t%s", temp);
strcpy(temp, message2);
printf("\n\nOriginal message: %s", temp);
memmove(temp + 4, temp + 16, 10);
printf("\nAfter memmove() without overlap:\t%s",
temp);
strcpy(temp, message2);
memmove(temp + 6, temp + 4, 10);
printf("\nAfter memmove() with overlap:\t%s\n", temp);
}
#include <stdio.h>
#define SQR(X) X * X
int main()
{
float y;
y = 225.0/SQR(15);
printf(“\n The value of y = %f”, y );
}
Y = 225.0/SQR(15) becomes
Y = 225.0/15*15
Y = 225.0 ( Since /and * have equal priority they are
evaluated from left to right )
Y = 225.0/SQR(15) becomes
Y = 225.0/((15)*(15))
Y = 225.0/225 = 1.0
Variable Declaration
extern int x;
Variable Definition
int b;
float f = 2.0
Function Declaration
Function Definition
For e.g.,
int * p;
p = (int *)malloc(5*sizeof(int)) /* If sizeof(int) = 4 then
5 * sizeof(int) = 20 */
For e.g.,
int * p;
p = (int *)calloc(5, 4) /* allocation for 5 integers each
occupying 4 bytes. So totally
5 * 4 = 20 bytes allocated */
#include <stdio.h>
#include <string.h>
int main()
{
char *p;
char buffer[MAX_BUFFER];
char substring[50];
int count = 0;
p = strstr(buffer, substring);
while ( p != NULL )
{
count++;
printf("\n Substring is located at position %d", p
- buffer);
p++;
p = strstr(p, substring);
}
printf("\n The number of occurences = %d\n", count);
return 0;
}
#include <stdio.h>
int x;
int modifyvalue()
{
return(x+=10);
}
int changevalue(int x)
{
return(x+=1);
}
void main()
{
int x=10;
x++;
changevalue(x);
x++;
modifyvalue( );
printf("First output : %d\n",x);
x++;
changevalue(x);
printf("Second output : %d\n",x);
modifyvalue( );
printf("Third output: %d\n",x);
}
First output : 12
Second output : 13
Third output: 13
int main()
{
fn();
}
void fn()
{
char *p;
p = (char *)malloc(20); /* allocate 20 bytes */
…
}
Advantages Disadvantages
Complex A, B, C;
A.real = 2
A.img = 3
B.real = 1
B.img = 5
C=A+B
For e.g., For sorting array elements we can break the task into
the following procedures :
4. What is encapsulation ?
Encapsulation is the mechanism that binds code and data
together and guarantees the integrity of the data. In C++ the
basis of encapsulation is the class.
MEMBER FUNCTIONS
DATA
The date class provided below will clearly illustrate the concept.
class date
{
private :
int day;
int month;
int year;
public :
void getdate () const;
void setdate ( int x, int y, int z );
};
void date::getdate()
{
// return date
}
void date::setdate ( int x, int y, int z )
{
// check if x in proper range for day. For
// certain months it can be between 1 – 30 // only. For some
others it can be
// between 1 – 31. For Feb month it can be // 28 only if it is
// not a leap year and 29 if it is a leap year. // All these
// checks need to be done here. If it is not a // proper value
do not set the object. Print
// out an error message and exit.
The date class illustrates that an object data can be updated only
through its member functions. The implementation of these
member functions ensures that object data is always kept in a
consistent state. Clients of a class can access/modify data only
through the member functions (interface).
5. Explain Inheritance
BICYCLE CAR
#include <iostream>
class samp {
int i;
public:
samp ( int n )
{
i = n;
cout << “Constructing\n”;
}
~samp ( ) { cout << “Destructing\n”; }
int get_i ( ) { return i; }
};
int main( )
{
samp a(10);
cout << sqr_it(a) << “\n”;
return 0;
}
class samp {
char *s;
public:
samp() { s = ‘\0’; }
~samp() { if (s) free(s); cout << Freeing s\n”; }
void show() { cout << s << “\n”; }
void set (char *str);
};
str.set(s);
return str;
}
class strtype {
char *p;
int len;
public:
strtype(char *ptr);
~strtype( );
void show( );
};
strtype::strtype(char *ptr)
{
len = strlen(ptr);
p = (char *)malloc(len+1);
if (!p) {
cout << “Allocation error\n”;
exit(1);
}
strcpy(p, ptr);
}
strtype::~strtype()
{
cout << “Freeing p\n”;
free(p);
}
void strtype::show()
{
cout << p << “ – length: “ << len;
cout << “\n”;
}
int main()
{
strtype s1("test");
strtype s2 = s1;
s1.show();
s2.show();
}
10. How does the copy constructor solve the above problem ?
class strtype {
char *p;
int len;
public:
strtype(char *ptr);
strtype(const strtype &o);
~strtype( );
void show( );
};
len = strlen(o.p);
k = strlen(o.p) + 1;
p = new char[k];
if ( !p )
{
cout << “Allocation Failure\n”;
exit(1);
}
strcpy(p, o.p);
}
#include <iostream>
class base {
int x;
public:
void setx(int n) { x = n; }
void showx() { cout << x << ‘\n’; }
};
ob.setx(10);
ob.sety(20);
ob.showx();
ob.showy();
return 0;
}
Base Class
Member
Private Inaccessible Inaccessible Inaccessible
#include <iostream>
class samp {
int a;
protected:
int b;
public:
int c;
samp(int n, int m) { a = n; b = m; }
int geta() { return a; }
int getb() { return b; }
};
int main ( )
{
samp ob(10, 20);
ob.c = 10;
ob.b = 99;
return 0;
class complex {
int real;
int img;
public:
complex () { real = 0; img = 0; }
complex ( int x, int y ) { real = x; img = y; }
complex operator+ ( complex ob2 );
};
int main ()
{
complex A(10, 2), B(5, 3), C;
Class Base {
int i;
Base(int x) { i = x; }
};
void func ( )
{
cout << “Using derived1’s version of func() :”;
cout << i * i << ‘\n’;
}
};
void func ( )
{
cout << “Using derived2’s version of func() :”;
cout << i + i << ‘\n’;
}
};
int main ( )
{
Base *p;
Derived1 d_ob1(10);
Derived2 d_ob2(10);
int i, j;
class Vehicle
{
public :
virtual void drive() = 0 // This means that it
// is a pure virtual
// function and hence
// the class is
// abstract and no
// objects can be
// instantiated for the
// class. It can
// only be a base
// class providing
// pure virtual
// functions
};
class Car
{
public :
void drive ()
{
// Provide the implementation specific to car
}
};
class jeep
{
public :
void drive ()
{
// Provide the implementation specific to jeep
}
};
Class base {
public :
virtual int f ( int a ) = 0;
};
For e.g.,
union {
int i;
char ch[4];
}
26. Provide at least one good use for static member functions
class {
int n, d;
public:
myclass(int i, int j) { n = i; d = j; }
// friend function declared inside the
// class definition
friend int isfactor(myclass ob);
}
if(isfactor(ob1))
cout << “2 is a factor of 10\n”;
else
cout << “2 is not a factor of 10\n”;
if(isfactor(ob2))
cout << “3 is a factor of 13\n”;
else
cout << “3 is not a factor of 13\n”;
}
Note :
Passing by pointer
int main ()
{
int a = 5, b = 10;
printf(“\na = %d\tb=%d\n”);
swap_by_value(a,b);
printf(“\na = %d\tb=%d\n”);
swap_by_reference(a,b);
a = 5; b = 10;
printf(“\na = %d\tb=%d\n”);
swap_by_pointer(&a,&b);
}
Forms I and II are equivalent. In fact Form I is just a shortcut to Form II.
We tend to use Form I all the time because of the ease of use.
Note : Only members functions are passed the this pointer. Friend
functions are not passed with the this pointer.
Overloading and Overriding look like similar terms but they are
vastly different. The following table summarizes the difference
between the 2 terms.
Overloading OVERRIDING
Compile time phenomenon Run time phenomenon
Achieved through Achieved through Virtual
1. Functions Functions (Run time
2. Operators polymorphism)
(Compile time
polymorphism)
Called so because functions Called so because when the
can have the same name if base class declares a member
they perform the same function to be virtual then the
function and the actual derived classes can redefine
function to be called is known the function according to their
at compile time by requirements. Thus the derived
determining the number and classes override the definition
type of arguments passed to set by the base class.
the function. In the case of
operators the overloading
actually helps to use the
operators for user defined
data types just as we do for
the standard data types
33. What will happen if I allocate memory using new and free
it using free. (or) allocate memory using calloc and free it using
delete ?
Though malloc and new are used for memory allocation they
operate in different ways. For e.g., when we use new, memory is
automatically allocated by determining the size of the data type.
With malloc we have to explicitly use the sizeof operator to
determine the number of bytes that are to be allocated. When
we allocate memory using malloc we have to use free function to
free the memory. Similarly if we use new we have to use the
corresponding function delete to free the memory. If we allocate
memory with new and free it using free we are basically
destroying the dynamic memory allocation system. The program
could crash because of this.
#include <iostream>
using namespace std;
class Base
{
public:
Base(){ cout<<"Constructor : Base"<<endl;}
~Base(){ cout<<"Destructor : Base"<<endl;}
};
class Derived: public Base
{
//Doing a lot of jobs by extending the
// functionality
public:
Derived(){ cout<<"Constructor : Derived"<<endl;}
~Derived(){ cout<<"Destructor : Derived"<<endl;}
};
int main()
{
Base *Var = new Derived();
delete Var;
return 0;
}
When we create a Derived class object dynamically the base class part
of the object is created first followed by the derived class object. But
since the object is assigned to a base class pointer when the call to
delete the pointer “delete Var” is made only the base class destructor
is called. This is because the decision is made based on the type of the
pointer rather than the object pointed to. So the output for this
program is :
Constructor : Base
Constructor : Derived
Destructor : Base
class strtype {
char *p;
int len;
public:
strtype(char *s);
~strtype( ) {
cout << “Freeing “ << “\n”;
delete [] p;
}
char *get( ) { return p; }
strtype &operator=(strtype &ob);
};
strtype::strtype(char *s)
{
int k;
k = strlen(s)+1;
p = new char[k];
if (!p)
{
cout << “Allocation error\n”;
exit(1);
}
len = k;
strcpy(p,s);
}
int main( )
{
strtype a(“Hello”), b(“There”);
cout << a.get() << “\n”;
cout << b.get() << “\n”;
CAR JEEP
MARUTI TATA
AMPHIBIOUS VEHICLE
BASE
DERIVED1 DERIVED2
DERIVED3
class strtype {
char *p;
public:
strtype(char *s);
~strtype() { delete [] p; }
char *get() { return p; }
};
strtype::strtype(char *s)
{
int k;
k = strlen(s) + 1;
p = new char [k];
If(!p)
{
cout << “Allocation error\n”;
exit(1);
}
strcpy(p, s);
}
void show( strtype x )
{
char *s;
s = x.get();
cout << s << “\n”;
}
int main( )
{
strtype a(“Hello”), b(“There”);
show(a);
show(b);
}
Hello There
a 0x1000 0x2000
b
When the strtype object a is passed as parameter to the show
function a bit wise copy of the object is made. The strtype
parameter in the show function is the bit wise copy of a. Then it
gets the p value and prints it. The status of object x is shown
below
Hello
x 0x1000
When we exit the function the object x goes out of scope. So the
memory allocated for p is freed as well. But the original object a
is also pointing to the same memory. So after we get back to the
main function the original object becomes useless. The same
happens when we call the show function with the parameter b.
What then is the solution ? The most simple fix is to pass the
parameter by reference to the show function. This involves only
one change in the code. The change is shown below for clarity.
void show( strtype &x )
{
char *s;
s = x.get();
cout << s << “\n”;
}
38. What are the differences between shallow copy and deep
copy ?
#include <iostream>
#include <string>
using namespace std;
class myclass
{
char *p;
public:
myclass(char *str);
myclass(const myclass &obj);
~myclass() { cout << "Destructor Invoked\n"; delete
p; }
void show() const { cout << p << endl; }
};
myclass::myclass(char *str)
{
cout << "Normal Constructor invoked\n";
int len = strlen(str);
p = new char[len+1];
if ( !p )
{
cout << "Allocation Error\n" << endl;
exit(1);
}
strcpy(p, str);
}
int main()
{
myclass obj1("Hello");
print(obj1);
cout << "Fine until here\n";
return 0;
}
OBJECT1
PTR = 0x100
COPY OF
OBJECT1 When the function is called with object1 a
bitwise copy is made by the default copy
PTR = 0x100 constructor and now both the original object
and the copy point to the same memory
OBJECT1
PTR = 0x100
When the function goes out of scope the
copy also goes out of scope and calls its
destructor to free the memory. This the
memory is deleted but the original object is
still pointing to that memory
OBJECT1
PTR = 0x100
COPY OF
OBJECT1
PTR = 0x200
OBJECT1
PTR = 0x100
When the function goes out of scope the copy
also goes out of scope and calls its destructor
to free the memory. The memory allocated for
the copy is only deleted,. The original object
does not get affected in this case
#include <iostream>
using namespace std;
class Base {
int x;
public:
Base(int a) { x = a; }
virtual void function1();
virtual void function2();
};
class Derived1:public Base
{
int y;
public:
Derived1(int a, int b) : Base(a) { y = b; }
virtual void function1();
};
void Base::function1()
{
cout << "\nBase::Function1" << endl;
}
void Base::function2()
{
cout << "\nBase::Function2" << endl;
}
void Derived1::function1()
{
cout << "\nDerived1::Function1" << endl;
}
void Derived2::function2()
{
cout << "\nDerived2::Function2" << endl;
}
int main()
{
Base *bptr;
Base bobj(8);
Derived1 d1obj(2,3);
Derived2 d2obj(4,5);
Fun pfun = NULL;
cout << "\n *** Size of the objects
******************\n";
pfun = (Fun)*(ntr+0);
pfun();
pfun = (Fun)*(ntr+1);
pfun();
pfun = (Fun)*(qtr+0);
pfun();
pfun = (Fun)*(qtr+1);
pfun();
pfun = (Fun)*(str+0);
pfun();
pfun = (Fun)*(str+1);
pfun();
return 0;
}
Derived1::Function1
Base::Function2
Base::Function1
Derived2::Function2
Base::Function1
Base::Function2
Base::Function1
Base::Function2
Derived1::Function1
Base::Function2
Base::Function1
Derived2::Function2
0x80491c0 (vptr)
0x804880A
Data Member ( x )
0x80487DE
0x80491b0 (vptr)
0x80487B2
Data Member ( x )
0x80487DE
Data Member ( y )
0x80491b0 (vptr)
0x804880A
Data Member ( x )
0x8048786
Data Member ( y )
When we call function1 through the base pointer pointing
to derived1 object it first accesses the vptr of the derived1
object and then accesses the V table for derived1 class.
Then it offsets into the table and gets the starting address
of the function and then executes the function. In cases
where the derived class does not override the base class
implementation of a function the V table will contain the
starting address of the base version of the function.
a. is a
b. has a
ROOM TABLE
BODY HEART
#include <iostream>
using namespace std;
class base
{
public:
int bval;
base(){ bval=0;}
};
int main()
{
base BaseArr[5];
SomeFunc(BaseArr,5);
deri DeriArr[5];
SomeFunc(DeriArr,5);
return 0;
}
00000
01010
BaseArr[0]
0
BaseArr[1]
0
BaseArr[2]
0
BaseArr[3] 0
BaseArr[4] 0
01010
DeriArr[0] 0
DeriArr[1] 0
DeriArr[2] 0
DeriArr[3]
0
DeriArr[4] 0
#include <iostream>
using namespace std;
int x;
This does not give any compiler error for the statement f() = 100.
The output of this program is 100 ( value of x ). Here we should
understand that when a function returns a reference then that
function can be used on the LHS of an assignment statement. The
value of the expression on the RHS is assigned to the variable
whose reference is returned by the function. The one and only one
possibility where a function call can be made on the LHS of an
assignment statement is when the function returne a reference.
This is also one of the important advantages of reference variables.
float f(float i)
{
return i/2.0;
}
double f(double i)
{
return i/3.0;
}
int main()
{
float x = 10.09;
double y = 10.09;
cout << f(x);
cout << f(y);
cout << f(10);
return 0;
}
x is float hence f(x) will call float f(float i)
y is double hence f(y) will call double f(double i)
f(10) is ambiguous since it does not know which f() to be called ?
int main()
{
int x = 1, y = 2;
cout << f(x, y)
}
int f ( int a )
{
return a * a;
}
int main()
{
cout << f(10, 2);
cout << f(10);
return 0;
}
the data
59. What are the various types of templates ? Explain what are
a) Function templates
b) Class templates
References POINTERS
Implemented internally as
constant pointers
References must be initialized Pointers may or may not be
initialized
Once a reference is initialized A pointer initialized to point to
it cannot be modified. one object at a later point of
time be made to point to
another object of the same
datatype
When a function returns a Not possible with pointers
reference the function can be
used in the LHS of an
assignment statement
Usage of references in easy Usage of pointers is messy
and elegant
Not possible with references Pointers can be incremented,
decremented and can be used
in arithmetic expressions
63. What are accessor and mutator functions ? Why are they
called so ?
// function
void seti (int a) { i = a; } // mutator function
;}
class Demo {
int x, y, z;
public:
void set ( int a, int b, int c )
{
x = a;
y = b;
z = c;
}
void get() const
{
cout << x << ‘ ‘ << y << ‘ ‘ << z << endl;
}
};
class Test {
public:
void show()
{
cout << “No private data members for this
class” << endl;
}
};
When there are no data members objects can still be
created and can invoke the member functions. Then such
objects are created with the minimal memory unit namely
1 byte. So an object of the Test class will be 1 byte in size.
UPDATE student
SET lname = ‘Sundar’ and fname = ‘Syam’
where STUDENT_ID = 10;
a) Row Triggers
b) Statement Triggers
ROLL_NUMBER STUDENT_NAME
10 Rahul Roy
22 Pankaj Kapoor
78 Deeksha Sharma
56 Ram Narayan
A sub-query is a query within a query. The sub query can
be illustrated with the following 2 tables.
AUTHORS TABLE
BOOKS TABLE
key ?
example
i. One to One
ii. One to Many
iii. Many to One
iv. Many to Many
example
25. Classify the SQL statements according to their
functionality.
29. What are all the commercial RDBMS systems that are
currently available ? Which is the most popular one ?
30. Explain the differences between inner join and outer join
with an example
33. What are the various types of constraints when you create
a
table. Explain each of them with an example.
Why ?
Will it return the same values for all the 3 queries or could
it be different ? Justify your answer.
CUSTOMER_LOAN
1 1012 2000
2 1023 8000
3 1032 3000
1 1054 1000
1 1075 5000
3 1081 4000
STUDENT
COURSE
STUDENT_COURSES
JAVA PROGRAM
RESULT (OUTPUT)
HTTP Request
Web Client
Web Server
HTTP Reply
$ ifconfig –a ( On solaris )
If you know the machine name and looking for ipaddress you can
use the nslookup command
APPLICATION LAYER
PRESENTATION LAYER
SESSION LAYER
TRANSPORT TCP
NETWORK IP
DATA LINK
PHYSICAL
1. Token Ring
2. Star
3. Bus
When you talk about your strengths just mentioning that you are
hard-working, dedicated, honest etc. will not do. Everybody can
mention these eye catching words. What you need to do is find
out from your recent past an example to prove at least 1 or 2 of
the strengths that you have mentioned. That will also set you
apart from others. This should be an honest attempt.
When you tell about your weakness ensure that the weakness
that you mention will not affect your performance with the
company. Don’t say something like “I am always late in
submitting assignments”. You may be really honest. But your
weakness will disqualify you then and there. A company needs to
deliver products/services on time. For e.g., you can say that you
have a craving for chocolates and you are trying to control it by
not buying and keeping stock of the same.
4. Which areas do you want to improve ?
Mention an area where you have improved a lot and there is still
scope for improvement. For e.g., you can say that your skill in a
programming language such as C has improved a lot with a lot of
practice and you can admit that there is still scope for
improvement.
6. How will you react with a situation where you are being blamed
for no fault of yours ?
For this question you need to be careful with your answers. You
should not complain against the person blaming you
immediately. First talk to the person blaming you and try to find
out why he is blaming you. Sometimes we do things which we
think is all right but it is not so from others perspective. By
talking to the person you will know if you really are at fault. If
both of you do not agree then it would be wise to consult a
neutral person to know his opinion. If it turns out that you are
being blamed unnecessarily then only should you take it up with
your higher-ups.
7. Why do you want to join an IT company ? Why are you not going
for core companies in your area ? ( non IT/CS/MCA students )
Non IT students can mention the interests that they have in the
software field. There is no harm in mentioning that the core
companies do not recruit that many as the IT companies and in
the present day job market you just want to have a job in hand.