Saturday, October 03, 2020

C Programming and Data Structure

 Q.1 What is the output of the following program?
main ( )
{ int x = 2, y = 5;
if (x < y) return (x = x+y); else printf (“z1”);
printf(“z2”);
}
(A) z2
(B) z1z2
(C) Compilation error
(D) None of these
Ans: D
There is no compilation error but there will no output because function is returning a value and if statement is true in this case.

Q.2 Choose the correct one
(A) Address operator can not be applied to register variables
(B) Address operator can be applied to register variables
(C) Use of register declaration will increase the execution time
(D) None of the above
Ans: D
A register access is much faster than a memory access, keeping the frequently accessed variables in the register will lead to faster execution of programs.

Q.3 What is the following program doing?
main ()
{ int d = 1;
do
printf(“%d\n”, d++);
while (d < = 9);}
(A) Adding 9 integers
(B) Adding integers from 1 to 9
(C) Displaying integers from 1 to 9
(D) None of these
Ans: C
d starting from 1 is incrementing one by one till d=9 so the printf statement is printing numbers from 1 to 9.

Q.4 What is the output of the following program?
main ( )
{ extern int x;
x = 20;
printf(“\n%d”, x);
}
(A) 0
(B) 20
(C) error
(D) garbage value
Ans: C
Output of the given program will be “Linker error-undefined symbol x”. External variables are declared outside a function.

Q.5 If x is one dimensional array, then pick up the correct answer
(A) *(x + i) is same as &x[i]
(B) *&x[i] is same as x + i
(C) *(x + i) is same as x[i] +1
(D) *(x + i) is same as *x[i]
Ans: A
num[i] is same as *(num+i)

Q.6 Consider the following declaration
int a, *b = &a, **c = &b;
The following program fragment
a = 4;
**c = 5;
(A) does not change the value of a
(B) assigns address of c to a
(C) assigns the value of b to a
(D) assigns 5 to a
Ans: D
The given statements assigns 5 to a

Q.7 Choose the correct answer
(A) enum variable can not be assigned new values
(B) enum variable can be compared
(C) enumeration feature increase the power of C
(D) None of the above
Ans: C
The enumerated data types give an opportunity to invent our own data typeand define what value the variable of this data type can take.

Q.8 The content of file will be lost if it is opened in
(A) w mode
(B) w+ mode
(C) a mode
(D) a+ mode
Ans: A
When the mode is writing, the contents are deleted and the file is opened as a new file.

Q.9 Consider the following code segment:
int a[10], *p1, *p2;
p1 = &a[4];
p2 = &a[6];
Which of the following statements is incorrect w.r.t. pointers?
(A) p1 + 2
(B) p2 – 2
(C) p2 + p1
(D) p2 – p1
Ans: C
Addition of two pointers is not allowed.

Q.10 The second expression (j – k) in the following expression will be evaluated
(i + 5) && (j – k)
(A) if expression (i + 5) is true.
(B) if expression (i + 5) is false.
(C) irrespective of whether (i + 5) is true or false.
(D) will not be evaluated in any case.
Ans: A
In a compound logical expression combined with &&, the second expression is evaluated only if first is evaluated in true.

Q.11 In the for statement: for (exp1; exp2; exp3) { … }
where exp1, exp2 and exp3 are expressions. What is optional?
(A) None of the expressions is optional.
(B) Only exp1 is optional.
(C) Only exp1 and exp3 are optional.
(D) All the expressions are optional.
Ans: D
All the expressions are optional. For (;;) is a valid statement in C.

Q.12 The output of the following code segment will be
char x = ‘B’;
switch (x) {
case ‘A’: printf(“a”);
case ‘B’: printf(“b”);
case ‘C’: printf(“c”);
}
(A) B
(B) b
(C) BC
(D) bc
Ans: D
Since there is no break statement, all the statement after case’B’ are executed.

Q.13 What will be the output of the following code segment?
main( ) {
char s[10];
strcpy(s, “abc”);
printf(“%d %d”, strlen(s), sizeof(s));
}
(A) 3 10
(B) 3 3
(C) 10 3
(D) 10 10
Ans: A
strlen(s) give the length of the string, that is 3 and sizeof(s) give the size of array s that is 10.

Q.14 Which of the following is the odd one out?
(A) j = j + 1;
(B) j =+ 1;
(C) j++;
(D) j += 1;
Ans: B
j=+1 is odd one out as rest all means incrementing the value of variable by 1.

Q.15 Which of the following is true for the statement:
NurseryLand.Nursery.Students = 10;
(A) The structure Students is nested within the structure Nursery.
(B) The structure NurseryLand is nested within the structure Nursery.
(C) The structure Nursery is nested within the structure NurseryLand.
(D) The structure Nursery is nested within the structure Students.
Ans: C
The structure Nursery is nested within the structure NurseryLand.

Q.16 What will be the output of the following code segment, if any?
myfunc ( struct test t) {
strcpy(t.s, “world”);
}
main( ) {
struct test { char s[10]; } t;
strcpy(t.s, “Hello”);
printf(“%s”, t.s);
myfunc(t);
printf(“%s”, t.s);
}
(A) Hello Hello
(B) world world
(C) Hello world
(D) the program will not compile
Ans: D
The program will not compile because undefined symbol s for myfunc( ) function. Structure should be defined before the main and the function where it is called.

Q.17 If a function is declared as void fn(int *p), then which of the following statements is valid to call function fn?
(A) fn(x) where x is defined as int x;
(B) fn(x) where x is defined as int *x;
(C) fn(&x) where x is defined as int *x;
(D) fn(*x) where x is defined as int *x;
Ans: B
Function void fn(int *p) needs pointer to int as argument. When x is defined as int *x, then x is pointer to integer and not *x.

Q.18 What is the following function computing? Assume a and b are positive integers.
int fn( int a, int b) {
if (b == 0)
return b;
else
return (a * fn(a, b - 1));
}
(A) Output will be 0 always
(B) Output will always be b
(C) Computing ab
(D) Computing a + b
Ans: A
The output is always be 0 because b is decremented in recursive function fn each time by 1 till the terminating condition b==0 where it will return 0.

Q.19 What is the output of the following C program?
# include <stdio.h>
main ( )
{
int a, b=0;
static int c [10]={1,2,3,4,5,6,7,8,9,0};
for (a=0; a<10;+ + a)
if ((c[a]%2)= = 0) b+ = c [a];
printf (“%d”, b);
}
(A) 20
(B) 25
(C) 45
(D) 90
Ans: A
printf statement will print b which is sum of the those values from array c which get divided by 2, that is 2+4+6+8=20.

Q.20 If a, b and c are integer variables with the values a=8, b=3 and c=-5. Then what is the
value of the arithmetic expression:
2 * b + 3 * (a-c)
(A) 45
(B) 6
(C) -16
(D) -1
Ans: A
the value of the arithmetic expression is 45 as 2*3+3*(8—5)=6+3*13=6+39=45

Monday, September 28, 2020

Database Systems MCQ

Q.1 The physical location of a record is determined by a mathematical formula that transforms a file key into a record location is :

(A) B-Tree File

(B) Hashed File

(C) Indexed File

(D) Sequential file

Ans: B

 

Q.2 Using Relational Algebra the query that finds customers, who have a balance of over 1000 is

(A) πCustomer_name(s balance >1000(Deposit))

(B) σCustomer_name(Pbalance >1000(Deposit))

(C) πCustomer_name(s balance >1000(Borrow))

(D) σCustomer_name(Pbalance >1000(Borrow))

Ans: A

 

Q.3 A primary key is combined with a foreign key creates

(A) Parent-Child relation ship between the tables that connect them.

(B) Many to many relationship between the tables that connect them.

(C) Network model between the tables that connect them.

(D) None of the above.

Ans: A

 

Q.4 In E-R Diagram derived attribute are represented by

(A) Ellipse

(B) Dashed ellipse

(C) Rectangle

(D) Triangle

Ans B

 

Q.5 Cross Product is a:

(A) Unary Operator

(B) Ternary Operator

(C) Binary Operator

(D) Not an operator

Ans: C

 

Q.6 An instance of relational schema R (A, B, C) has distinct values of A including NULL values. Which one of the following is true?

(A) A is a candidate key

(B) A is not a candidate key

(C) A is a primary Key

(D) Both (A) and (C)

Ans: B

 

Q.7 Consider the join of a relation R with relation S. If R has m tuples and S has n tuples, then the maximum size of join is:

(A) mn

(B) m+n

(C) (m+n)/2

(D) 2(m+n)

Ans: A

 

Q.8 The natural join is equal to :

(A) Cartesian Product

(B) Combination of Union and Cartesian product

(C) Combination of selection and Cartesian product

(D) Combination of projection and Cartesian product

Ans: D

 

Q.9 Which one of the following is not true for a view:

(A) View is derived from other tables.

(B) View is a virtual table.

(C) A view definition is permanently stored as part of the database.

(D) View never contains derived columns.

Ans: C

 

Q.10 A primary key if combined with a foreign key creates

(A) Parent-Child relationship between the tables that connect them.

(B) Many to many relationship between the tables that connect them.

(C) Network model between the tables that connect them.

(D) None of the above.

Ans: A

 

Q.11 In E-R Diagram relationship type is represented by

(A) Ellipse

(B) Dashed ellipse

(C) Rectangle

(D) Diamond

Ans: D

 

Q.12 Hierarchical model is also called

(A) Tree structure

(B) Plex Structure

(C) Normalize Structure

(D) Table Structure

Ans: A

 

Q.13 To delete a particular column in a relation the command used is:

(A) UPDATE

(B) DROP

(C) ALTER

(D) DELETE

Ans: C

 

Q.14 The ______ operator is used to compare a value to a list of literals values that have been specified.

(A) BETWEEN

(B) ANY

(C) IN

(D) ALL

Ans: A

 

Q.15 A logical schema

A) is the entire database

B) is a standard way of organizing information into a accessible part

C) describe how data is actually stored on disk

D) none of these

Ans: D

 

Q.16 A B-tree of order m has maximum of _____________ children

(A) m

(B) m+1

(C) m-1

(D) m/2

Ans: A

 

Q.17 _____________ function divides one numeric expression by another and returns the remainder.

(A) POWER

(B) MOD

(C) ROUND

(D) REMAINDER

Ans: B

 

Q.18 A data manipulation command the combines the records from one or more tables is called

(A) SELECT

(B) PROJECT

(C) JOIN

(D) PRODUCT

Ans: C

 

Q.19 In E-R diagram generalization is represented by

(A) Ellipse

(B) Dashed ellipse

(C) Rectangle

(D) Triangle

Ans: D

 

Q.20 _________ is a virtual table that draws its data from the result of an SQL SELECT statement.

(A) View

(B) Synonym

(C) Sequence

(D) Transaction

Ans: A

 

Q.21 The method of access which uses key transformation is known as

(A) Direct

(B) Hash

(C) Random

(D) Sequential

Ans: B

 

Q.22 A table joined with itself is called

(A) Join

(B) Self Join

(C) Outer Join

(D) Equi Join

Ans: B

 

Q.23 _________ data type can store unstructured data

(A) RAW

(B) CHAR

(C) NUMERIC

(D) VARCHAR

Ans: A

 

Q.24 Which two files are used during operation of the DBMS

(A) Query languages and utilities

(B) DML and query language

(C) Data dictionary and transaction log

(D) Data dictionary and query language

Ans: C

Search Aptipedia