Array I
Ques 1. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *arr[4]={"hello", "good", "bad", "yes" };
char *chptr;
chptr=arr;
chptr++;
printf("\n chptr = %s", *chptr);
return 0;
}
options:
A. good
B. hello
C. bad
D. run time error
Ques 2. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *arr[4]={"hello", "good", "bad", "yes" };
char **chptr;
chptr=arr;
*chptr++;
printf("\n chptr = %s", chptr[1]);
return 0;
}
options:
A. hello
B. bad
C. good
D. run time error
Ques 3. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
int iarr[5] = {2,3,4,5,6};
printf("\n chptr = %d %d", *(iarr+1) , *(*(&iarr)+1));
return 0;
}
options:
A. 3 2
B. 2 2
C. 3 3
D. compile time error
Ques 4. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
int inum[5] = {2,3,4,5,6};
printf("\n chptr = %d %d", sizeof(inum), sizeof(inum[0]));
return 0;
}
options:
A. 4 4
B. 20 4
C. 20 20
D. compile time error
Ques 5. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
int s[5] = {32,23,43,52,16};
int *p=(&s+1);
p-- ;
printf("\n chptr = %d ", *p);
return 0;
}
options:
A. 16
B. 32
C. 23
D. compile time error
Ques 6. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
void fun(int ar[])
{
printf("%d\n", ar[4]);
}
int main()
{
int ar[5] = {32,23,43,52,16};
fun(ar);
return 0;
}
options:
A. 16
B. 32
C. 43
D. compile time error
Ques 7. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
void fun(int ar[])
{
printf("%d\n", ar[2]);
}
int main()
{
int ar[5] = {32,23,43,52,16};
fun(ar[2]);
return 0;
}
options:
A. 43
B. 16
C. 52
D. run time error
Ques 8. what is the output for the below program?
#include <stdio.h>
#include <stdlib.h>
void fun(int arr[])
{
printf("%d\n", arr[3]);
}
int main()
{
int numarr[5] = {2,3,4,15,23,4,6};
fun(&numarr[1]);
return 0;
}
options:
A. 15
B. compiler error
C. 23
D. 15
Ques 9. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
void fun(int arr[])
{
int k;
if(k=1)
printf("%d\n", arr[0]);
else
printf("%d\n", arr[3]);
}
int main()
{
int narr[5] = {2,3,4,15,23,4,6};
fun(narr);
return 0;
}
options:
A. 15
B. 2
C. 4
D. compiler error
Ques 10. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
int x,y,z,e,f;
int *narr[5] = {&x,&y,&z,&e,&f};
int marr[2][2] ={5,6,7,8} ;
narr[1] = 1000;
printf("%d %d \n", narr[1],marr[1][1]);
return 0;
}
options:
A. compile time error
B. run time error
C. 1000 8
D. 6
Answers
1. D
2. B
3. C
4. B
5. A
6. A
7. D
8. C
9. B
10. C