C -QUESTION BANK
1. The C language terminator is
(a) semicolon (b) colon (c) period (d) exclamation mark
2. What is false about the following -- A compound statement is
(a) A set of simple statements (b) Demarcated on either side by curly brackets
(c) Can be used in place of simple statement (d) A C function is not a compound statement.
3. What is true about the following C Functions
(a) Need not return any value (b) Should always return an integer
(c) Should always return a float (d) Should always return more than one value
4. Main must be written as
(a) The first function in the program (b) Second function in the program
(c) Last function in the program (d) Any where in the program
5. Which of the following about automatic variables within a function is correct?
(a) Its type must be declared before using the variable
(b) They are local (c) They are not initialized to zero (d) they are global
6. Write one statement equivalent to the following two statements: x=sqr(a); return(x);
Choose from one of the alternatives
(a) return(sqr(a)); (b) printf("sqr(a)");
(c) return(a*a*a); (d) printf("%d",sqr(a));
7. Which of the following about the C comments is incorrect?
(a) Comments can go over multiple lines
(b) Comments can start any where in the line
(c) A line can contain comments with out any language statements
(d) Comments can occur within comments
8. What is the value of y in the following code?
x=7;
y=0;
if(x=6) y=7;
else y=1;
(a) 7 (b) 0 (c) 1 (d) 6
9. Which of the following represents true statement either x is in the range of 10 and 50 or y is zero
(a) x >= 10 && x <= 50 || y = = 0 (b) x<50
(c) y!=10 && x>=50 (d) None of these
10. Which of the following is not an infinite loop ?
(a) while(1)\{ ....} (b) for(;;){...}
(c) x=0; (d) # define TRUE 0
do{ /*x unaltered within the loop*/ ...
.....}while(x = = 0); while(TRUE){ ....}
11. What does the following function print?
func(int i)
{
if(i%2)return 0;
else return 1;
}
main()
{
int =3;
i=func(i);
i=func(i);
printf("%d",i);
}
(a) 3 (b) 1 (c) 0 (d) 2
12. How does the C compiler interpret the following two statements
p=p+x;
q=q+y;
(a) p= p+x; (b)p=p+xq=q+y; (c)p= p+xq; (d)p=p+x/q=q+y;
q=q+y; q=q+y;
For questions 13,14,15,16 use the following alternatives:
a.int b.char c.string d.float
13. '9' ans: b
14. "1 e 02" ans d
15. 10e05 ans d
16. 15 ans a
17. Read the folllowing code
# define MAX 100
# define MIN 100
....
....
if(x>MAX)
x=1;
else if(x<MIN)
x=-1;
x=50;
if the initial value of x=200,what is the value after executing this code?
(a) 200 (b) 1 (c) -1 (d) 50
18. A memory of 20 bytes is allocated to a string declared as char *s then the following two statements are executed:
s="Entrance"
l=strlen(s);
what is the value of l ?
(a)20 (b)8 (c)9 (d)21
19. Given the piece of code
int a[50];
int *pa;
pa=a;
To access the 6th element of the array which of the following is incorrect?
(a) *(a+5) (b) a[5] (c) pa[5] (d) *(*pa + 5}
20. Consider the following structure:
struct num nam
{
int no;
char name[25];
}
struct num nam n1[]={{12,"Fred"},{15,"Martin"},{8,"Peter"},{11,Nicholas"}};
.....
.....
printf("%d%d",n1[2],no,(*(n1 + 2),no) + 1);
What does the above statement print?
(a) 8,9 (b) 9,9 (c) 8,8 (d) 8,unpredictable value
21. Identify the in correct expression
(a)a=b=3=4; (b)a=b=c=d=0; (c)float a=int b= 3.5; (d)int a; floatb;a=b=3.5;
22. Regarding the scope of the varibles;identify the incorrect statement:
(a) automatic variables are automatically initialized to 0 (b) static variables are are automatically initialized to 0
(c) the address of a register variable is not accessible (d) static variables cannot be initialized with any expression
23. cond 1?cond 2?cond 3?:exp 1:exp 2:exp 3:exp 4;
is equivalent to which of the following?
(a) if cond 1
exp 1;
else if cond 2
exp 2;
else if cond 3
exp 3;
else exp 4;
(b) if cond 1
if cond 2
if cond 3
exp 1;
else exp 2;
else exp 3;
else exp 4;
(c) if cond 1 && cond 2 && cond 3
exp 1 |exp 2|exp 3|exp 4;
(d) if cond 3
exp 1;
else if cond 2 exp 2;
else if cond 3 exp 3;
else exp 4;
24. Which of the following is invalid
(a) a+=b (b) a*=b (c) a>>=b (d) a**=b
26. What does the following code do?
fn(int n, int p, int r)
{
static int a=p;
switch(n)
{
case 4:a+=a*r;
case 3:a+=a*r;
case 2:a+=a*r;
case 1:a+=a*r;
}
}
(a) computes simple interest for one year
(b) computes amount on compound interest for 1 to 4 years
(c) computes simple interest for four year (d) computes compound interest for 1 year
27.
a=0;
while(a<5)
printf("%d\\n",a++);
How many times does the loop occurs?
(a) infinite (b)5 (c)4 (d)6
28. How many times does the loop iterated ?
for(i=0;i=10;i+=2)
printf("Hi\\n");
(a)10 (b) 2 (c) 5 (d) None of these
29. What is incorrect among the following
A recursive function
(a) calls itself (b) is equivalent to a loop
(c) has a termination condition (d) does not have a return value at all
30. Which of the following go out of the loop if expn 2 becoming false
(a) while(expn 1)\{...if(expn 2)continue;} (b) while(!expn 1)\{if(expn 2)continue;...}
(c) do{..if(expn 1)continue;..}while(expn 2); (d) while(!expn 2)\{if(expn 1)continue;..\}
31. Consider the following program
main()
{
unsigned int i=10;
while(i>=0)
{
printf("%u",i)
i--;
}
}
How many times the loop will get executed
(a)10 (b)9 (c)11 (d) infinite
32.Pick out the odd one out
(a) malloc() (b) calloc() (c) free() (d) realloc()
33.Consider the following program
main()
{
int a[5]={1,3,6,7,0};
int *b;
b=&a[2];
}
The value of b[-1] is
(a) 1 (b) 3 (c) -6 (d) none
34. # define prod(a,b)=a*b
main()
{
int x=2;
int y=3;
printf("%d",prod(x+2,y-10));
}
the output of the program is
(a) 8 (b) 6 (c) 7 (d) None
35.Consider the following program segment
int n,sum=1;
switch(n)
{
case 2:sum=sum+2;
case 3:sum*=2;
break;
default:sum=0;
}
If n=2, what is the value of sum
(a) 0 (b) 6 (c) 3 (d) None of these
36. Identify the incorrect one
1.if(c=1)
2.if(c!=3)
3.if(a<b)then
4.if(c==1)
(a) 1 only (b) 1&3 (c) 3 only (d) All of the above
37. The format specified for hexa decimal is
(a) %d (b) %o (c) %x (d) %u
38. Find the output of the following program
main()
{
int x=5, *p;
p=&x
printf("%d",++*p);
}
(a) 5 (b) 6 (c) 0 (d) none of these
39.Consider the following C code
main()
{
int i=3,x;
while(i>0)
{
x=func(i);
i--;
}
int func(int n)
{
static sum=0;
sum=sum+n;
return(sum);
}
}
The final value of x is
(a) 6 (b) 8 (c) 1 (d) 3
40. Int *a[5] refers to
(a) array of pointers (b) pointer to an array (c) pointer to a pointer (d) none of these
41.Which of the following statements is incorrect
(a) typedef struct new
{
int n1;
char n2;
} DATA;
(b) typedef struct
{
int n3;
char *n4;
}ICE;
(c) typedef union
{
int n5;
float n6;
} UDT;
(d) #typedef union
{
int n7;
float n8;
} TUDAT;
42. Point out error, if any, in the following program
main()
{
int i=1;
switch(i)
{
case 1:
printf("\nRadioactive cats have 18 half-lives");
break;
case 1*2+4:
printf("\nBottle for rent -inquire within");
break;
}
}
Ans. No error. Constant expression like 1*2+4 are acceptable in cases of a switch.
43. Point out the error, if any, in the following program
main()
{
int a=10,b;
a>= 5 ? b=100 : b=200;
printf("\n%d",b);
}
Ans. lvalue required in function main(). The second assignment should be written in parenthesis as follows:
a>= 5 ? b=100 : (b=200);
44. In the following code, in which order the functions would be called?
a= f1(23,14)*f2(12/4)+f3();
a) f1, f2, f3 b) f3, f2, f1
c) The order may vary from compiler to compiler d) None of the above
45. What would be the output of the following program?
main()
{
int i=4;
switch(i)
{
default:
printf("\n A mouse is an elephant built by the Japanese");
case 1:
printf(" Breeding rabbits is a hair raising experience");
break;
case 2:
printf("\n Friction is a drag");
break;
case 3:
printf("\n If practice make perfect, then nobody's perfect");
}
}
a) A mouse is an elephant built by the Japanese b) Breeding rabbits is a hare raising experience
c) All of the above d) None of the above
46. What is the output of the following program?
#define SQR(x) (x*x)
main()
{
int a,b=3;
a= SQR(b+2);
printf("%d",a);
}
a) 25 b) 11 c) error d) garbage value
47. In which line of the following, an error would be reported?
1. #define CIRCUM(R) (3.14*R*R);
2. main()
3. {
4. float r=1.0,c;
5. c= CIRCUM(r);
6. printf("\n%f",c);
7. if(CIRCUM(r))==6.28)
8. printf("\nGobbledygook");
9. }
a) line 1 b) line 5 c) line 6 d) line 7
48. What is the type of the variable b in the following declaration?
#define FLOATPTR float*
FLOATPTR a,b;
a) float b) float pointer c) int d) int pointer
49. In the following code;
#include<stdio.h>
main()
{
FILE *fp;
fp= fopen("trial","r");
}
fp points to:
a) The first character in the file.
b) A structure which contains a "char" pointer which points to the first character in the file.
c) The name of the file. d) None of the above.
50. We should not read after a write to a file without an intervening call to fflush(), fseek() or rewind() < TRUE/FALSE>
Ans. True
51. If the program (myprog) is run from the command line as myprog 1 2 3 , What would be the output?
main(int argc, char *argv[])
{
int i;
for(i=0;i<argc;i++)
printf("%s",argv[i]);
}
a) 1 2 3 b) C:\MYPROG.EXE 1 2 3
c) MYP d) None of the above
52. If the following program (myprog) is run from the command line as myprog 1 2 3, What would be the output?
main(int argc, char *argv[])
{
int i,j=0;
for(i=0;i<argc;i++)
j=j+ atoi(argv[i]);
printf("%d",j);
}
a) 1 2 3 b) 6 c) error d) "123"
53. If the following program (myprog) is run from the command line as myprog monday tuesday wednesday thursday,
What would be the output?
main(int argc, char *argv[])
{
while(--argc >0)
printf("%s",*++argv);
}
a) myprog monday tuesday wednesday thursday b) monday tuesday wednesday thursday
c) myprog tuesday thursday d) None of the above
54. In the following code, is p2 an integer or an integer pointer?
typedef int* ptr
ptr p1,p2;
Ans. Integer pointer
55. Point out the error in the following program
main()
{
const int x;
x=128;
printf("%d",x);
}
Ans. x should have been initialized where it is declared.
56. What would be the output of the following program?
main()
{
int y=128;
const int x=y;
printf("%d",x);
}
a) 128 b) Garbage value c) Error d) 0
57. What is the difference between the following declarations?
const char *s;
char const *s;
Ans. No difference
58. What is the difference between the following declarations?
const char *const s; char const *const s;
Ans. No difference
59. What would be the output of the following program?
main()
{
char near * near *ptr1;
char near * far *ptr2;
char near * huge *ptr3;
printf("%d %d %d",sizeof(ptr1),sizeof(ptr2),sizeof(ptr3));
}
a) 1 1 1 b) 1 2 4 c) 2 4 4 d) 4 4 4
60. If the following program (myprog) is run from the command line as myprog friday tuesday sunday,
What would be the output?
main(int argc, char*argv[])
{
printf("%c",**++argv);
}
a) m b) f c) myprog d) friday
61. If the following program (myprog) is run from the command line as myprog friday tuesday sunday,
What would be the output?
main(int argc, char *argv[])
{
printf("%c",*++argv[1]);
}
a) r b) f c) m d) y
62. If the following program (myprog) is run from the command line as myprog friday tuesday sunday,
What would be the output?
main(int argc, char *argv[])
{
while(sizeofargv)
printf("%s",argv[--sizeofargv]);
}
a) myprog friday tuesday sunday b) myprog friday tuesday
c) sunday tuesday friday myprog d) sunday tuesday friday
63. Point out the error in the following program
main()
{
int a=10;
void f();
a=f();
printf("\n%d",a);
}
void f()
{
printf("\nHi");
}
Ans. The program is trying to collect the value of a "void" function into an integer variable.
64. In the following program how would you print 50 using p?
main()
{
int a[]={10, 20, 30, 40, 50};
char *p;
p= (char*) a;
}
Ans. printf("\n%d",*((int*)p+4));
65. Would the following program compile?
main()
{
int a=10,*j;
void *k;< BR> j=k=&a;
j++;
k++;
printf("\n%u%u",j,k);
}
a) Yes b) No, the format is incorrect
c) No, the arithmetic operation is not permitted on void pointers
d) No, the arithmetic operation is not permitted on pointers
66. According to ANSI specifications which is the correct way of declaring main() when it receives command line arguments?
a) main(int argc, char *argv[]) b) main(argc,argv) int argc; char *argv[];
c) main() {int argc; char *argv[]; } d) None of the above
67. What error would the following function give on compilation?
f(int a, int b)
{
int a;
a=20;
return a;
}
a) missing parenthesis in the return statement
b) The function should be declared as int f(int a, int b)
c) redeclaration of a d) None of the above
68. Point out the error in the following program
main()
{
const char *fun();
*fun()='A';
}
const char *fun()
{
return "Hello";
}
Ans. fun() returns to a "const char" pointer which cannot be modified
69. What would be the output of the following program?
main()
{
const int x=5;
int *ptrx;
ptrx=&x;
*ptrx=10;
printf("%d",x);
}
a) 5 b) 10 c) Error d) Garbage value
70. A switch statement cannot include
a) constants as arguments b) constant expression as arguments
c) string as an argument d) None of the above
71. How long the following program will run?
main()
{
printf("\nSonata Software");
main();
}
a) infinite loop b) until the stack overflows
c) All of the above d) None of the above
72. On combining the following statements, you will get char*p; p=malloc(100);
a) char *p= malloc(100) b) p= (char*)malloc(100)
c) All of the above d) None of the above
73. What is the output of the following program?
main()
{
int n=5;
printf("\nn=%*d",n,n);
}
a) n=5 b) n=5
c) n= 5 d) error
74.What would be the output of the following program.
#include<stdio.h>
main()
{
extern int a;
printf("%d",a);;
}
int a=20;
(a) 20 (b) 0 (c) garbage value (d) error!!
75.What would be the output of the following program.
main()
{
int a[5]={2,3};
printf("\n %d %d %d",a[2],a[3],a[4]);
}
(a) garbage value (b) 2 3 3 (c) 3 2 2 (d) 0 0 0
76.What would be the output of the following program.
main()
{
inti=-3,j=2,k=0,m;
m=++i&&++j||++k;
printf("\n %d %d %d %d",i,j,k,m);
}
(a) -2 3 0 1 (b) -3 2 0 1 (c) -2 3 1 1 (d) error
77.What would be the output of the following program.
main()
{
int a,b;
a=sumdig(123);
b=sumdig(123);
printf("%d %d",a,b);
}
sumdig(int n)
{
static int s=0;
int d;
if(n!=0)
{
d=n%10;
n=(n-d)/10;
s=s+d;
sumdig(n);
}
else return(s);
}
(a) 12 6 (b) 6 12 (c) 3 15 (d) error
78.What would be the output of the following program.
#define CUBE(x) (x*x*x)
main()
{
int a,b=3;
a=CUBE(b++);
printf("\n %d %d",a,b);
}
(a) 64 4 (b) 27 4 (c) 27 6 (d) 64 6
79.What would be the output of the following program.
main()
{
const int x=get();
printf("%d",x);
}
get()
{
return(20);
}
(a) 20 (b) garbage value (c) error (d) 0
80.A function has this prototype void f1(int **x),
How will you call this function?
(a) int **a; (b) int a; (c) int *a; (d) int a=5;
f1(a); f1(&a); f1(&a); f1(&&a);
81.pointout the error, if any, in the for loop
main()
{
int l=1;
for(;;)
{
printf("%d",l++);
if(l>10)
break;
}
}
(a) The condition in the for loop is a must (b) The two semicolons should be dropped
(c) The for loop should be replaced by awhile loop (d) No error
82.Can the following piece of code be executed?
int main(void)
{
char strA[10]="compile",strB[10];
my_strcpy(strB,strA);
puts(strB);
}
char * my_strcpy(char *destination,char *source)
{
char *p=destination;
while(*source!='\0')
{
*p++=*source++;
}
*p='\0';
return destination;
}
(a) Compilation will only give a warning but will proceed to execute & will display "compile"
(b) The compilation error char *(char *,char *) differs in levels of indirection from 'int()' will occur
(c) Yes & it will print compile on the screen (d) None of the above
83.What would be the output of the following program.
#include<stdio.h>
main()
{
char str[5]="fast";
static char *ptr_to_array = str;
printf("%s",ptr_to_array);
}
(a) Compilation will only give a warning but will proceed to execute & will display "fast"
(b) display "fast" on screen (c) will give a compilation error (d) none of the above
84.What would be the output of the following program.
main()
{
int num,*p;
num=5;
p=#
printf("%d",*p);
}
(a) 6 (b) 5 (c) junk value (d) compilation error
85.What would be the output of the following program.
main()
{
int a[3]={2,3,4};
char *p;
p=a;
p=(char *)((int *)p+1);
printf("%d",p);
}
(a) 2 (b) 0 (c) junk value (d) 3
86.What would be the output of the following program.
main()
{
int i=10;
fn(i);
printf("%d",i);
}
fn(int i)
{
return ++i;
}
(a) 10 (b) 11 (c) 12 (d) Compilation error
87. What will be the value of i & j after the loop isexecuted?<BR> for(i=0,j=0;i<5,j<25;i++,j++)
(a) i=4,j= 24 (b) i=24,j= 24 (c) i=25,j= 25 (d) i=5,j=25
88.What would be the output of the following program.
main()
{
int i,j;
i=10;
j=sizeof(++i);
printf("%d",i);
}
(a) 11 (b) 10 (c) 4 (d) compilation error
89.What would be the output of the following program.
main()
{
int i=7;
printf("%d\n",i++*i++);
}
(a) 49 (b) 56 (c) 72 (d) compilation error
90. What will the printf print?
main()
{
char *p,*f();
p=f();
printf("f() returns:%s\n",p);
}
char *f()
{
char result[80];
strcpy(result,"anything will do");
return (result);
}
(a) f() returns: anything will do (b) f() returns:
(c) compilation error (d) The printf statement is not going to be executed
91.How many times the following program would print 'Jamboree'?
main()
{
printf("\n Jamboree");
main();
}
(a) infinite number of times (b) 32767 times
(c) 65535 times (d) till the stack does not overflow
92.Notice the error in the default statement in the code snippet below.Will it give a compilation error?
main()
{
int a=10,j;
j=fn(a);
switch(j)
{
case 30: printf("the value is 30");
break;
case 50: printf("the value is 50");
break;
default:printf("the value is not 30 or 50");
}
}
fn(int a)
{
return (++a);
}
(a) Will display "the value is 30"
(b) Will display "The value is not 30 or 50"
(c) Yes a compilation error would happen
(d) No compilation errors but there will be no output on the screen
93.What would be the output of the following program.
main()
{
struct emp
{
char name[20];
int age;
float sal;
};
struct emp e = {"tiger"};
printf("\n %d %f",e.age,e.sal);
}
(a) 0 0.000000 (b) Garbage values (c) Error (d) none of the above
1. Convert the expression ((A + B) * C – (D – E) ^ (F + G)) to equivalent Prefix and Postfix notations.
Prefix Notation:
^ - * +ABC - DE + FG(ans)
Postfix Notation:
AB + C * DE - - FG + ^ (ans)
2. Sorting is not possible by using which of the following methods?
(a) Insertion
(b) Selection
(c) Exchange
(d) Deletion
3. A binary tree with 20 nodes has 21 null branches?
4. How many different trees are possible with 3 nodes ? 5 ans.
5. In tree construction which is the suitable efficient data structure?
(a) Array (b) Linked list (c) Stack (d) Queue (e) none
6. Traverse the given tree using Inorder, Preorder and Postorder traversals.
Ø Inorder : D H B E A F C I G J(ans)
Ø Preorder: A B D H E C F G I J(ans)
Ø Postorder: H D E B F I J G C A(ans)
7. Draw a binary Tree for the expression :
A * B - (C + D) * (P / Q)
8. What is the time complexity of linear search algorithm over an array of n elements?
a. O (log2 n)
b. O (n) (ans)
c. O (n log2 n)
d. O (n2)
9. Which data structure is needed to convert infix notations to postfix notations?
a. Linear list
b. Queue.
c. Tree.
d. Stack. (ans)
10. A linear list of elements in which deletion can be done from one end(front) and insertion can take place only at the other end (rear) is known as
a. Queue (ans)
b. Stacks.
c. Trees.
d. Deque.
11. A binary tree in which of the levels except possibly the last, have the maximum number of nodes and all the nodes at the last level appear as far leaf as possible, is known as
a. Full binary tree.
b. 2-tree
c. Threaded tree.
d. Complete binary tree.(ans)
12. A list of integers are read in, one at a time and a binary search tree is constructed, Next the tree is traversed and the integers are printed. Which traversed would result in a printout which duplicates the original order of the list intergers ?
a. Preorder.
b. Postorder.
c. Inorder.
d. None of the above. (ans)
13. The time required to search an element in a binary search tree having n elements is
a O(1).
b. O(log2 n) (ans)
c. O(n)
d. O(n log2 n)
14. The infix expression (A+(B-C)*D) is correctly represented in prefix notation as
a. A+B-C*D
b. +A*-BCD
c. ABC-D*+
d. A+BC-D*
15. In what tree, for every node the height of its left subtree and right subtree differ atleast by one ?
a. Binary search tree.
b. AVL tree. (ans)
c. Complete tree.
d. Threaded binary tree.
Unix Test Paper
Q1 Unix is a
a. Single user, single tasking OS
b. Single user, multi tasking OS
c. Multi user, multi tasking OS
d. None of the above
Q 2 Command to list the files in directory
a. ps
b. ls
c. lp
d. cp
Q3 command to rename the file
a. cp
b. rm
c. mv
d. None of the above
Q 4 With a umask value of 112, what are the default permissions assigned to newly created files?
a. ---x--x-wx
b. -rw-rw-r--
c. -rwxrwxr--
d. -rw-rw----
Q 5 Which of the following is a popular terminal emulation software
a. VTERM
b. Vt100
c. COMIT
d. PERL
Q 6 The former administrator of Mercury Technical is no longer employed there. You are the new administrator, but do not know the root password. If you boot into single user mode, you can change the root password, but what command must you give at a LILO prompt to be able to do this?
a. linux single
b. linux passwd
c. linux 3
d. linux one
Q 7 You wish to find all the three-letter files in the current directory that end with the letter y. What command should you use?
a. ls *y
b. ls *y*
c. ls ??y
d ls ??y*
Q 8 The command "type vi" returns:
vi is hashed (/bin/vi)
This indicates:
a. vi is overloaded by a function
b. vi has been used in this session or has been manually hashed
c. the "which" command would be able to locate vi
Q 9 You want to give an ordinary user access to this parallel port:
crw-rw---- 1 root lp 9, 0 Apr 11 2002 lp0
You should
a. chmod 666 /dev/lp0
b. Add the user to the lp group
c. Add the user to /etc/sudoers
Q10 The command to delete a line from cursor position to beginning of the line
a. Dd
b. Du
c. Df
d. D0
Q 11 Vi editor will work in these mode
a. Insert
b.Command
c. Extended
d. All the above
Q 12 The default shell giving to the user is
a. C-shell
b. K-shell
c. Bash-shell
d. Bourne-shell
Q 13 What search criteria would best be used to find the lines within the MERCURY file about “clients”?
a. grep clients MERCURY
b. find clients MERCURY
c. sed clients MERCURY
d. search clients MERCURY
Q 14 The utility providing mail facility to the user is
a. Cpp
b.Shell
c. Comp
d. A.out
Q15 The utility provided to debug the program is
a. Shell
b. Gdb
c. Ed
d. None of the above
Q 16 The command to execute the process at specified time
a.At
b.Finger
c. None of the above
Q 17 Which command can be used to rearrange the order of jobs in a spooling queue awaiting printing?
a. lpc
b lpstat
c lpq
d lpr
Q 18 Which field of the /etc/passwd file holds the passwords for users?
a. first
b. second
c. third
d. fourth
Q 19 It is 3:00 and you are late for a meeting. You need to start the qwerty utility before heading to the meeting so it will run for the next few hours and compile weekly system usage results. Currently you are logged in as a regular user, but the qwerty script requires root permission to run. How should you execute the script?
a. su ; qwerty
b. su qwerty
c. su –c qwerty
d. su : qwerty
Q 20 Which file system can you not use with the mount utility?
a. msdos
b. coda
c. autofs
d. swap
Q 21 Which of the following will set the variable DAY equal to FRIDAY?
a. DAY FRIDAY
b. DAY=FRIDAY
c. DAY:FRIDAY
d. $DAY FRIDAY
Q 22 Which utility can be used to list modules, remove modules, and add modules?
a. modprobe
b. insmod
c. rmmod
d. depmod
Q23 A process with a PID number of 1777 has entered runaway mode. You have tried to remove it with a standard kill command, but it will not go away. What command can you use to be assured the process will terminate?
a. kill –NOW 1777
b. kill –HUP 1777
c. kill –15 1777
d. kill –9 1777
Q 24 vi command to go to extended mode is
a. I
b. A
c. :
d. p
Q25 The vi command to paste the content after the cursor position
a. o
b. p
c. P
d. a
Q 26. Which program is probably responsible for this message?
You will require a password to access your desktops
a. /bin/login
b. Kerberos
c. vncserver
Q 27. To prevent overwrite of existing files in the bash shell, use:
a. set -o noclobber
b. set +o noclobber
c. set -o clobber
d. set +o clobber
Q 28. The command
split -3 bigfile
will split "bigfile" into 3 files of approximate equal size
a. True
b. False
Q29. The command to display the list of processes running in the system is
a. Ps
b. Ls
c. Who
d. Wc
Q30 Command to create an empty file
a. Cat
b. Touch
c. Pico
d. Emacs
Q31 Assuming that the directory /safe does not exist, and that the directory /these contains files and other directories, what will a "ls" of /safe show after this command:
cp -a /these /safe
a. these
b. Copies of whatever files and directories were in /these
c. Nothing
Q 32. SMB is most similar to:
a. MSDOS
b. NFS
c. SMTP
Q 33. The default permissions for files in Unix are
a. 0655
b. 0755
c. 0666
d. 0644
Q34.The command pwd gives
a. Password in encrypted form
b. Password in decrypted form
c. Present working directory
d. None of these
Q 35. A sticky bit applied to a file would mean that
a. No one can remove it
b. It would stick around in memory even when its execution is over
c. Next time if u login it would get executed on its own
d. None of the above
Q 36. Command to delete an empty directory
a. Rm
b. Rmdir
c. Rm –r
d. None of the above
Q37. A bash user has the following files in their home directory:
.bash_login
.bash_profile
.profile
Which will be run as the user logs in?
a. .bash_login
b. .bash_profile
c. .profile
d. .profile and .bash_profile
e. All of them
Q38 File system contains
a. Boot block
b. Super block
c. Inode list
d. Data block
e. All the above
Q39 Father for all processes is
a. Root
b. Shell
c. Shed
d. Init
Q40 The first inode number used for files or directories on an ext2 filesystem (not counting 2 for the fs root itself) is:
a. 3
b. 7
c. 11
Q41 The command
vi +/5 /etc/hosts
a. Opens both /etc/hosts and the file "+5" for editing
b. Opens /etc/hosts for editing and positions the cursor at line 5
c. Opens /etc/hosts for editing and positions the cursor at the first line that contains the character "5"
Q 42 Using bash, how many files will be created by the following command (assume an empty directory):
touch {a,b}{a,b}{a,b}
a. None
b. One
c. Three
d. Six
e. Eight
f. Twelve
Q 43 The command head f1 would display
a. First line of the file f1
b. Nothing
c. First 10 lines of the file f1
d. The whole file f1
Q 44 the command to change the permissions
a. Touch
b. Chdir
c. Chmod
d. Chgrp
Q 45 The command to create device files
a. Cat
b. Touch
c. Mknod
d. None of these
Q 46 The vi command to delete the line from current cursor position to end of the line is
a. Dd
b. D
c. D$
d. None of the above
Q 47 The vi command to copy the line from current cursor position to end of the line is
a. Yy
b. Y$
c. R$
d. Xx
Q 48 The command to replace a character
a. X
b. R
c. P
d. D
Q 49 the command to delete 10 lines in vi editor
a. Dd10
b. 10dd
c. d10d
d. none of the above
Q 50 The command to come out of the editor after saving
a. Q
b. Quit
c. ZZ
d. :wq
Q 51. File table doesn’t maintains this
a. Offset
b. Mode
c. Reff. Count
d. Links
Q 52 Default file opened by the process are
a. Std I/P
b. Std O/P
c. Std Err
d. All the above
Q 53 Kernel allocate unique __________for files
a. Pid
b. Inode
c. Uid
d. None of the above
Q 54 dup() system call does
a. Duplicates files
b. Duplicates process
c. Duplicates file descriptor
d. Duplicates inode
Q 55 Inode number of root directory is
a. 0
b. 2
c. 1
d. 4
Q 56 command to create symbolic link is
a. ln
b. ln –a
c. ln –s
d. ln –l
Q57 Which of the following is true
a. Hard link refers inode number of the file
b. Soft link refers name of the file
c. Only (a)
d. Only (b)
e. Both (a) and (b)
Q 58 System call to create a symbolic link is
a. Link();
b. Unlink();
c. Link( type of link );
d. Symlink();
Q 59 The system call to give statistics of a file is
a. Stat();
b. Lstat();
c. Fstat();
d. All the above
Q 60 System call to change the directory is
a. Chmod();
b. Chdir();
c. Chown();
d. Chgrp();
Q 61 The data structure maintained by super block to store free inodes is
a. Linked list
b. Array
c. Queue
d. Stack
Q 62 The data structure maintained by super block to store free disk blocks is
a. Linked list
b. Array
c. Queue
d. Stack
Q 63 The effective permissions of directory are
a. 0777
b. 0755
c. 0754
d. 0765
Q 64 By default no.of links to the directory and files are
a. 1,2
b. 2,1
c. 1,3
d. 3,1
Q 65 system call to create a device file is
a. create();
b. mknod();
c. mkfs();
d. none of the above
Q 66 malloc() internally calls ______system call
a. alloc();
b. salloc();
c. sbrk();
d. none of the above
Q 67 lock() is the ______type of locking technique
a. mandatory
b. advisory
Q 68 First process which executes when restarts the system is
a. Init
b. Process 0
c. Shell
Q 69 Data structures maintained by the kernel for process are
a. Process table
b. Inode table
c. Region table
d. Both (a) and (c)
e. Both (a) and (b)
f. All (a) , (b) and (c)
Q 70 The process which is running in back ground called
a. Zombie process
b. Daemon process
c. Zif process
d. None of the above
Q 71 system call to get process id and parents process id
a. Getppid(), getpid();
b. Getpid(), getppid();
c. Get ppid(),getgpid();
d. Getgpid(), getppid();
Q 72 system call to create a process is
a. Fork()
b. Vfork();
c. Both (a) and (b)
d. None of the above
Q 73 fork() returns on success
a. Pid of child to init, 0 to parent
b. Pid of child to parent, 0 to child
c. 0 to parent, pid of parent to child
d. none of the above
Q 74 system call to execute already existing process is
a. fork();
b. vfork();
c. execl();
Q 75 command to kill a process is
a. kill pid
b. kill –9 pid
c. kill –1 pid
d. kill –2 pid
Q 76 command to send a signal to another process from shell
a. Kill
b. Signal
c. Raise
d. None of these
Q 77 system call to initiate the signal handler in the process
a. Kill()
b. Signal()
c. Raise()
d. None of these
Q 78 system call to send the signal to same process by a process
a. Kill()
b. Signal()
c. Raise()
d. None of these
Q 79 signals can be send to a process by kernel as well as another process
a. True
b. False
Q 80 Signals can send b/w unrelated processes also
a. True
b. False
Q 81 Command to create a pipe is
a. Mknod
b. Create
c. Open
d. None of the above
Q 82 System call to create a unnamed pipe
a. Mknod()
b. Pipe()
c. Create()
d. None of the above
Q 83 System call to create a named pipe(FIFO)
a. Mknod()
b. Pipe()
c. Create()
d. None of the above
Q 84 Which of the following statement is true
a. Process will block if pipe opened in write mode if nobody is opened in read mode
b. Process will block if pipe opened in read mode if nobody is opened in write mode
c. Both (a) and (b)
d. None of the above
Q 85 System V IPCs are
a. Message Queues
b. Semaphores
c. Shared memory
d. All the above
Q 86 SEMZCNT meant for
a. No. of processes are waiting for semaphore value has to increase.
b. No. of processes are waiting for semaphore value has to become Zero.
c. No. of processes are waiting for semaphore count has to delete
d. None of the above
Q 87 command to check the statistics of IPCs
a. Ls –l
b. Ipcs
c. Ps
d. All the above
Q 88 The flag to remove the ipc in controlling system call is
a. IPC_SET
b. IPC_RMID
c. IPC_STAT
d. All the above
Q 89 The command to remove System IPc
a. Ipcrm
b. Rm
c. Rmipc
d. Ipcrmid
Q 90 Which of these commands could you use to show one page of output at a time?
a. more
b. less
c. sed
d. pause
e. grep
Q 91 What command would send the output of cmd1 to the input of cmd2?
a. cmd1 | cmd2
b. cmd1 || cmd2
c. cmd1 && cmd2
d. cmd1 ; cmd2
e. cmd1 cmd2
Q 92 Which statement describes the cron daemon?
a. Manages scheduling of routine system tasks
b. Manages all incoming connections and spawns off child processes
c. Is responsible for file sharing across a network
d. Manages the printing subsystem
e. Keeps track of system messages and errors
Q 93 Which of the following are valid block devices on most default linux distributions?
a. hard disks
b. loopback devices
c. serial ports
d. virtual terminals
e. tape devices
Q 94 How can you best see how much free space you have in your current directory?
a. Use df .
b. Use df
c. Use du /
d. Use du .
e. Use df /
Q 95 State whether the statement is true or false
Swap device is the part of Secondary device
a. True
b. False
Q 96 Sockets are
a. End point communications
b. IP address + Port number
c. Used to communicate b/w two processes which are there in two systems
d. All the above
e. None of the above
Q 97 bind() system call is used
a. To bind the socket
b. To bind a name to the socket
c. To delete the socket
d. To connect the socket
Q 98 default operation of all the signals is
a. restart the process
b. terminate the process
c. kill the process
Q 99 the signals which doesn’t have any default operation
a. SIGCLD
b. SIGUSR1
c. SIGUSR2
d. SIGKILL
Q 100 The signal which can not be ignored is
a. SIGCLD
b. SIGKILL
c. SIGILL
d. SIGSYS
1. The C language terminator is
(a) semicolon (b) colon (c) period (d) exclamation mark
2. What is false about the following -- A compound statement is
(a) A set of simple statements (b) Demarcated on either side by curly brackets
(c) Can be used in place of simple statement (d) A C function is not a compound statement.
3. What is true about the following C Functions
(a) Need not return any value (b) Should always return an integer
(c) Should always return a float (d) Should always return more than one value
4. Main must be written as
(a) The first function in the program (b) Second function in the program
(c) Last function in the program (d) Any where in the program
5. Which of the following about automatic variables within a function is correct?
(a) Its type must be declared before using the variable
(b) They are local (c) They are not initialized to zero (d) they are global
6. Write one statement equivalent to the following two statements: x=sqr(a); return(x);
Choose from one of the alternatives
(a) return(sqr(a)); (b) printf("sqr(a)");
(c) return(a*a*a); (d) printf("%d",sqr(a));
7. Which of the following about the C comments is incorrect?
(a) Comments can go over multiple lines
(b) Comments can start any where in the line
(c) A line can contain comments with out any language statements
(d) Comments can occur within comments
8. What is the value of y in the following code?
x=7;
y=0;
if(x=6) y=7;
else y=1;
(a) 7 (b) 0 (c) 1 (d) 6
9. Which of the following represents true statement either x is in the range of 10 and 50 or y is zero
(a) x >= 10 && x <= 50 || y = = 0 (b) x<50
(c) y!=10 && x>=50 (d) None of these
10. Which of the following is not an infinite loop ?
(a) while(1)\{ ....} (b) for(;;){...}
(c) x=0; (d) # define TRUE 0
do{ /*x unaltered within the loop*/ ...
.....}while(x = = 0); while(TRUE){ ....}
11. What does the following function print?
func(int i)
{
if(i%2)return 0;
else return 1;
}
main()
{
int =3;
i=func(i);
i=func(i);
printf("%d",i);
}
(a) 3 (b) 1 (c) 0 (d) 2
12. How does the C compiler interpret the following two statements
p=p+x;
q=q+y;
(a) p= p+x; (b)p=p+xq=q+y; (c)p= p+xq; (d)p=p+x/q=q+y;
q=q+y; q=q+y;
For questions 13,14,15,16 use the following alternatives:
a.int b.char c.string d.float
13. '9' ans: b
14. "1 e 02" ans d
15. 10e05 ans d
16. 15 ans a
17. Read the folllowing code
# define MAX 100
# define MIN 100
....
....
if(x>MAX)
x=1;
else if(x<MIN)
x=-1;
x=50;
if the initial value of x=200,what is the value after executing this code?
(a) 200 (b) 1 (c) -1 (d) 50
18. A memory of 20 bytes is allocated to a string declared as char *s then the following two statements are executed:
s="Entrance"
l=strlen(s);
what is the value of l ?
(a)20 (b)8 (c)9 (d)21
19. Given the piece of code
int a[50];
int *pa;
pa=a;
To access the 6th element of the array which of the following is incorrect?
(a) *(a+5) (b) a[5] (c) pa[5] (d) *(*pa + 5}
20. Consider the following structure:
struct num nam
{
int no;
char name[25];
}
struct num nam n1[]={{12,"Fred"},{15,"Martin"},{8,"Peter"},{11,Nicholas"}};
.....
.....
printf("%d%d",n1[2],no,(*(n1 + 2),no) + 1);
What does the above statement print?
(a) 8,9 (b) 9,9 (c) 8,8 (d) 8,unpredictable value
21. Identify the in correct expression
(a)a=b=3=4; (b)a=b=c=d=0; (c)float a=int b= 3.5; (d)int a; floatb;a=b=3.5;
22. Regarding the scope of the varibles;identify the incorrect statement:
(a) automatic variables are automatically initialized to 0 (b) static variables are are automatically initialized to 0
(c) the address of a register variable is not accessible (d) static variables cannot be initialized with any expression
23. cond 1?cond 2?cond 3?:exp 1:exp 2:exp 3:exp 4;
is equivalent to which of the following?
(a) if cond 1
exp 1;
else if cond 2
exp 2;
else if cond 3
exp 3;
else exp 4;
(b) if cond 1
if cond 2
if cond 3
exp 1;
else exp 2;
else exp 3;
else exp 4;
(c) if cond 1 && cond 2 && cond 3
exp 1 |exp 2|exp 3|exp 4;
(d) if cond 3
exp 1;
else if cond 2 exp 2;
else if cond 3 exp 3;
else exp 4;
24. Which of the following is invalid
(a) a+=b (b) a*=b (c) a>>=b (d) a**=b
26. What does the following code do?
fn(int n, int p, int r)
{
static int a=p;
switch(n)
{
case 4:a+=a*r;
case 3:a+=a*r;
case 2:a+=a*r;
case 1:a+=a*r;
}
}
(a) computes simple interest for one year
(b) computes amount on compound interest for 1 to 4 years
(c) computes simple interest for four year (d) computes compound interest for 1 year
27.
a=0;
while(a<5)
printf("%d\\n",a++);
How many times does the loop occurs?
(a) infinite (b)5 (c)4 (d)6
28. How many times does the loop iterated ?
for(i=0;i=10;i+=2)
printf("Hi\\n");
(a)10 (b) 2 (c) 5 (d) None of these
29. What is incorrect among the following
A recursive function
(a) calls itself (b) is equivalent to a loop
(c) has a termination condition (d) does not have a return value at all
30. Which of the following go out of the loop if expn 2 becoming false
(a) while(expn 1)\{...if(expn 2)continue;} (b) while(!expn 1)\{if(expn 2)continue;...}
(c) do{..if(expn 1)continue;..}while(expn 2); (d) while(!expn 2)\{if(expn 1)continue;..\}
31. Consider the following program
main()
{
unsigned int i=10;
while(i>=0)
{
printf("%u",i)
i--;
}
}
How many times the loop will get executed
(a)10 (b)9 (c)11 (d) infinite
32.Pick out the odd one out
(a) malloc() (b) calloc() (c) free() (d) realloc()
33.Consider the following program
main()
{
int a[5]={1,3,6,7,0};
int *b;
b=&a[2];
}
The value of b[-1] is
(a) 1 (b) 3 (c) -6 (d) none
34. # define prod(a,b)=a*b
main()
{
int x=2;
int y=3;
printf("%d",prod(x+2,y-10));
}
the output of the program is
(a) 8 (b) 6 (c) 7 (d) None
35.Consider the following program segment
int n,sum=1;
switch(n)
{
case 2:sum=sum+2;
case 3:sum*=2;
break;
default:sum=0;
}
If n=2, what is the value of sum
(a) 0 (b) 6 (c) 3 (d) None of these
36. Identify the incorrect one
1.if(c=1)
2.if(c!=3)
3.if(a<b)then
4.if(c==1)
(a) 1 only (b) 1&3 (c) 3 only (d) All of the above
37. The format specified for hexa decimal is
(a) %d (b) %o (c) %x (d) %u
38. Find the output of the following program
main()
{
int x=5, *p;
p=&x
printf("%d",++*p);
}
(a) 5 (b) 6 (c) 0 (d) none of these
39.Consider the following C code
main()
{
int i=3,x;
while(i>0)
{
x=func(i);
i--;
}
int func(int n)
{
static sum=0;
sum=sum+n;
return(sum);
}
}
The final value of x is
(a) 6 (b) 8 (c) 1 (d) 3
40. Int *a[5] refers to
(a) array of pointers (b) pointer to an array (c) pointer to a pointer (d) none of these
41.Which of the following statements is incorrect
(a) typedef struct new
{
int n1;
char n2;
} DATA;
(b) typedef struct
{
int n3;
char *n4;
}ICE;
(c) typedef union
{
int n5;
float n6;
} UDT;
(d) #typedef union
{
int n7;
float n8;
} TUDAT;
42. Point out error, if any, in the following program
main()
{
int i=1;
switch(i)
{
case 1:
printf("\nRadioactive cats have 18 half-lives");
break;
case 1*2+4:
printf("\nBottle for rent -inquire within");
break;
}
}
Ans. No error. Constant expression like 1*2+4 are acceptable in cases of a switch.
43. Point out the error, if any, in the following program
main()
{
int a=10,b;
a>= 5 ? b=100 : b=200;
printf("\n%d",b);
}
Ans. lvalue required in function main(). The second assignment should be written in parenthesis as follows:
a>= 5 ? b=100 : (b=200);
44. In the following code, in which order the functions would be called?
a= f1(23,14)*f2(12/4)+f3();
a) f1, f2, f3 b) f3, f2, f1
c) The order may vary from compiler to compiler d) None of the above
45. What would be the output of the following program?
main()
{
int i=4;
switch(i)
{
default:
printf("\n A mouse is an elephant built by the Japanese");
case 1:
printf(" Breeding rabbits is a hair raising experience");
break;
case 2:
printf("\n Friction is a drag");
break;
case 3:
printf("\n If practice make perfect, then nobody's perfect");
}
}
a) A mouse is an elephant built by the Japanese b) Breeding rabbits is a hare raising experience
c) All of the above d) None of the above
46. What is the output of the following program?
#define SQR(x) (x*x)
main()
{
int a,b=3;
a= SQR(b+2);
printf("%d",a);
}
a) 25 b) 11 c) error d) garbage value
47. In which line of the following, an error would be reported?
1. #define CIRCUM(R) (3.14*R*R);
2. main()
3. {
4. float r=1.0,c;
5. c= CIRCUM(r);
6. printf("\n%f",c);
7. if(CIRCUM(r))==6.28)
8. printf("\nGobbledygook");
9. }
a) line 1 b) line 5 c) line 6 d) line 7
48. What is the type of the variable b in the following declaration?
#define FLOATPTR float*
FLOATPTR a,b;
a) float b) float pointer c) int d) int pointer
49. In the following code;
#include<stdio.h>
main()
{
FILE *fp;
fp= fopen("trial","r");
}
fp points to:
a) The first character in the file.
b) A structure which contains a "char" pointer which points to the first character in the file.
c) The name of the file. d) None of the above.
50. We should not read after a write to a file without an intervening call to fflush(), fseek() or rewind() < TRUE/FALSE>
Ans. True
51. If the program (myprog) is run from the command line as myprog 1 2 3 , What would be the output?
main(int argc, char *argv[])
{
int i;
for(i=0;i<argc;i++)
printf("%s",argv[i]);
}
a) 1 2 3 b) C:\MYPROG.EXE 1 2 3
c) MYP d) None of the above
52. If the following program (myprog) is run from the command line as myprog 1 2 3, What would be the output?
main(int argc, char *argv[])
{
int i,j=0;
for(i=0;i<argc;i++)
j=j+ atoi(argv[i]);
printf("%d",j);
}
a) 1 2 3 b) 6 c) error d) "123"
53. If the following program (myprog) is run from the command line as myprog monday tuesday wednesday thursday,
What would be the output?
main(int argc, char *argv[])
{
while(--argc >0)
printf("%s",*++argv);
}
a) myprog monday tuesday wednesday thursday b) monday tuesday wednesday thursday
c) myprog tuesday thursday d) None of the above
54. In the following code, is p2 an integer or an integer pointer?
typedef int* ptr
ptr p1,p2;
Ans. Integer pointer
55. Point out the error in the following program
main()
{
const int x;
x=128;
printf("%d",x);
}
Ans. x should have been initialized where it is declared.
56. What would be the output of the following program?
main()
{
int y=128;
const int x=y;
printf("%d",x);
}
a) 128 b) Garbage value c) Error d) 0
57. What is the difference between the following declarations?
const char *s;
char const *s;
Ans. No difference
58. What is the difference between the following declarations?
const char *const s; char const *const s;
Ans. No difference
59. What would be the output of the following program?
main()
{
char near * near *ptr1;
char near * far *ptr2;
char near * huge *ptr3;
printf("%d %d %d",sizeof(ptr1),sizeof(ptr2),sizeof(ptr3));
}
a) 1 1 1 b) 1 2 4 c) 2 4 4 d) 4 4 4
60. If the following program (myprog) is run from the command line as myprog friday tuesday sunday,
What would be the output?
main(int argc, char*argv[])
{
printf("%c",**++argv);
}
a) m b) f c) myprog d) friday
61. If the following program (myprog) is run from the command line as myprog friday tuesday sunday,
What would be the output?
main(int argc, char *argv[])
{
printf("%c",*++argv[1]);
}
a) r b) f c) m d) y
62. If the following program (myprog) is run from the command line as myprog friday tuesday sunday,
What would be the output?
main(int argc, char *argv[])
{
while(sizeofargv)
printf("%s",argv[--sizeofargv]);
}
a) myprog friday tuesday sunday b) myprog friday tuesday
c) sunday tuesday friday myprog d) sunday tuesday friday
63. Point out the error in the following program
main()
{
int a=10;
void f();
a=f();
printf("\n%d",a);
}
void f()
{
printf("\nHi");
}
Ans. The program is trying to collect the value of a "void" function into an integer variable.
64. In the following program how would you print 50 using p?
main()
{
int a[]={10, 20, 30, 40, 50};
char *p;
p= (char*) a;
}
Ans. printf("\n%d",*((int*)p+4));
65. Would the following program compile?
main()
{
int a=10,*j;
void *k;< BR> j=k=&a;
j++;
k++;
printf("\n%u%u",j,k);
}
a) Yes b) No, the format is incorrect
c) No, the arithmetic operation is not permitted on void pointers
d) No, the arithmetic operation is not permitted on pointers
66. According to ANSI specifications which is the correct way of declaring main() when it receives command line arguments?
a) main(int argc, char *argv[]) b) main(argc,argv) int argc; char *argv[];
c) main() {int argc; char *argv[]; } d) None of the above
67. What error would the following function give on compilation?
f(int a, int b)
{
int a;
a=20;
return a;
}
a) missing parenthesis in the return statement
b) The function should be declared as int f(int a, int b)
c) redeclaration of a d) None of the above
68. Point out the error in the following program
main()
{
const char *fun();
*fun()='A';
}
const char *fun()
{
return "Hello";
}
Ans. fun() returns to a "const char" pointer which cannot be modified
69. What would be the output of the following program?
main()
{
const int x=5;
int *ptrx;
ptrx=&x;
*ptrx=10;
printf("%d",x);
}
a) 5 b) 10 c) Error d) Garbage value
70. A switch statement cannot include
a) constants as arguments b) constant expression as arguments
c) string as an argument d) None of the above
71. How long the following program will run?
main()
{
printf("\nSonata Software");
main();
}
a) infinite loop b) until the stack overflows
c) All of the above d) None of the above
72. On combining the following statements, you will get char*p; p=malloc(100);
a) char *p= malloc(100) b) p= (char*)malloc(100)
c) All of the above d) None of the above
73. What is the output of the following program?
main()
{
int n=5;
printf("\nn=%*d",n,n);
}
a) n=5 b) n=5
c) n= 5 d) error
74.What would be the output of the following program.
#include<stdio.h>
main()
{
extern int a;
printf("%d",a);;
}
int a=20;
(a) 20 (b) 0 (c) garbage value (d) error!!
75.What would be the output of the following program.
main()
{
int a[5]={2,3};
printf("\n %d %d %d",a[2],a[3],a[4]);
}
(a) garbage value (b) 2 3 3 (c) 3 2 2 (d) 0 0 0
76.What would be the output of the following program.
main()
{
inti=-3,j=2,k=0,m;
m=++i&&++j||++k;
printf("\n %d %d %d %d",i,j,k,m);
}
(a) -2 3 0 1 (b) -3 2 0 1 (c) -2 3 1 1 (d) error
77.What would be the output of the following program.
main()
{
int a,b;
a=sumdig(123);
b=sumdig(123);
printf("%d %d",a,b);
}
sumdig(int n)
{
static int s=0;
int d;
if(n!=0)
{
d=n%10;
n=(n-d)/10;
s=s+d;
sumdig(n);
}
else return(s);
}
(a) 12 6 (b) 6 12 (c) 3 15 (d) error
78.What would be the output of the following program.
#define CUBE(x) (x*x*x)
main()
{
int a,b=3;
a=CUBE(b++);
printf("\n %d %d",a,b);
}
(a) 64 4 (b) 27 4 (c) 27 6 (d) 64 6
79.What would be the output of the following program.
main()
{
const int x=get();
printf("%d",x);
}
get()
{
return(20);
}
(a) 20 (b) garbage value (c) error (d) 0
80.A function has this prototype void f1(int **x),
How will you call this function?
(a) int **a; (b) int a; (c) int *a; (d) int a=5;
f1(a); f1(&a); f1(&a); f1(&&a);
81.pointout the error, if any, in the for loop
main()
{
int l=1;
for(;;)
{
printf("%d",l++);
if(l>10)
break;
}
}
(a) The condition in the for loop is a must (b) The two semicolons should be dropped
(c) The for loop should be replaced by awhile loop (d) No error
82.Can the following piece of code be executed?
int main(void)
{
char strA[10]="compile",strB[10];
my_strcpy(strB,strA);
puts(strB);
}
char * my_strcpy(char *destination,char *source)
{
char *p=destination;
while(*source!='\0')
{
*p++=*source++;
}
*p='\0';
return destination;
}
(a) Compilation will only give a warning but will proceed to execute & will display "compile"
(b) The compilation error char *(char *,char *) differs in levels of indirection from 'int()' will occur
(c) Yes & it will print compile on the screen (d) None of the above
83.What would be the output of the following program.
#include<stdio.h>
main()
{
char str[5]="fast";
static char *ptr_to_array = str;
printf("%s",ptr_to_array);
}
(a) Compilation will only give a warning but will proceed to execute & will display "fast"
(b) display "fast" on screen (c) will give a compilation error (d) none of the above
84.What would be the output of the following program.
main()
{
int num,*p;
num=5;
p=#
printf("%d",*p);
}
(a) 6 (b) 5 (c) junk value (d) compilation error
85.What would be the output of the following program.
main()
{
int a[3]={2,3,4};
char *p;
p=a;
p=(char *)((int *)p+1);
printf("%d",p);
}
(a) 2 (b) 0 (c) junk value (d) 3
86.What would be the output of the following program.
main()
{
int i=10;
fn(i);
printf("%d",i);
}
fn(int i)
{
return ++i;
}
(a) 10 (b) 11 (c) 12 (d) Compilation error
87. What will be the value of i & j after the loop isexecuted?<BR> for(i=0,j=0;i<5,j<25;i++,j++)
(a) i=4,j= 24 (b) i=24,j= 24 (c) i=25,j= 25 (d) i=5,j=25
88.What would be the output of the following program.
main()
{
int i,j;
i=10;
j=sizeof(++i);
printf("%d",i);
}
(a) 11 (b) 10 (c) 4 (d) compilation error
89.What would be the output of the following program.
main()
{
int i=7;
printf("%d\n",i++*i++);
}
(a) 49 (b) 56 (c) 72 (d) compilation error
90. What will the printf print?
main()
{
char *p,*f();
p=f();
printf("f() returns:%s\n",p);
}
char *f()
{
char result[80];
strcpy(result,"anything will do");
return (result);
}
(a) f() returns: anything will do (b) f() returns:
(c) compilation error (d) The printf statement is not going to be executed
91.How many times the following program would print 'Jamboree'?
main()
{
printf("\n Jamboree");
main();
}
(a) infinite number of times (b) 32767 times
(c) 65535 times (d) till the stack does not overflow
92.Notice the error in the default statement in the code snippet below.Will it give a compilation error?
main()
{
int a=10,j;
j=fn(a);
switch(j)
{
case 30: printf("the value is 30");
break;
case 50: printf("the value is 50");
break;
default:printf("the value is not 30 or 50");
}
}
fn(int a)
{
return (++a);
}
(a) Will display "the value is 30"
(b) Will display "The value is not 30 or 50"
(c) Yes a compilation error would happen
(d) No compilation errors but there will be no output on the screen
93.What would be the output of the following program.
main()
{
struct emp
{
char name[20];
int age;
float sal;
};
struct emp e = {"tiger"};
printf("\n %d %f",e.age,e.sal);
}
(a) 0 0.000000 (b) Garbage values (c) Error (d) none of the above
1. Convert the expression ((A + B) * C – (D – E) ^ (F + G)) to equivalent Prefix and Postfix notations.
Prefix Notation:
^ - * +ABC - DE + FG(ans)
Postfix Notation:
AB + C * DE - - FG + ^ (ans)
2. Sorting is not possible by using which of the following methods?
(a) Insertion
(b) Selection
(c) Exchange
(d) Deletion
3. A binary tree with 20 nodes has 21 null branches?
4. How many different trees are possible with 3 nodes ? 5 ans.
5. In tree construction which is the suitable efficient data structure?
(a) Array (b) Linked list (c) Stack (d) Queue (e) none
6. Traverse the given tree using Inorder, Preorder and Postorder traversals.
Ø Inorder : D H B E A F C I G J(ans)
Ø Preorder: A B D H E C F G I J(ans)
Ø Postorder: H D E B F I J G C A(ans)
7. Draw a binary Tree for the expression :
A * B - (C + D) * (P / Q)
8. What is the time complexity of linear search algorithm over an array of n elements?
a. O (log2 n)
b. O (n) (ans)
c. O (n log2 n)
d. O (n2)
9. Which data structure is needed to convert infix notations to postfix notations?
a. Linear list
b. Queue.
c. Tree.
d. Stack. (ans)
10. A linear list of elements in which deletion can be done from one end(front) and insertion can take place only at the other end (rear) is known as
a. Queue (ans)
b. Stacks.
c. Trees.
d. Deque.
11. A binary tree in which of the levels except possibly the last, have the maximum number of nodes and all the nodes at the last level appear as far leaf as possible, is known as
a. Full binary tree.
b. 2-tree
c. Threaded tree.
d. Complete binary tree.(ans)
12. A list of integers are read in, one at a time and a binary search tree is constructed, Next the tree is traversed and the integers are printed. Which traversed would result in a printout which duplicates the original order of the list intergers ?
a. Preorder.
b. Postorder.
c. Inorder.
d. None of the above. (ans)
13. The time required to search an element in a binary search tree having n elements is
a O(1).
b. O(log2 n) (ans)
c. O(n)
d. O(n log2 n)
14. The infix expression (A+(B-C)*D) is correctly represented in prefix notation as
a. A+B-C*D
b. +A*-BCD
c. ABC-D*+
d. A+BC-D*
15. In what tree, for every node the height of its left subtree and right subtree differ atleast by one ?
a. Binary search tree.
b. AVL tree. (ans)
c. Complete tree.
d. Threaded binary tree.
Unix Test Paper
Q1 Unix is a
a. Single user, single tasking OS
b. Single user, multi tasking OS
c. Multi user, multi tasking OS
d. None of the above
Q 2 Command to list the files in directory
a. ps
b. ls
c. lp
d. cp
Q3 command to rename the file
a. cp
b. rm
c. mv
d. None of the above
Q 4 With a umask value of 112, what are the default permissions assigned to newly created files?
a. ---x--x-wx
b. -rw-rw-r--
c. -rwxrwxr--
d. -rw-rw----
Q 5 Which of the following is a popular terminal emulation software
a. VTERM
b. Vt100
c. COMIT
d. PERL
Q 6 The former administrator of Mercury Technical is no longer employed there. You are the new administrator, but do not know the root password. If you boot into single user mode, you can change the root password, but what command must you give at a LILO prompt to be able to do this?
a. linux single
b. linux passwd
c. linux 3
d. linux one
Q 7 You wish to find all the three-letter files in the current directory that end with the letter y. What command should you use?
a. ls *y
b. ls *y*
c. ls ??y
d ls ??y*
Q 8 The command "type vi" returns:
vi is hashed (/bin/vi)
This indicates:
a. vi is overloaded by a function
b. vi has been used in this session or has been manually hashed
c. the "which" command would be able to locate vi
Q 9 You want to give an ordinary user access to this parallel port:
crw-rw---- 1 root lp 9, 0 Apr 11 2002 lp0
You should
a. chmod 666 /dev/lp0
b. Add the user to the lp group
c. Add the user to /etc/sudoers
Q10 The command to delete a line from cursor position to beginning of the line
a. Dd
b. Du
c. Df
d. D0
Q 11 Vi editor will work in these mode
a. Insert
b.Command
c. Extended
d. All the above
Q 12 The default shell giving to the user is
a. C-shell
b. K-shell
c. Bash-shell
d. Bourne-shell
Q 13 What search criteria would best be used to find the lines within the MERCURY file about “clients”?
a. grep clients MERCURY
b. find clients MERCURY
c. sed clients MERCURY
d. search clients MERCURY
Q 14 The utility providing mail facility to the user is
a. Cpp
b.Shell
c. Comp
d. A.out
Q15 The utility provided to debug the program is
a. Shell
b. Gdb
c. Ed
d. None of the above
Q 16 The command to execute the process at specified time
a.At
b.Finger
c. None of the above
Q 17 Which command can be used to rearrange the order of jobs in a spooling queue awaiting printing?
a. lpc
b lpstat
c lpq
d lpr
Q 18 Which field of the /etc/passwd file holds the passwords for users?
a. first
b. second
c. third
d. fourth
Q 19 It is 3:00 and you are late for a meeting. You need to start the qwerty utility before heading to the meeting so it will run for the next few hours and compile weekly system usage results. Currently you are logged in as a regular user, but the qwerty script requires root permission to run. How should you execute the script?
a. su ; qwerty
b. su qwerty
c. su –c qwerty
d. su : qwerty
Q 20 Which file system can you not use with the mount utility?
a. msdos
b. coda
c. autofs
d. swap
Q 21 Which of the following will set the variable DAY equal to FRIDAY?
a. DAY FRIDAY
b. DAY=FRIDAY
c. DAY:FRIDAY
d. $DAY FRIDAY
Q 22 Which utility can be used to list modules, remove modules, and add modules?
a. modprobe
b. insmod
c. rmmod
d. depmod
Q23 A process with a PID number of 1777 has entered runaway mode. You have tried to remove it with a standard kill command, but it will not go away. What command can you use to be assured the process will terminate?
a. kill –NOW 1777
b. kill –HUP 1777
c. kill –15 1777
d. kill –9 1777
Q 24 vi command to go to extended mode is
a. I
b. A
c. :
d. p
Q25 The vi command to paste the content after the cursor position
a. o
b. p
c. P
d. a
Q 26. Which program is probably responsible for this message?
You will require a password to access your desktops
a. /bin/login
b. Kerberos
c. vncserver
Q 27. To prevent overwrite of existing files in the bash shell, use:
a. set -o noclobber
b. set +o noclobber
c. set -o clobber
d. set +o clobber
Q 28. The command
split -3 bigfile
will split "bigfile" into 3 files of approximate equal size
a. True
b. False
Q29. The command to display the list of processes running in the system is
a. Ps
b. Ls
c. Who
d. Wc
Q30 Command to create an empty file
a. Cat
b. Touch
c. Pico
d. Emacs
Q31 Assuming that the directory /safe does not exist, and that the directory /these contains files and other directories, what will a "ls" of /safe show after this command:
cp -a /these /safe
a. these
b. Copies of whatever files and directories were in /these
c. Nothing
Q 32. SMB is most similar to:
a. MSDOS
b. NFS
c. SMTP
Q 33. The default permissions for files in Unix are
a. 0655
b. 0755
c. 0666
d. 0644
Q34.The command pwd gives
a. Password in encrypted form
b. Password in decrypted form
c. Present working directory
d. None of these
Q 35. A sticky bit applied to a file would mean that
a. No one can remove it
b. It would stick around in memory even when its execution is over
c. Next time if u login it would get executed on its own
d. None of the above
Q 36. Command to delete an empty directory
a. Rm
b. Rmdir
c. Rm –r
d. None of the above
Q37. A bash user has the following files in their home directory:
.bash_login
.bash_profile
.profile
Which will be run as the user logs in?
a. .bash_login
b. .bash_profile
c. .profile
d. .profile and .bash_profile
e. All of them
Q38 File system contains
a. Boot block
b. Super block
c. Inode list
d. Data block
e. All the above
Q39 Father for all processes is
a. Root
b. Shell
c. Shed
d. Init
Q40 The first inode number used for files or directories on an ext2 filesystem (not counting 2 for the fs root itself) is:
a. 3
b. 7
c. 11
Q41 The command
vi +/5 /etc/hosts
a. Opens both /etc/hosts and the file "+5" for editing
b. Opens /etc/hosts for editing and positions the cursor at line 5
c. Opens /etc/hosts for editing and positions the cursor at the first line that contains the character "5"
Q 42 Using bash, how many files will be created by the following command (assume an empty directory):
touch {a,b}{a,b}{a,b}
a. None
b. One
c. Three
d. Six
e. Eight
f. Twelve
Q 43 The command head f1 would display
a. First line of the file f1
b. Nothing
c. First 10 lines of the file f1
d. The whole file f1
Q 44 the command to change the permissions
a. Touch
b. Chdir
c. Chmod
d. Chgrp
Q 45 The command to create device files
a. Cat
b. Touch
c. Mknod
d. None of these
Q 46 The vi command to delete the line from current cursor position to end of the line is
a. Dd
b. D
c. D$
d. None of the above
Q 47 The vi command to copy the line from current cursor position to end of the line is
a. Yy
b. Y$
c. R$
d. Xx
Q 48 The command to replace a character
a. X
b. R
c. P
d. D
Q 49 the command to delete 10 lines in vi editor
a. Dd10
b. 10dd
c. d10d
d. none of the above
Q 50 The command to come out of the editor after saving
a. Q
b. Quit
c. ZZ
d. :wq
Q 51. File table doesn’t maintains this
a. Offset
b. Mode
c. Reff. Count
d. Links
Q 52 Default file opened by the process are
a. Std I/P
b. Std O/P
c. Std Err
d. All the above
Q 53 Kernel allocate unique __________for files
a. Pid
b. Inode
c. Uid
d. None of the above
Q 54 dup() system call does
a. Duplicates files
b. Duplicates process
c. Duplicates file descriptor
d. Duplicates inode
Q 55 Inode number of root directory is
a. 0
b. 2
c. 1
d. 4
Q 56 command to create symbolic link is
a. ln
b. ln –a
c. ln –s
d. ln –l
Q57 Which of the following is true
a. Hard link refers inode number of the file
b. Soft link refers name of the file
c. Only (a)
d. Only (b)
e. Both (a) and (b)
Q 58 System call to create a symbolic link is
a. Link();
b. Unlink();
c. Link( type of link );
d. Symlink();
Q 59 The system call to give statistics of a file is
a. Stat();
b. Lstat();
c. Fstat();
d. All the above
Q 60 System call to change the directory is
a. Chmod();
b. Chdir();
c. Chown();
d. Chgrp();
Q 61 The data structure maintained by super block to store free inodes is
a. Linked list
b. Array
c. Queue
d. Stack
Q 62 The data structure maintained by super block to store free disk blocks is
a. Linked list
b. Array
c. Queue
d. Stack
Q 63 The effective permissions of directory are
a. 0777
b. 0755
c. 0754
d. 0765
Q 64 By default no.of links to the directory and files are
a. 1,2
b. 2,1
c. 1,3
d. 3,1
Q 65 system call to create a device file is
a. create();
b. mknod();
c. mkfs();
d. none of the above
Q 66 malloc() internally calls ______system call
a. alloc();
b. salloc();
c. sbrk();
d. none of the above
Q 67 lock() is the ______type of locking technique
a. mandatory
b. advisory
Q 68 First process which executes when restarts the system is
a. Init
b. Process 0
c. Shell
Q 69 Data structures maintained by the kernel for process are
a. Process table
b. Inode table
c. Region table
d. Both (a) and (c)
e. Both (a) and (b)
f. All (a) , (b) and (c)
Q 70 The process which is running in back ground called
a. Zombie process
b. Daemon process
c. Zif process
d. None of the above
Q 71 system call to get process id and parents process id
a. Getppid(), getpid();
b. Getpid(), getppid();
c. Get ppid(),getgpid();
d. Getgpid(), getppid();
Q 72 system call to create a process is
a. Fork()
b. Vfork();
c. Both (a) and (b)
d. None of the above
Q 73 fork() returns on success
a. Pid of child to init, 0 to parent
b. Pid of child to parent, 0 to child
c. 0 to parent, pid of parent to child
d. none of the above
Q 74 system call to execute already existing process is
a. fork();
b. vfork();
c. execl();
Q 75 command to kill a process is
a. kill pid
b. kill –9 pid
c. kill –1 pid
d. kill –2 pid
Q 76 command to send a signal to another process from shell
a. Kill
b. Signal
c. Raise
d. None of these
Q 77 system call to initiate the signal handler in the process
a. Kill()
b. Signal()
c. Raise()
d. None of these
Q 78 system call to send the signal to same process by a process
a. Kill()
b. Signal()
c. Raise()
d. None of these
Q 79 signals can be send to a process by kernel as well as another process
a. True
b. False
Q 80 Signals can send b/w unrelated processes also
a. True
b. False
Q 81 Command to create a pipe is
a. Mknod
b. Create
c. Open
d. None of the above
Q 82 System call to create a unnamed pipe
a. Mknod()
b. Pipe()
c. Create()
d. None of the above
Q 83 System call to create a named pipe(FIFO)
a. Mknod()
b. Pipe()
c. Create()
d. None of the above
Q 84 Which of the following statement is true
a. Process will block if pipe opened in write mode if nobody is opened in read mode
b. Process will block if pipe opened in read mode if nobody is opened in write mode
c. Both (a) and (b)
d. None of the above
Q 85 System V IPCs are
a. Message Queues
b. Semaphores
c. Shared memory
d. All the above
Q 86 SEMZCNT meant for
a. No. of processes are waiting for semaphore value has to increase.
b. No. of processes are waiting for semaphore value has to become Zero.
c. No. of processes are waiting for semaphore count has to delete
d. None of the above
Q 87 command to check the statistics of IPCs
a. Ls –l
b. Ipcs
c. Ps
d. All the above
Q 88 The flag to remove the ipc in controlling system call is
a. IPC_SET
b. IPC_RMID
c. IPC_STAT
d. All the above
Q 89 The command to remove System IPc
a. Ipcrm
b. Rm
c. Rmipc
d. Ipcrmid
Q 90 Which of these commands could you use to show one page of output at a time?
a. more
b. less
c. sed
d. pause
e. grep
Q 91 What command would send the output of cmd1 to the input of cmd2?
a. cmd1 | cmd2
b. cmd1 || cmd2
c. cmd1 && cmd2
d. cmd1 ; cmd2
e. cmd1 cmd2
Q 92 Which statement describes the cron daemon?
a. Manages scheduling of routine system tasks
b. Manages all incoming connections and spawns off child processes
c. Is responsible for file sharing across a network
d. Manages the printing subsystem
e. Keeps track of system messages and errors
Q 93 Which of the following are valid block devices on most default linux distributions?
a. hard disks
b. loopback devices
c. serial ports
d. virtual terminals
e. tape devices
Q 94 How can you best see how much free space you have in your current directory?
a. Use df .
b. Use df
c. Use du /
d. Use du .
e. Use df /
Q 95 State whether the statement is true or false
Swap device is the part of Secondary device
a. True
b. False
Q 96 Sockets are
a. End point communications
b. IP address + Port number
c. Used to communicate b/w two processes which are there in two systems
d. All the above
e. None of the above
Q 97 bind() system call is used
a. To bind the socket
b. To bind a name to the socket
c. To delete the socket
d. To connect the socket
Q 98 default operation of all the signals is
a. restart the process
b. terminate the process
c. kill the process
Q 99 the signals which doesn’t have any default operation
a. SIGCLD
b. SIGUSR1
c. SIGUSR2
d. SIGKILL
Q 100 The signal which can not be ignored is
a. SIGCLD
b. SIGKILL
c. SIGILL
d. SIGSYS