Pointer Test I
Ques. 1: If a variable is a pointer to a structure, then what is the operator to
access data members of the structure through the pointer variable?
A. dot operator(.)
B. address operator(&)
C. indirection operator(*)
D. -> operator
Ques. 2: What will be the output result of below code?
#include
main()
{
float x = 13.442;
int *w = x;
printf("%d",*w);
}
A. 10
B. 10.2
C. error: incompatible type
D. no output
Ques. 3: The operator used to access the value of variable at address stored in a pointer variable is?
A. indirection operator(*)
B. address operator(&)
C. dot operator(.)
D. logical And operator(&&)
Ques. 4: What will be the output of following code assuming that array begins at location 1002?
#include
main()
{
int m[5] = {5, 6,7, 8, 9};
int *s = m;
printf("%d\t%d\t%d\t%d\t",*s,0[m],m,s);
}
A. error
B. 5 5 1002 1002
C. 5 0 1002 0
D. 5 5 0 1002
Ques. 5: What will be the output of following code?
#include
int iarr[] = {1,2,3};
main()
{
int *qptr;
qptr = iarr;
qptr = qptr+3;
printf("%d",*qptr);
}
A. error
B. 3
C. 2
D. garbage value
Ques. 6: What is the output of below code?
#include
void main()
{
int const *ptr = 5;
printf("%d", ++(*ptr));
}
A. error
B. 5
C. 6
D. print address of p
Ques 7: What will be the output of following code?
#include
main()
{
struct std
{
int a = 3;
char str[] = "hello";
};
struct std *ptr;
printf("%d", ptr->x);
printf("%s", ptr->name);
}
A. 3 hello
B. garbage value
C. error in declaration of pointer to structure.
D. error because of initializing variables in structure declaration
Ques. 8: What will be the output of following code?
#include
main()
{
register a = 5;
char b[] = "welcome";
printf("%s %d", b, a);
}
A. error
B. welcome 5
C. welcome
D. none of the above
Ques. 9: What is the size of char on 32-bit machine?
A. 1
B. 2
C. 4
D. 8
Ques. 10: Is the NULL pointer same as an uninitialised pointer?
A. Yes
B. No
Ques.11: Which of the statement is correct about the code?
int add(int, int);
int (*p)(int, int);
p = add;
A. p is a pointer to a function add which return integer
B. p is a function which return integer pointer
C. p is a function similar to add function
D. none of the above
Ques. 12: What will be the output of following code?
#include
int fun(int *m,int *n)
{
*m = *m+*n;
*n = *m-*n;
*m = *m-*n;
}
main()
{
int a = 10,b = 20;
fun(&a,&b);
printf("a= %d b = %d\n", a, b);
}
A. x=10 y=20 B. x=20 y=10
C. 20 10 D. error
ques 13: What will be the output of the C program?
#include
int main(){
int g = 435;
char *mptr;
mptr = (char *)&g;
printf("%d ",*mptr);
return 0;
}
A. -77
B. Run Time Error
C. Garbage value
D. Compile Time Error
ques 14: What will be the output of the C program?
#include
int main(){
int h = 3;
int *m;
int **p;
m = &h;
p = &m;
p++;
printf("%d ",**p);
return 0;
}
A. Garbage value
B. Compilation Error
C. Run time error
D. Linker Error
Ques. 15. What will be the output of the C program?
#include
int main(){
int a = 24;
int *b;
b = &a;
b++;
printf("%d ",*b);
}
A. Linker Error
B. Run time error
C. Compilation Error
D. Garbage value
Ques 16. What will be the output of the C program?
#include
#include
int main(){
char *str = "welcome";
char b[22];
strcpy(b, "ptinstitute");
printf("\n%s %s",str, b);
return 0;
}
A. welcome ptinstitute
B. Run time error
C. Compilation Error
D. Garbage value
Ques 17. What will be the output of the following C program?
#include
#include
int main(){
char *str1 = "hello";
char str2[22];
*str1 = "world";
printf("\n%s %s",str1, str2);
return 0;
}
A. Linker Error
B. Run time error
C. Compilation Error
D. Garbage value
Ques 18. What will be the output of the C program?
#include
int main()
{
char *str = "welcometoworld";
printf(str + 4);
return 0;
}
A. ometoworld
B. metoworld
C. welc
D. welco
Ques 19. What will be the output of the C program?
#include
int main()
{
char *qptr = "goodmorning";
printf("%c\n",*&*qptr);
return 0;
}
A. Address of g
B. Compilation Error
C. g
D. Run time error
Ques 20. What will be the output of the C program?
#include
#include
int main(){
register y = 23;
int *q;
q = &y;
printf("%u",q);
return 0;
}
A. Address of a
B. Run time error
C. Garbage value
D. Compile time error
Answers
1. D. -> operator
2. C. error: incompatible type
3. A. indirection operator(*)
4. B. 5 5 1002 1002
5. D. garbage value
6. A. error // incrementing the const pointer data *ptr is not allowed
7. D. error because of initializing variables in structure declaration
8. B. welcome 5
9. A. 1
10. B. No // NULL pointer pointing to address 0x0, uninitialised pointer pointing to some unknown location.
11. A. p is a pointer to a function add which return integer
12. B. x=20 y=10
13. A. -77
14. C. Run time error // p is pointer to m, m is a pointer to h. on incrementing the p ,
//it will points to some garbage value, so it is a runtime error.
15. D. Garbage value // b is pointer variable pionting to variable a. on incrementing b
// it points to other location which is not initialised hence gives garbage value.
16. A. welcome ptinstitute
17. C. Compilation Error // str1 is a ponter to character variable, it can be initialised only at declaration.
18. A. ometoworld
19. C. g
20. D. Compile time error // y is a register variable, q is requesting the register address.