C Programming Questions and Answers on Pointers and Arrays for Freshers

1. What is the output of this C code?

  1.     #include 
  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
Answer: a
2. What is the output of this C code?

  1.     #include 
  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
Answer: b
3. What is the output of this C code?

  1.     #include 
  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
Answer: c
4. What is the output of this C code?

  1.     #include 
  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
Answer: d
5. What is the output of this C code?
  1.     #include 
  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
Answer: d
6. What is the output of the code given below?

  1.     #include 
  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
Answer: c
7. What is the output of the code given below?
  1.     #include 
  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
Answer: b
8. What is the output of the code given below?

  1.     #include 
  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
Answer: d
9. What is the output of this C code?
  1.     #include 
  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
Answer: a
10. What is the output of this C code?
  1.     #include 
  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
Answer: b
11. Different ways to initialize an array with all elements as zero are

a) int array[5] = {};
b) int array[5] = {0};
c) int a = 0, b = 0, c = 0;
    int array[5] = {a, b, c};
d) All of the mentioned
Answer: d
12. The elements in the array of the following code are
    int array[5] = {5};

a) 5, 5, 5, 5, 5
b) 5, 0, 0, 0, 0
c) 5, (garbage), (garbage), (garbage), (garbage)
d) (garbage), (garbage), (garbage), (garbage), 5
Answer: b
13. Which of the following declaration is illegal?

a) int a = 0, b = 1, c = 2;
    int array[3] = {a, b, c};
b) int size = 3;
    int array[size];
c) int size = 3;
    int array[size] = {1, 2, 3};
d) All of the mentioned
Answer: c
14. An array of similar data types which themselves are collection of dissimilar data type are

a) Linked Lists
b) Trees
c) Array of Structure
d) All of the mentioned
Answer: c
15. Comment on an array of void data type:

a) It can store any data-type
b) It only stores element of similar data type to first element
c) It acquires the data type with the highest precision in it
d) You cannot have an array of void data type
Answer: d
16. What is the output of the code given below?

  1.     #include 
  2.     int main()
  3.     {
  4.         int ary[4] = {1, 2, 3, 4};
  5.         int p[4];
  6.         p = ary;
  7.         printf("%d\n", p[1]);
  8.     }
a) 1
b) Compile time error
c) Undefined behaviour
d) 2
Answer: b

Related

Actionscript Objective Questions for Interviews

Top Most Actionscript Objective Questions 1. What keyword brings control out of a loop A. splitB. breakC. endD. stop Ans B 2. Read the following code var str1String = foobar; var str2String = he...

Data Structure Objective Type Questions and Answers on Circular Linked List

1. What differentiates a circular linked list from a normal linked list? a) You cannot have the ‘next’ pointer point to null in a circular linked listb) It is faster to traverse the circular linked...

Data Structure Multiple Choice Questions and Answers on Single Linked List Operations

1. A linear collection of data elements where the linear node is given by means of pointer is called? a) Linked listb) Node listc) Primitive listd) None of the mentioned Answer: a 2. Consider an ...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item