Pointer
-----------
1 ) Prior to using a pointer variable it should be
a) Declared
b) Initialized
c) Both declared and initalized
d) None of these
2) In C a pointer variable to an integer can be created by the decalaration
a) int p*;
b) int *p;
c) int +p;
d) int $p;
3) What will be the output of the following C code?
void main() {
int a[] = {1,2,3,4,5}, *p;
p = a;
++*p;
printf("%d ", *p);
p += 2;
printf("%d ", *p);
}
a) 2 4
b) 3 4
c) 2 2
d) 2 3
4) What is the output of the following C code?
char *ptr;
char mystring[] = "abcdefg";
ptr = mystring;
ptr += 5;
printf("%s",ptr);
a) fg
b) efg
c) defg
d) cdefg
e) bcdefg
5)Which of the following statements correct about k used in the below statement?
char ****k;
a) k is a pointer to a pointer to a pointer to a char
b) k is a pointer to a pointer to a pointer to a pointer to a char
c) k is a pointer to a char pointer
d) k is a pointer to a pointer to a char
6)Which of these keywords are used for the block to handle the exceptions generated
by try block?
a) try
b) catch
c) throw
d) check
7)What is the output of the below Java code with Exceptions?
public class ExceptionTest1
{
public static void main(String[] args)
{
try
{
int a=9, b=0;
int c = a/b;
System.out.println("Exception occurred.");
}
catch(Exception e)
{
System.out.println("Catching an Exception.");
}
}
}
A)
Exception occurred.
Catching an Exception.
B)
Exception occurred.
C )
Catching an Exception.
D) No output
8)If an exception occurs, all the lines of Java code that is below it stops
executing. State TRUE or FALSE.
A) TRUE
B) FALSE
C) -
D) -
9)Java exceptions are handled by ____.
A) Java Compiler
B) Java Runtime
C) -
D) -
10) What is the output of the below Java code with Exceptions?
public class ExceptionTest2
{
public static void main(String[] args)
{
try
{
int ary[] = {10, 20, 30};
int tempt = ary[4];
}
catch(ArrayIndexOutOfBoundsException e1)
{
System.out.println(e1.getMessage());
}
catch(Exception e2)
{
System.out.println("Some exception");
}
}
}
A)
Index 4 out of bounds for length 3
B)
Index 4 out of bounds for length
Some exception
C)
Some exception
D) No exception occurs
11)Choose the correct way of writing multiple CATCH blocks in Java.
A)
try {
int num = 10/0;
}
catch(Exception e1)
{
System.out.println("EXCEPTION");
}
catch(ArithmeticException e2)
{
System.out.println("ARITHMETIC EXCEPTION");
}
B)
try {
int num = 10/0;
}
catch(ArithmeticException e2)
{
System.out.println("ARITHMETIC EXCEPTION");
}
catch(Exception e1)
{
System.out.println("EXCEPTION");
}
C) -
D) -
12) What is the output of the below java code with exception handling blocks?
public class ExceptionTest4
{
public static void main(String[] args)
{
try
{
}
catch(Exception e)
{
}
finally
{
System.out.println("FINALLY block executed");
}
}
}
A) No output
B) FINALLY block executed
C) Compiler error
D) None
13) What is the output of the below Java code with exception handling blocks?
public class ExceptionTest5
{
public static void main(String[] args)
{
int ary[] = new int[2];
ary[10] = 5;
try
{
int number= 2/0;
}
catch(Exception e)
{
System.out.println("Divide by Zero");
}
finally
{
System.out.println("Inside FINALLY block");
}
}
}
A) Inside FINALLY block
B) Divide by Zero
Inside FINALLY block
C) Compiler error
D) No output
14)Choose which are Java unchecked exceptions below?
A) NullPointerException, ArithmeticException
B) IndexOutOfBoundException, ArrayIndexOutOfBoundsException
C) IllegalArgumentException, StringIndexOutOfBoundsException
D) All the above
15)What will be the output of the program.
void main() {
printf("%d %d", sizeof(int *), sizeof(int **));
}
a) 2, 0
b) 0, 2
c) 2, 2
d) 2, 4
e) 4, 4
16)Find the output of the following program?
void main() {
char *msg = "hi";
printf(msg);
}
a) hi
b) h
c) hi followed by garbage value
d) None of Error
17)#include <stdio.h>
int main()
{
int i = 1024;
for (; i; i >>= 1)
printf("%d " , i);
return 0;
}
18)MCQ 2:
#include <stdio.h>
#define PRINT(i, limit) do{ if(i++ < limit){printf("%d ",i);continue;}}while(0)
int main()
{
int i = 0;
PRINT(i, 3);
return 0;
}
19)MCQ 3:
#include <stdio.h>
int main()
{
int i = 0;
switch (i)
{
case '0': printf("0");
break;
case '1': printf("1");
break;
default: printf("default");
}
return 0;
}
20)MCQ 4:
#include <stdio.h>
int main()
{
int i = 3;
switch (i)
{
case 0+1: printf("0");
break;
default: printf("default");
case 1+2: printf("3");
break;
}
return 0;
}
21)
#include <stdio.h>
#define EVEN 0
#define ODD 1
int main()
{
int i = 3;
switch (i & 1)
{
case EVEN: printf("Even");
break;
case ODD: printf("Odd");
break;
default: printf("Default");
}
return 0;
}
22)
#include <stdio.h>
int main()
{
int i;
if (printf("0"))
i = 3;
else
i = 5;
printf("%d", i);
return 0;
}
23)
#include <stdio.h>
int i;
int main()
{
if (i);
else
printf("Ëlse");
return 0;
}
24)
#include<stdio.h>
int main()
{
int n;
for (n = 9; n ; n--)
printf("n = %d", n--);
return 0;
}
25)How can you write a[i][j][k][l] in equivalent pointer expression?
a) (((***(a+i)+j)+k)+l)
b) ((**(*(a+i)+j)+k)+l)
c) (*(*(*(a+i)+j)+k)+l)
d) *(*(*(*(a+i)+j)+k)+l)
26) What is the output of this C code?
int main() {
int i = 10;
void *p = &i;
printf("%d\n" (int)*p);
return 0;
}
a) Compile time error
b) Segmentation fault/runtime crash
c) 10
d) Undefined behaviour
27)What will be the output of the following C code?
void main() {
char *p;
p = "Hello";
printf("%c\n", *&*p);
}
a) Hello
b) H
c) Some address will be printed
d) None of these
29)Will this program compile?
int main() {
char str[5] = "LetsFind";
return 0;
}
a) True
b) False
30)MCQ 18:
#include <stdio.h>
int main()
{
int x = 3;
if (x == 2); x = 0;
if (x == 3) x++;
else x += 2;
printf("x = %d", x);
return 0;
}
31)What will be the size of the following structure?
#include <stdio.h>
struct temp {
int a[10];
char p;
};
a) 5
b) 11
c) 41
d) 44
32)What is the size of a C structure?
a) C structure is always 128 bytes
b) Size of C structure is the totatl bytes of all elements of structure.
c) Size of C structure is the size of largest elements
d) None of the above
33) Choose a correct statement about C structure?
int main() {
struct ship {
};
return 0;
}
a) It is wrong to define an empty structure
b) Member variables can be added to a structure even after its first definition.
c) There is no use of defining an empty structure
d) None of the above
34)Which of the following structure declaration will throw an error?
a)
struct temp{
}s;
main(){
b)
struct temp{
};
structtemp s;
main(){
c)
struct temp s;
struct temp{
};
main(){
d) None of the mentioned
35)What is actually passed if you pass a structure variable to a function?
a) Copy of structure variable
b) Reference of structure variable
c) Starting address of structure variable
d) Ending address of structure variable
36)Which properly declares a variable of struct foo?
a) struct foo;
b) struct foo var;
c) foo;
d) int foo;
37)Can the following C code be compiled successfully?
#include <stdio.h>
struct p {
int k;
char c;
float f;
}
int main() {
struct p x = {.c = 97,.f = 3,.k = 1};
printf("%f\n", x.f);
}
a) Yes
b) No
c) Depends on the standard
d) Depends on the platform
38)The correct syntax to access the member of the ith structure in the array of
structures is?
struct temp {
int b;
}s[50];
a) s.b.[i];
b) s.[i].b;
c) s.b[i];
d) s[i].b;
39)Comment on the output of hte following C code.
#include <stdio.h>
struct temp {
int a;
int b;
int c;
};
main() {
struct temp p[] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
}
a) No Compile time error, generates an array of structure of size 3
b) No Compile time error, generates an array of structure of size 9
c) Compile time error, illegal declaration of a multidimensional array
d) Compile time error, illegal assignment to members of structure
40)Which of the following cannot be a structure member?
a) Another structure
b) Function
c) Array
d) None of the mentioned
4.What will be the output of the following pseudocode?
Integer a, b, c
Set a=1, b=7 ,c=10
f (b>a)
c=2&a 1 0
c=0; 0 1
End if
if ((a & c & b)<(c + b - a))
c=(a^ 6)^c 0 0 1
1 1 0 1 1 1
End if 0 0 0
Print a + b + c
[NOTE:- &:bitwise AND-The bitwise AND operator(&) compares each bit of the first
operand to the corresponding bit of the second operand. If both bits are 1, the
corresponding result bit is set to 1. Otherwise, the corresponding result bit is
set to 0.]
[^ is the bitwise exclusive OR operator that compares each bit of its first operand
to the corresponding bit of its second operand. If one bit is 0 and the other bit
is 1 , the corresponding result bit is set to 1.Otherwise, the corresponding result
bit is dset to 0.]
12
15
20
29
5.Consider two arrays, X and Y:
X= {1,2,3}
Y= {1,2,3}
An array Z is formed by adding corresponding elements of array X and Y. Now, an
array W is formed by adding corresponding elements of array X,Y and Z. What will
be the sum of the last second element of W?
None of the mentioned options
12
16
20
In Database Management System (DBMS), we can say that each record is also called a
tuple and rows. And each column is called fields and attributes.