Assignment of objective questions
1. The size of the character pointer (in bytes) in C language is...
a. 1 Byte
b. 2 Byte
c. 4 Byte
d. None of the above
Answer - b. 2 Byte
2. Which is the correct pointer arithmetic for accessing array using pointer
int *p, i, arr[5];
p = arr;
a. p + i * sizeof(<data_type_of_i>);
b. p + i * sizeof(<data_type_of_int>);
c. p + i * sizeof(<data_type_of_pointer>);
d. None of the above
Answer - c. p + i * sizeof(<data_type_of_pointer>);
3. Which of the following is not a unary operator?
a. !
b. ++
c. sizeof()
d. %
Answer - d. %
4. Find the output of the following program(in Turbo)
main()
{
int x = 3, y;
y = 3 + sizeof(4) * x + 5;
printf("x = %d, y = %d", x, y);
}
a. x = 3, y = 5
b. x = 3, y = 14
c. x = 3, y = 10
d. x = 3, y = 20
Answer - b. x = 3, y = 14
5. Predict the output(in Turbo)
int a;
printf("%u", &a + 1);
(Assume address of a is 5000)
a. 5000
b. 5001
c. 5002
d. 5004
Answer - c. 5002
6. Guess the output of the following code
int arr[5], *p;
p = arr;
a. Syntax Error
b. Runtime Error
c. Compile Time Error
d. None of the above
Answer - d. None of the above
7. Does the pointer moves in the following statement?
int arr[5];
int *p = arr;
p++;
a. Yes
b. No
c. Syntax Error
d. Runtime Error
Answer - a. Yes
8. Predict the output (Assume address of arr is 5000 and Compiler is Turbo)
int arr[5] = {10, 20, 30, 40, 50};
printf("%d", *(arr + 3));
a. Syntax Error
b. Runtime Error
c. 5006
d. 40
Answer - d. 40
9. The data passed in the subscript operator during array traversal is known as
a. Index
b. Integer Value
c. Offset Value.
d. None of the above
Answer - c. Offset Value
10. Predict the output (Assume address of arr is 5000 and Compiler is Turbo)
int arr[5] = {10, 20, 30, 40, 50};
printf("%d", 3[arr]);
a. Syntax Error
b. Runtime Error
c. 5006
d. 40
Answer - d. 40
11. Predict the output (Assume address of arr is 5000 and Compiler is Turbo)
int arr[5] = {10, 20, 30, 40, 50};
printf("%d", arr[-1]);
a. Syntax Error
b. Runtime Error
c. 4998
d. Absurd Value
Answer - d. Absurd Value
12. Predict the output (Assume address of arr is 5000 and Compiler is Turbo)
int arr[5] = {10, 20, 30, 40, 50};
arr++;
printf("%d", *arr);
a. Syntax Error
b. L Value Required
c. 20
d. Absurd Value
Answer - b. L Value Required
13. The following statement can also be written as
if(<var> != 0)
{
....
....
}
a. <var>
b. !<var>
c. <var>!
d. None of the above
Answer - a. <var>
14. The following statement can be written as
while(1)
{
...
...
}
a. while(1 = 0)
b. while(1 == 0)
c. while(1 != 0)
d. None of the above
Answer - c. while(1 != 0)
15. Guess the output?
void main()
{
int a = 10;
if(a = 5)
printf("Hi");
else
printf("Bye");
printf("a = %d", a);
getch();
}
a. Compile Time Error
b. Hi5
c. Bye10
d. HiBye10
Answer - b. Hi5
16. Guess the output?
void main()
{
int a = 10;
if(a == 5)
printf("Hi");
else
printf("Bye");
printf("a = %d", a);
getch();
}
a. Compile Time Error
b. Hi5
c. Bye10
d. HiBye10
Answer - c. Bye10
17. The following statement can be written as
if(<var_name> == 0)
{
....
....
}
a. <var_name>
b. !<var_name>
c. <var_name>!
d. None of the above
Answer - b. !<var_name>
18. The following statement can be written as
if(a%2 == 0)
{
....
....
}
a. a%2
b. !a%2
c. a%2!
d. !(a%2)
Answer - d. !(a%2)
19. Predict the output(Assume address of arr is 3000)
int arr[5], *p, *q;
p = arr;
q = &arr[3];
printf("%d", q - p);
a. 6
b. 4
c. 3
d. 2
Answer - d. 2
20. Predict the output
int a, *p;
char c, *q;
p = &a;
q = &c;
printf("%c", p - q);
a. 0
b. Syntax Error
c. Compile Time Error
d. None of the above
Answer - c. Compile Time Error