Quiz on Arrays and Pointers
1 What is the output of the following program?
#include <stdio.h>
void foo(int a[])
{
a[0]=10;
printf("%d",a[0]);
return ;
}
int main()
{
int a[]={1,2,3};
foo(a);
printf("%d",a[0]);
return 0;
}
11
101
1010
110
ans 1010
2 What is the output of the following program?
#include<stdio.h>
int main()
{
int size, i;
size=5;
int arr[size]={1,2,3,4,5};
for(i=1; i<=size;i++)
{
printf("%d", arr[i]);
}
return 0;
}
12345
2345
23456
None of These
ans. none of these
3 In C, if you pass an array as an argument to a function,
what actually gets passed?
Value of elements in array
First element of the array
Base address of the array
Address of the last element of array
ans . base address of array
4 What will be output if you will execute following c code?
#include<stdio.h>
void main(){
char arr[16]="The African Queen";
printf("%s",arr);
}
The African Queen
The African Quee
he African Queen
Error
ans. error
5 What is the valid statement that you can make about the
output of the following code?
#include<stdio.h>
void fun(int * a)
{
int ** x=&a;
printf("%u\n",x);
return ;
}
int main(){
int a[5]={1,2,3,4,5};
int * b = a;
int ** y=&b;
printf("%u\n",y);
fun(b);
return 0;
}
Both the printed values are necessarily the same
Both the printed values are necessarily different
Both the printed values may be same
None of these
ans. both the printed values may be same
6 What will be output if you will execute following C code?
#include<stdio.h>
void main(){
char arr[20]="MysticRiver";
printf("%d",sizeof(arr));
}
11
20
44
80
ans.20
7 What is the output of the following code?
#include<stdio.h>
int main()
{
int a[5] = {5, 1, 15, 20, 25};
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf("%d, %d, %d", i, j, m);
return 0;
}
2 2 15
3 2 20
3 1 20
3 2 15
ans. 3 2 15
8 Which of the following are correct ways to initialize an array?
(There may be multiple answers.)
int num[]={1,2,3,4};
int num{}={1,2,3,4};
int num[4]={1,2,3,4};
int num()={1,2,3,4};
ans. A&C
9 What will be the output of the following program?
#include<stdio.h>
int main(){
int a = 330;
char *p;
p =( char *)&a;
printf("%d ",*p);
return 0;
}
330
74
54
331
ans 74
Labels:
Array
,
pointers
,
quiz