Faq On Pointers
Faq On Pointers
Faq On Pointers
A. int x;
B. int &x;
C. ptr x;
D. int *x;
2. Which of the following gives the memory address of integer variable a?
A. *a;
B. a;
C. &a;
D. address(a);
3. Which of the following gives the memory address of a variable pointed to by pointer a?
A. a;
B. *a;
C. &a;
D. address(a);
4. Which of the following gives the value stored at the address pointed to by pointer a?
A. a;
B. val(a);
C. *a;
D. &a;
5. Which of the following is the proper keyword to allocate memory in C?
A. new
B. malloc
C. create
D. value
6. Which of the following is the proper keyword to deallocate memory?
A. free
B. delete
C. clear
D. remove
7. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. char *p = NULL;
5. char *q = 0;
6. if (p)
7. printf(" p ");
8. else
9. printf("nullp");
10. if (q)
11. printf("q\n");
12. else
13. printf(" nullq\n");
14. }
a) nullp nullq
b) Depends on the compiler
c) x nullq where x can be p or nullp depending on the value of NULL
d) p q
8. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 10;
5. void *p = &i;
6. printf("%d\n", (int)*p);
7. return 0;
8. }
a) Compile time error
b) Segmentation fault/runtime crash
c) 10
d) Undefined behaviour
9. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 10;
5. void *p = &i;
6. printf("%f\n", *(float*)p);
7. return 0;
8. }
a) Compile time error
b) Undefined behaviour
c) 10
d) 0.000000
10. What is the output of this C code?
1. #include <stdio.h>
2. int *f();
3. int main()
4. {
5. int *p = f();
6. printf("%d\n", *p);
7. }
8. int *f()
9. {
10. int *j = (int*)malloc(sizeof(int));
11. *j = 10;
12. return j;
13. }
a) 10
b) Compile time error
c) Segmentation fault/runtime crash since pointer to local variable is returned
d) Undefined behaviour
11. What is the output of this C code?
1. #include <stdio.h>
2. int *f();
3. int main()
4. {
5. int *p = f();
6. printf("%d\n", *p);
7. }
8. int *f()
9. {
10. int j = 10;
11. return &j;
12. }
a) 10
b) Compile time error
c) Segmentation fault/runtime crash
d) Undefined behaviour
12. Comment on the following pointer declaration?
int *ptr, p;
a) ptr is a pointer to integer, p is not
b) ptr and p, both are pointers to integer
c) ptr is a pointer to integer, p may or may not be
d) ptr and p both are not pointers to integer
13. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. int *ptr, a = 10;
5. ptr = &a;
6. *ptr += 1;
7. printf("%d,%d/n", *ptr, a);
8. }
a) 10,10
b) 10,11
c) 11,10
d) 11,11
14. Comment on the following?
const int *ptr;
a) You cannot change the value pointed by ptr
b) You cannot change the pointer ptr itself
c) Both (a) and (b)
d) You can change the pointer as well as the value pointed by it
15. Which is an indirection operator among the following?
a) &
b) *
c) ->
d) .
16. Which of the following does not initialize ptr to null (assuming variable declaration of a as int
a=0;?
a) int *ptr = &a;
b) int *ptr = &a &a;
c) int *ptr = a a;
d) All of the mentioned
17. What is the output of this C code?
1. #include <stdio.h>
2. int x = 0;
3. void main()
4. {
5. int *ptr = &x;
6. printf("%p\n", ptr);
7. x++;
8. printf("%p\n ", ptr);
9. }
a) Same address
b) Different address
c) Compile time error
d) Varies
18. What is the output of this C code?
1. #include <stdio.h>
2. int x = 0;
3. void main()
4. {
5. int *const ptr = &x;
6. printf("%p\n", ptr);
7. ptr++;
8. printf("%p\n ", ptr);
9. }
a) 0 1
b) Compile time error
c) 0xbfd605e8 0xbfd605ec
d) 0xbfd605e8 0xbfd605e8
19. What is the output of this C code?
1. #include <stdio.h>
2. void main()
3. {
4. int x = 0;
5. int *ptr = &x;
6. printf("%p\n", ptr);
7. ptr++;
8. printf("%p\n ", ptr);
9. }
a) 0xbfd605e8 0xbfd605ec
b) 0xbfd605e8 0cbfd60520
c) 0xbfd605e8 0xbfd605e9
d) Run time error
20. What is the output of this C code?
1. #include <stdio.h>
2. void main()
3. {
4. int x = 0;
5. int *ptr = &5;
6. printf("%p\n", ptr);
7. }
a) 5
b) Address of 5
c) Nothing
d) Compile time error
21. What is the output of this C code?
1. #include <stdio.h>
2. void main()
3. {
4. int x = 0;
5. int *ptr = &x;
6. printf("%d\n", *ptr);
7. }
a) Address of x
b) Junk value
c) 0
d) Run time error
22. What is the output of this C code?
1. #include <stdio.h>
2. void foo(int*);
3. int main()
4. {
5. int i = 10;
6. foo((&i)++);
7. }
8. void foo(int *p)
9. {
10. printf("%d\n", *p);
11. }
a) 10
b) Some garbage value
c) Compile time error
d) Segmentation fault/code crash
23. What is the output of this C code?
1. #include <stdio.h>
2. void foo(int*);
3. int main()
4. {
5. int i = 10, *p = &i;
6. foo(p++);
7. }
8. void foo(int *p)
9. {
10. printf("%d\n", *p);
11. }
a) 10
b) Some garbage value
c) Compile time error
d) Segmentation fault
24. What is the output of this C code?
1. #include <stdio.h>
2. void foo(float *);
3. int main()
4. {
5. int i = 10, *p = &i;
6. foo(&i);
7. }
8. void foo(float *p)
9. {
10. printf("%f\n", *p);
11. }
a) 10.000000
b) 0.000000
c) Compile time error
d) Undefined behaviour
25. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 97, *p = &i;
5. foo(&i);
6. printf("%d ", *p);
7. }
8. void foo(int *p)
9. {
10. int j = 2;
11. p = &j;
12. printf("%d ", *p);
13. }
a) 2 97
b) 2 2
c) Compile time error
d) Segmentation fault/code crash
26. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 97, *p = &i;
5. foo(&p);
6. printf("%d ", *p);
7. return 0;
8. }
9. void foo(int **p)
10. {
11. int j = 2;
12. *p = &j;
13. printf("%d ", **p);
14. }
a) 2 2
b) 2 97
c) Undefined behaviour
d) Segmentation fault/code crash
27. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 11;
5. int *p = &i;
6. foo(&p);
7. printf("%d ", *p);
8. }
9. void foo(int *const *p)
10. {
11. int j = 10;
12. *p = &j;
13. printf("%d ", **p);
14. }
a) Compile time error
b) 10 10
c) Undefined behaviour
d) 10 11
28. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 10;
5. int *p = &i;
6. foo(&p);
7. printf("%d ", *p);
8. printf("%d ", *p);
9. }
10. void foo(int **const p)
11. {
12. int j = 11;
13. *p = &j;
14. printf("%d ", **p);
15. }
a) 11 11 11
b) 11 11 Undefined-value
c) Compile time error
d) Segmentation fault/code-crash
29. What is the output of the code below?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 10;
5. int *const p = &i;
6. foo(&p);
7. printf("%d\n", *p);
8. }
9. void foo(int **p)
10. {
11. int j = 11;
12. *p = &j;
13. printf("%d\n", **p);
14. }
a) 11 11
b) Undefined behaviour
c) Compile time error
d) Segmentation fault/code-crash
30. Which of the following are correct syntaxes to send an array as a parameter to function:
a) func(&array);
b) func(array);
c) func(*array);
d) func(array[size]);
31. What is the output of this C code?
1. #include <stdio.h>
2. void m(int *p, int *q)
3. {
4. int temp = *p; *p = *q; *q = temp;
5. }
6. void main()
7. {
8. int a = 6, b = 5;
9. m(&a, &b);
10. printf("%d %d\n", a, b);
11. }
a) 5 6
b) 6 5
c) 5 5
d) 6 6
32. What is the output of this C code?
1. #include <stdio.h>
2. void m(int *p)
3. {
4. int i = 0;
5. for(i = 0;i < 5; i++)
6. printf("%d\t", p[i]);
7. }
8. void main()
9. {
10. int a[5] = {6, 5, 3};
11. m(&a);
12. }
a) 0 0 0 0 0
b) 6 5 3 0 0
c) Run time error
d) 6 5 3 junk junk
33. What is the output of this C code?
1. #include <stdio.h>
2. void main()
3. {
4. int a[3] = {1, 2, 3};
5. int *p = a;
6. printf("%p\t%p", p, a);
7. }
a) Same address is printed.
b) Different address is printed.
c) Compile time error
d) Nothing
34. What is the output of this C code?
1. #include <stdio.h>
2. void main()
3. {
4. char *s = "hello";
5. char *p = s;
6. printf("%p\t%p", p, s);
7. }
a) Different address is printed
b) Same address is printed
c) Run time error
d) Nothing
35. What is the output of this C code?
1. #include <stdio.h>
2. void main()
3. {
4. char *s= "hello";
5. char *p = s;
6. printf("%c\t%c", p[0], s[1]);
7. }
a) Run time error
b) h h
c) h e
d) h l
36. What is the output of this C code?
1. #include <stdio.h>
2. void main()
3. {
4. char *s= "hello";
5. char *p = s;
6. printf("%c\t%c", *(p + 3), s[1]);
7. }
a) h e
b) l l
c) l o
d) l e
37. What is the output of this C code?
1. #include <stdio.h>
2. void main()
3. {
4. char *s= "hello";
5. char *p = s;
6. printf("%c\t%c", 1[p], s[1]);
7. }
a) h h
b) Run time error
c) l l
d) e e
38. What is the output of the code given below?
1. #include <stdio.h>
2. void foo( int[] );
3. int main()
4. {
5. int ary[4] = {1, 2, 3, 4};
6. foo(ary);
7. printf("%d ", ary[0]);
8. }
9. void foo(int p[4])
10. {
11. int i = 10;
12. p = &i;
13. printf("%d ", p[0]);
14. }
a) 10 10
b) Compile time error
c) 10 1
d) Undefined behaviour
39. What is the output of the code given below?
1. #include <stdio.h>
2. int main()
3. {
4. int ary[4] = {1, 2, 3, 4};
5. int *p = ary + 3;
6. printf("%d\n", p[-2]);
7. }
a) 1
b) 2
c) Compile time error
d) Some garbage value
40. What is the output of the code given below?
1. #include <stdio.h>
2. int main()
3. {
4. int ary[4] = {1, 2, 3, 4};
5. int *p = ary + 3;
6. printf("%d %d\n", p[-2], ary[*p]);
7. }
a) 2 3
b) Compile time error
c) 2 4
d) 2 somegarbagevalue
41. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. int ary[4] = {1, 2, 3, 4};
5. printf("%d\n", *ary);
6. }
a) 1
b) Compile time error
c) Some garbage value
d) Undefined variable
42. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. const int ary[4] = {1, 2, 3, 4};
5. int *p;
6. p = ary + 3;
7. *p = 5;
8. printf("%d\n", ary[3]);
9. }
a) 4
b) 5
c) Compile time error
d) 3
43. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. double *ptr = (double *)100;
5. ptr = ptr + 2;
6. printf("%u", ptr);
7. }
a) 102
b) 104
c) 108
d) 116
44. Comment on the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. int *p = (int *)2;
5. int *q = (int *)3;
6. printf("%d", p + q);
7. }
a) 2
b) 3
c) 5
d) Compile time error
45. Which of the following operand can be applied to pointers p and q?
(Assuming initialization as int *a = (int *)2; int *b = (int *)3;)
a) a + b
b) a b
c) a * b
d) a / b
46. What is the size of *ptr in a 32-bit machine, (assuming initialization as int *ptr = 10;)?
a) 1
b) 2
c) 4
d) 8
47. Which of following logical operation can be applied to pointers?
(Assuming initialization int *a = 2; int *b = 3;)
a) a | b
b) a ^ b
c) a & b
d) None of the mentioned
48. What is the output of this C code?
1. #include <stdio.h>
2. void main()
3. {
4. char *s = "hello";
5. char *p = s;
6. printf("%c\t%c", *(p + 1), s[1]);
7. }
a) h e
b) e l
c) h h
d) e e
49. What is the output of this C code?
1. #include <stdio.h>
2. void main()
3. {
4. char *s = "hello";
5. char *p = s;
6. printf("%c\t%c", *p, s[1]);
7. }
a) e h
b) Compile time error
c) h h
d) h e
50. What is the output of this C code?
1. #include <stdio.h>
2. void main()
3. {
4. char *s = "hello";
5. char *n = "cjn";
6. char *p = s + n;
7. printf("%c\t%c", *p, s[1]);
8. }
a) h e
b) Compile time error
c) c o
d) h n
51. What is the output of this C code?
1. #include <stdio.h>
2. void main()
3. {
4. char *s = "hello";
5. char *p = s * 3;
6. printf("%c\t%c", *p, s[1]);
7. }
a) h e
b) l e
c) Compile time error
d) l h
52. What is the output of this C code?
1. #include <stdio.h>
2. void main()
3. {
4. char *s= "hello";
5. char *p = s + 2;
6. printf("%c\t%c", *p, s[1]);
7. }
a) l e
b) h e
c) l l
d) h l
53. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. void *p;
5. int a[4] = {1, 2, 3, 8};
6. p = &a[3];
7. int *ptr = &a[2];
8. int n = p - ptr;
9. printf("%d\n", n);
10. }
a) 1
b) Compile time error
c) Segmentation fault
d) 4
54. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. void *p;
5. int a[4] = {1, 2, 3, 4};
6. p = &a[3];
7. int *ptr = &a[2];
8. int n = (int*)p - ptr;
9. printf("%d\n", n);
10. }
a) 1
b) Compile time error
c) Segmentation fault
d) 4
55. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. int a[4] = {1, 2, 3, 4};
5. int b[4] = {1, 2, 3, 4};
6. int n = &b[3] - &a[2];
7. printf("%d\n", n);
8. }
a) -3
b) 5
c) 4
d) Compile time error
56. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. int a[4] = {1, 2, 3, 4};
5. int *p = &a[1];
6. int *ptr = &a[2];
7. ptr = ptr * 1;
8. printf("%d\n", *ptr);
9. }
a) 2
b) 1
c) Compile time error
d) Undefined behaviour
57. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. int a[4] = {1, 2, 3, 4};
5. int *ptr = &a[2];
6. float n = 1;
7. ptr = ptr + n;
8. printf("%d\n", *ptr);
9. }
a) 4
b) 3
c) Compile time error
d) Undefined behaviour
58. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. int a[4] = {1, 2, 3, 4};
5. void *p = &a[1];
6. void *ptr = &a[2];
7. int n = 1;
8. n = ptr - p;
9. printf("%d\n", n);
10. }
a) 1
b) 4
c) Compile time error
d) Depends on the compiler
59. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. char *str = "hello, world\n";
5. char *strc = "good morning\n";
6. strcpy(strc, str);
7. printf("%s\n", strc);
8. return 0;
9. }
a) hello, world
b) Crash/segmentation fault
c) Undefined behaviour
d) Run time error
60. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. char *str = "hello world";
5. char strc[] = "good morning india\n";
6. strcpy(strc, str);
7. printf("%s\n", strc);
8. return 0;
9. }
a) hello world
b) hello worldg india
c) Compile time error
d) Undefined behaviour
61. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. char *str = "hello, world!!\n";
5. char strc[] = "good morning\n";
6. strcpy(strc, str);
7. printf("%s\n", strc);
8. return 0;
9. }
a) hello, world!!
b) Compile time error
c) Undefined behaviour
d) Segmenation fault
62. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. char *str = "hello, world\n";
5. str[5] = '.';
6. printf("%s\n", str);
7. return 0;
8. }
a) hello. world
b) hello, world
c) Compile error
d) Segmentation fault
63. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. char str[] = "hello, world";
5. str[5] = '.';
6. printf("%s\n", str);
7. return 0;
8. }
a) hello. world
b) hello, world
c) Compile error
d) Segmentation fault
64. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. char *str = "hello world";
5. char strary[] = "hello world";
6. printf("%d %d\n", sizeof(str), sizeof(strary));
7. return 0;
8. }
a) 11 11
b) 12 12
c) 4 12
d) 4 11
65. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. char *str = "hello world";
5. char strary[] = "hello world";
6. printf("%d %d\n", strlen(str), strlen(strary));
7. return 0;
8. }
a) 11 11
b) 12 11
c) 11 12
d) x 11 where x can be any positive integer.
66. What is the output of this C code?
1. #include <stdio.h>
2. void f(char *k)
3. {
4. k++;
5. k[2] = 'm';
6. printf("%c\n", *k);
7. }
8. void main()
9. {
10. char s[] = "hello";
11. f(s);
12. }
a) l
b) e
c) h
d) o
67. What is the output of this C code?
1. #include <stdio.h>
2. void fun(char *k)
3. {
4. printf("%s", k);
5. }
6. void main()
7. {
8. char s[] = "hello";
9. fun(s);
10. }
a) hello
b) Run time error
c) Nothing
d) h
68. Comment on the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. char *str = "This" //Line 1
5. char *ptr = "Program\n"; //Line 2
6. str = ptr; //Line 3
7. printf("%s, %s\n", str, ptr); //Line 4
8. }
a) Memory holding this is cleared at line 3
b) Memory holding this loses its reference at line 3
c) You cannot assign pointer like in Line 3
d) Output will be This, Program
69. What type initialization is needed for the segment ptr*3+ = 3; to work?
a) char *ptr = Hello!;
b) char ptr*+ = Hello!;
c) Both (a) and (b)
d) None of the mentioned
70. The syntax for constant pointer to address (i.e., fixed pointer address) is:
a) const <type> * <name>
b) <type> * const <name>
c) <type> const * <name>
d) Both (a) and (c)
71. Comment on the output of this C code?
1. #include <stdio.h>
2. int add(int a, int b)
3. {
4. return a + b;
5. }
6. int main()
7. {
8. int (*fn_ptr)(int, int);
9. fn_ptr = add;
10. printf("The sum of two numbers is: %d", (int)fn_ptr(2, 3));
11. }
a) Compile time error, declaration of a function inside main.
b) Compile time error, no definition of function fn_ptr.
c) Compile time error, illegal application of statement fn_ptr = add.
d) No Run time error, output is 5.
72. The correct way to declare and assign a function pointer is done by:
(Assuming the function to be assigned is int multi(int, int);)
a) int (*fn_ptr)(int, int) = multi;
b) int *fn_ptr(int, int) = multi;
c) int *fn_ptr(int, int) = &multi;
d) Both (b) & (c)
73. Calling a function f with a an array variable a[3] where a is an array, is equivalent to
a) f(a[3])
b) f(*(a + 3))
c) f(3[a])
d) All of the mentioned
74. What is the output of this C code?
1. #include <stdio.h>
2. void f(char *k)
3. {
4. k++;
5. k[2] = 'm';
6. }
7. void main()
8. {
9. char s[] = "hello";
10. f(s);
11. printf("%c\n", *s);
12. }
a) h
b) e
c) m
d) o;
75.What is the output of this C code?
1. #include <stdio.h>
2. void main()
3. {
4. char s[] = "hello";
5. s++;
6. printf("%c\n", *s);
7. }
a) Compile time error
b) h
c) e
d) o
76. To declare a 3 dimension array using pointers, which of the following is the correct syntax:
a) char *a[][];
b) char **a[];
c) char ***a;
d) All of the mentioned
77. Comment on the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. char *a = {"p", "r", "o", "g", "r", "a", "m"};
5. printf("%s", a);
6. }
a) Output will be program
b) Output will be p
c) No output
d) Compile-time error
78. An array of strings can be initialized by:
a) char *a*+ = ,Hello, World-;
b) char *a*+ = ,Hello, Worlds-;
c) char *b = Hello;
char *c = World;
char *a[] = {b, c};
d) All of the mentioned.
79. What is the output of this C code?
1. #include <stdio.h>
2. void main()
3. {
4. char *a[10] = {"hi", "hello", "how"};
5. int i = 0;
6. for (i = 0;i < 10; i++)
7. printf("%s", *(a[i]));
8. }
a) Segmentation fault
b) hi hello how followed by 7 null values
c) 10 null values
d) depends on compiler
80. What is the output of this C code?
1. #include <stdio.h>
2. void main()
3. {
4. char *a[10] = {"hi", "hello", "how"};
5. int i = 0, j = 0;
6. a[0] = "hey";
7. for (i = 0;i < 10; i++)
8. printf("%s\n", a[i]);
9. }
a) hi hello how Segmentation fault
b) hi hello how followed by 7 null values
c) hey hello how Segmentation fault
d) Depends on compiler
81. What is the output of this C code?
1. #include <stdio.h>
2. void main()
3. {
4. char *a[10] = {"hi", "hello", "how"};
5. printf("%d\n", sizeof(a));
6. }
a) 10
b) 13
c) Run time error
d) 40
82. What is the output of this C code?
1. #include <stdio.h>
2. void main()
3. {
4. char *a[10] = {"hi", "hello", "how"};
5. printf("%d\n", sizeof(a[1]));
6. }
a) 6
b) 4
c) 5
d) 3
83. What is the output of this C code?
1. #include <stdio.h>
2. void main()
3. {
4. char *a[10] = {"hi", "hello", "how"};
5. int i = 0;
6. for (i = 0;i < 10; i++)
7. printf("%s", a[i]);
8. }
a) hi hello how Segmentation fault
b) hi hello how null
c) hey hello how Segmentation fault
d) hi hello how followed by 7 nulls
84. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. char *p[1] = {"hello"};
5. printf("%s", (p)[0]);
6. return 0;
7. }
a) Compile time error
b) Undefined behaviour
c) hello
d) None of the mentioned
85. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. char **p = {"hello", "hi", "bye"};
5. printf("%s", (p)[0]);
6. return 0;
7. }
a) Compile time error
b) Undefined behaviour
c) hello
d) Address of hello
86. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0, j = 1;
5. int *a[] = {&i, &j};
6. printf("%d", (*a)[0]);
7. return 0;
8. }
a) Compile time error
b) Undefined behaviour
c) 0
d) Some garbage value
87. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0, j = 1;
5. int *a[] = {&i, &j};
6. printf("%d", *a[0]);
7. return 0;
8. }
a) Compile time error
b) Undefined behaviour
c) 0
d) Some garbage value
88. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0, j = 1;
5. int *a[] = {&i, &j};
6. printf("%d", (*a)[1]);
7. return 0;
8. }
a) Compile time error
b) Undefined behaviour
c) 1
d) Some garbage value
89. Which of the following are generated from char pointer?
a) char *string = Hello.;
b) char *string;
scanf(%s, string);
c) char string*+ = Hello.;
d) Both (a) and (c).
90. Which of the following declaration are illegal?
a) int a[][] = {{1, 2, 3}, {2, 3, 4, 5}};
b) int *a[] = {{1, 2, 3}, {2, 3, 4, 5}};
c) int a[4][4] = {{1, 2, 3}, {2, 3, 4, 5}};
d) Both (a) and (b).
91. int *b[10]; which is true for b
a) The definition only allocates 10 pointers and does not initialize them
b) Initialization must be done explicitly
c) Both a and b
d) Error
92. What is the output of the code given below?
1. #include <stdio.h>
2. int main()
3. {
4. char *a[1] = {"hello"};
5. printf("%s", a[0]);
6. return 0;
7. }
a) Compile time error
b) hello
c) Undefined behaviour
d) hellon
93. What is the output of this C code (considering sizeof char is 1 and pointer is 4)?
1. #include <stdio.h>
2. int main()
3. {
4. char *a[2] = {"hello", "hi"};
5. printf("%d", sizeof(a));
6. return 0;
7. }
a) 9
b) 4
c) 8
d) 10
94. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. char a[2][6] = {"hello", "hi"};
5. printf("%d", sizeof(a));
6. return 0;
7. }
a) 9
b) 12
c) 8
d) 10
95. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. char a[2][6] = {"hello", "hi"};
5. printf("%s", *a + 1);
6. return 0;
7. }
a) hello
b) hi
c) ello
d) ello hi
96. What is the output of this C code?
1. #include <stdio.h>
2. int main()
3. {
4. char *a[2] = {"hello", "hi"};
5. printf("%s", *(a + 1));
6. return 0;
7. }
a) hello
b) ello
c) hi
d) ello hi
97. Advantage of a multi-dimension array over pointer array.
a) Pre-defined size.
b) Input can be taken from user.
c) Faster Access.
d) All of the mentioned
98. Which of the following operation is possible using a pointer char?
(Assuming declaration char *a;)
a) Input via %s
b) Generation of multidimensional array
c) Changing address to point at another location
d) All of the mentioned
99. Comment on the following two operations?
int *a[] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 1
int b[4][4] = {{1, 2, 3}, {1, 2, 3, 4}};//- 2
a) 1 will work, 2 will not
b) 1 and 2, both will work
c) 1 wont work, 2 will work
d) Neither of them will work
100. Comment on the following two operations?
int *a[] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 1
int b[][] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 2
a) 1 works, 2 doesnt
b) 2 works, 1 doesnt
c) Both of them work
d) Neither of them work
101. Which function is not called in the following program?
1. #include <stdio.h>
2. void first()
3. {
4. printf("first");
5. }
6. void second()
7. {
8. first();
9. }
10. void third()
11. {
12. second();
13. }
14. void main()
15. {
16. void (*ptr)();
17. ptr = third;
18. ptr();
19. }
a) Function first
b) Function second
c) Function third
d) None of the mentioned
102. How to call a function without using the function name to send parameters?
a) typedefs
b) Function pointer
c) Both (a) and (b)
d) None of the mentioned
103. Correct syntax to pass a Function Pointer as an argument
a) void pass(int (*fptr)(int, float, char)){}
b) void pass(*fptr(int, float, char)){}
c) void pass(int (*fptr)){}
d) void pass(*fptr){}
104. Which of the following is not possible in C?
a) Array of function pointer
b) Returning a function pointer
c) Comparison of function pointer
d) None of the mentioned
105. What is the output of this C code?
1. #include <stdio.h>
2. void first()
3. {
4. printf("Hello World");
5. }
6. void main()
7. {
8. void *ptr() = first;
9. ptr++
10. ptr();
11. }
a) Illegal application of ++ to void data type
b) pointer function initialized like a variable
c) Both (a) and (b)
d) None of the mentioned
106. What is the output of this C code?
1. #include <stdio.h>
2. int mul(int a, int b, int c)
3. {
4. return a * b * c;
5. }
6. void main()
7. {
8. int (*function_pointer)(int, int, int);
9. function_pointer = mul;
10. printf("The product of three numbers is:%d",
11. function_pointer(2, 3, 4));
12. }
a) The product of three numbers is:24
b) Run time error
c) Nothing
d) Varies
107. What is the output of this C code?
1. #include <stdio.h>
2. int mul(int a, int b, int c)
3. {
4. return a * b * c;
5. }
6. void main()
7. {
8. int (function_pointer)(int, int, int);
9. function_pointer = mul;
10. printf("The product of three numbers is:%d",
11. function_pointer(2, 3, 4));
12. }
a) The product of three numbers is:24
b) Compile time error
c) Nothing
d) Varies
108. What is the output of this C code?
1. #include <stdio.h>
2. void f(int (*x)(int));
3. int myfoo(int);
4. int (*fooptr)(int);
5. int ((*foo(int)))(int);
6. int main()
7. {
8. fooptr = foo(0);
9. fooptr(10);
10. }
11. int ((*foo(int i)))(int)
12. {
13. return myfoo;
14. }
15. int myfoo(int i)
16. {
17. printf("%d\n", i + 1);
18. }
a) 10
b) 11
c) Compile time error
d) Undefined behaviour
109. What is the output of this C code?
1. #include <stdio.h>
2. int mul(int a, int b, int c)
3. {
4. return a * b * c;
5. }
6. void main()
7. {
8. int *function_pointer;
9. function_pointer = mul;
10. printf("The product of three numbers is:%d",
11. function_pointer(2, 3, 4));
12. }
a) The product of three numbers is:24
b) Compile time error
c) Nothing
d) Varies
110. What is the output of this C code?
1. #include <stdio.h>
2. int sub(int a, int b, int c)
3. {
4. return a - b - c;
5. }
6. void main()
7. {
8. int (*function_pointer)(int, int, int);
9. function_pointer = ⊂
10. printf("The difference of three numbers is:%d",
11. (*function_pointer)(2, 3, 4));
12. }
a) The difference of three numbers is:1
b) Run time error
c) The difference of three numbers is:-5
d) Varies
111. One of the uses for function pointers in C is
a) Nothing
b) There are no function pointers in c
c) To invoke a function
d) To call a function defined at run-time.
112. What is the output of this C code?
1. #include <stdio.h>
2. void f(int);
3. void (*foo)() = f;
4. int main(int argc, char *argv[])
5. {
6. foo(10);
7. return 0;
8. }
9. void f(int i)
10. {
11. printf("%d\n", i);
12. }
a) Compile time error
b) 10
c) Undefined behaviour
d) None of the mentioned
113. What is the output of this C code?
1. #include <stdio.h>
2. void f(int);
3. void (*foo)(void) = f;
4. int main(int argc, char *argv[])
5. {
6. foo(10);
7. return 0;
8. }
9. void f(int i)
10. {
11. printf("%d\n", i);
12. }
a) Compile time error
b) 10
c) Undefined behaviour
d) None of the mentioned
114. What is the output of this C code?
1. #include <stdio.h>
2. void f(int);
3. void (*foo)(float) = f;
4. int main()
5. {
6. foo(10);
7. }
8. void f(int i)
9. {
10. printf("%d\n", i);
11. }
a) Compile time error
b) 10
c) 10.000000
d) Undefined behaviour
115. What is the output of this C code?
1. #include <stdio.h>
2. void f(int (*x)(int));
3. int myfoo(int i);
4. int (*foo)(int) = myfoo;
5. int main()
6. {
7. f(foo(10));
8. }
9. void f(int (*i)(int))
10. {
11. i(11);
12. }
13. int myfoo(int i)
14. {
15. printf("%d\n", i);
16. return i;
17. }
a) Compile time error
b) Undefined behaviour
c) 10 11
d) 10 Segmentation fault
116. What is the output of this C code?
1. #include <stdio.h>
2. void f(int (*x)(int));
3. int myfoo(int);
4. int (*foo)() = myfoo;
5. int main()
6. {
7. f(foo);
8. }
9. void f(int(*i)(int ))
10. {
11. i(11);
12. }
13. int myfoo(int i)
14. {
15. printf("%d\n", i);
16. return i;
17. }
a) 10 11
b) 11
c) 10
d) Undefined behaviour
117.What is meaning of following declaration?
int(*ptr[5])();
(a)ptr is pointer to function.
(b)ptr is array of pointer to function
(c)ptr is pointer to such function which return type is array.
(d)ptr is pointer to array of function.
(e)None of these
118. What is meaning of following pointer declaration?
int(*(*ptr1)())[2];
(a)ptr is pointer to function.
(b)ptr is array of pointer to function
(c)ptr is pointer to such function which return type is pointer to an array.
(d)ptr is pointer array of function.
(e)None of these
119. What is size of generic pointer in c?
(a)0
(b)1
(c)2
(d)Null
(e)Undefined
120. What will be output of following c code?
#include<stdio.h>
int main(){
int *p1,**p2;
double *q1,**q2;
clrscr();
printf("%d %d ",sizeof(p1),sizeof(p2));
printf("%d %d",sizeof(q1),sizeof(q2));
getch();
return 0;
}
(a)1 2 4 8
(b)2 4 4 8
(c)2 4 2 4
(d)2 2 2 2
(e)2 2 4 4
121. What will be output if you will compile and execute the following c code?
#include<stdio.h>
int main(){
char huge *p=(char *)0XC0563331;
char huge *q=(char *)0XC2551341;
if(p==q)
else if(p>q)
else
return 0;
}
printf("Equal");
printf("Greater than");
printf("Less than");
(a)Equal
(b)Greater than
(c)Less than
(d)Compiler error
(e)None of above
122. What will be output if you will compile and execute the following c code?
#include<stdio.h>
int main(){
int a=5,b=10,c=15;
int *arr[]={&a,&b,&c};
printf("%d",*arr[1]);
return 0;
}
(a)5
(b)10
(c)15
(d)Compiler error
(e)None of above
123. What will be output if you will compile and execute the following c code?
#include<stdio.h>
int main(){
int a[2][4]={3,6,9,12,15,18,21,24};
printf("%d %d %d",*(a[1]+2),*(*(a+1)+2),2[1[a]]);
return 0;
}
(a)15 18 21
(b)21 21 21
(c)24 24 24
(d)Compiler error
(e)None of above
124. What will be output if you will compile and execute the following c code?
#include<stdio.h>
int main(){
const int x=25;
int * const p=&x;
*p=2*x;
printf("%d",x);
return 0;
}
(a)25
(b)50
(c)0
(d)Compiler error
(e)None of above
125. What will be output if you will compile and execute the following c code?
#include<stdio.h>
int main(){
static char *s[3]={"math","phy","che"};
typedef char *( *ppp)[3];
static ppp p1=&s,p2=&s,p3=&s;
char * (*(*array[3]))[3]={&p1,&p2,&p3};
char * (*(*(*ptr)[3]))[3]=&array;
p2+=1;
p3+=2;
printf("%s",(***ptr[0])[2]);
return 0;
}
(a) math
(b) phy
(c) che
(d) Compiler error
(e) None of these
126. What will be output if you will compile and execute the following c code?
#include<conio.h>
#include<stdio.h>
int display();
int(*array[3])();
int(*(*ptr)[3])();
int main(){
array[0]=display;
array[1]=getch;
ptr=&array;
printf("%d",(**ptr)());
(*(*ptr+1))();
return 0;
}
int display(){
int x=5;
return x++;
}
(a)5
(b)6
(c)0
(d)Compiler error
(e)None of these
127. What is the output of this program?
#include <stdio.h>
int main(void)
{
struct node
{
int a;
int b;
int c;
};
struct node s = { 3, 5, 6 };
struct node *pt = &s;
printf("%d\n", *(int*)pt);
return 0;
}
(a) 3
(b) 5
(c) 6
(d) 7
128. Consider the following code segment:
int foo(int x, int n)
{
int val = 1;
if (n > 0)
{
if (n % 2 == 1)
val *= x;
val *= foo(x * x, n / 2);
}
return val;
}
What function of x and n is computed by foo?
(a) x
n
(b) x n
(c) n
x
(d) none of the above
129. Consider the following program:
#include <stdio.h>
int main(void)
{
int a[5] = { 1, 2, 3, 4, 5 };
int *ptr = (int*)(&a + 1);
printf("%d %d\n", *(a + 1), *(ptr - 1));
return 0;
}
What is the output of this program?
(a) 2 2
(b) 2 1
(c) 2 5
(d) none of the above
130. Consider the following program:
#include <stdio.h>
int main(void)
{
int a[][3] = {1, 2, 3, 4, 5, 6};
int (*ptr)[3] = a;
printf("%d %d ", (*ptr)[1], (*ptr)[2]);
++ptr;
printf("%d %d\n", (*ptr)[1], (*ptr)[2]);
return 0;
}
What is the output of this program?
(a) 2 3 5 6
(b) 2 3 4 5
(c) 4 5 0 0
(d) none of the above
131. Consider the following code segment:
#include <stdlib.h>
int *f1(void)
{
int x = 10;
return &x;
}
int *f2(void)
{
int *ptr;
*ptr = 10;
return ptr;
}
int *f3(void)
{
int *ptr;
ptr = malloc(sizeof *ptr);
return ptr;
}
Which of these functions uses pointers incorrectly?
(a) f3 only
(b) f1 and f3
(c) f1 and f2
(d) f1, f2, and f3
132. Consider the following program:
#include <stdio.h>
void f1(int*, int);
void f2(int*, int);
void (*p[2])(int*, int);
int main(void)
{
int a = 3;
int b = 5;
p[0] = f1;
p[1] = f2;
p[0](&a, b);
printf("%d %d ", a, b);
p[1](&a, b);
printf("%d %d\n", a, b);
return 0;
}
void f1(int *p, int q)
{
int tmp = *p;
*p = q;
q = tmp;
}
void f2(int *p, int q)
{
int tmp = *p;
*p = q;
q = tmp;
}
What is the output of this program?
(a) 5 5 5 5
(b) 3 5 3 5
(c) 5 3 3 5
(d) none of the above
133. Consider the following program
typedef int (*test)(float*, float*);
test tmp;
What is the type of tmp?
(a) function taking two pointer-to-float arguments and returning pointer to int
(b) pointer to int
(c) pointer to function taking two pointer-to-float arguments and returning int
(d) none of the above
134. Consider the following program:
#include <stdio.h>
void f(char**);
int main(void)
{
char *argv[] = { "ab", "cd", "ef", "gh", "ij", "kl" };
f(argv);
return 0;
}
void f(char **p)
{
char *t;
t = (p += sizeof(int))[-1];
printf("%s\n", t);
}
What is the output of this program on an implementation where int and all pointer types occupy 2
bytes?
(a) ab
(b) cd
(c) ef
(d) gh
135.
Are the expression *ptr++ and ++*ptr are same?
A. True
B. False
136. If the size of integer is 4bytes, What will be the output of the program?
int main() {
int arr[] = {12, 13, 14, 15, 16};
printf("%d, %d, %d\n", sizeof(arr), sizeof(*arr), sizeof(arr[0]));
return 0;
}
A. 10, 2, 4
B. 20, 2, 2
C. 20, 4, 4
D. 16, 2, 2
137. True/False: The ampersand (&) is used to dereference a pointer variable in C++.
Answer: False
138 When the ___________ is present in front of a variable name, it represents the address of
that variable.
a. asterisk ( * )
b. conditional operator
c. ampersand ( & )
d. semicolon ( ; )
e. None of these
139 A pointer variable may be initialized with
a. any non-zero integer value
b. any address in the computer's memory
c. the address of an existing variable
d. a and c only
e. None of these
140 A pointer variable is designed to store ________.
a. any legal C++ value
b. only floating-point values
c. a memory address
d. a float value
e. None of these
141 We should use the delete operator for objects that were ________.
a. never used
b. not correctly initialized
c. created with the new operator
d. dereferenced inappropriately
e. None of these