C Programming Questions and Answers – Pointers and Arrays
C Programming Questions and Answers – Pointers and Arrays
1.What is the output of this C code?
#include <stdio.h>
void main()
{
int a[3] = {1, 2, 3};
int *p = a;
printf(“%p\t%p”, p, a);
}
a) Same address is printed.
b) Different address is printed.
c) Compile time error
d) Nothing
View Answer
2.What is the output of this C code?
#include <stdio.h>
void main()
{
char *s = “hello”;
char *p = s;
printf(“%p\t%p”, p, s);
}
a) Different address is printed
b) Same address is printed
c) Run time error
d) Nothing
View Answer
3.What is the output of this C code?
#include <stdio.h>
void main()
{
char *s= “hello”;
char *p = s;
printf(“%c\t%c”, p[0], s[1]);
}
a) Run time error
b) h h
c) h e
d) h l
View Answer
4.What is the output of this C code?
#include <stdio.h>
void main()
{
char *s= “hello”;
char *p = s;
printf(“%c\t%c”, *(p + 3), s[1]);
}
a) h e
b) l l
c) l o
d) l e
View Answer
5.What is the output of this C code?
#include <stdio.h>
void main()
{
char *s= “hello”;
char *p = s;
printf(“%c\t%c”, 1[p], s[1]);
}
a) h h
b) Run time error
c) l l
d) e e
View Answer
6.What is the output of the code given below?
#include <stdio.h>
void foo( int[] );
int main()
{
int ary[4] = {1, 2, 3, 4};
foo(ary);
printf(“%d “, ary[0]);
}
void foo(int p[4])
{
int i = 10;
p = &i;
printf(“%d “, p[0]);
}
a) 10 10
b) Compile time error
c) 10 1
d) Undefined behaviour
View Answer
7.What is the output of the code given below?
#include <stdio.h>
int main()
{
int ary[4] = {1, 2, 3, 4};
int *p = ary + 3;
printf(“%d\n”, p[-2]);
}
a) 1
b) 2
c) Compile time error
d) Some garbage value
View Answer
8.What is the output of the code given below?
#include <stdio.h>
int main()
{
int ary[4] = {1, 2, 3, 4};
int *p = ary + 3;
printf(“%d %d\n”, p[-2], ary[*p]);
}
a) 2 3
b) Compile time error
c) 2 4
d) 2 somegarbagevalue
View Answer
9.What is the output of this C code?
#include <stdio.h>
int main()
{
int ary[4] = {1, 2, 3, 4};
printf(“%d\n”, *ary);
}
a) 1
b) Compile time error
c) Some garbage value
d) Undefined variable
View Answer
10.What is the output of this C code?
#include <stdio.h>
int main()
{
const int ary[4] = {1, 2, 3, 4};
int *p;
p = ary + 3;
*p = 5;
printf(“%d\n”, ary[3]);
}
a) 4
b) 5
c) Compile time error
d) 3
View Answer
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
View Answer
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
View Answer
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
View Answer
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
View Answer
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
View Answer
16.What is the output of the code given below?
#include <stdio.h>
int main()
{
int ary[4] = {1, 2, 3, 4};
int p[4];
p = ary;
printf(“%d\n”, p[1]);
}
a) 1
b) Compile time error
c) Undefined behaviour
d) 2