Thursday, December 25, 2008

Array of Pointer in C program Questions with Answers


Q1. What will be output ?
Ans:
#include
#include
unsigned long int (* avg())[3]
{
static unsigned long int arr[3]={1,2,3};
return &arr;
}
void main()
{
unsigned long int (*ptr)[3];
ptr=avg();
clrscr();
printf("%d",*(*ptr+2));
getch();
}
Output :3

Q2. What will be output ?
#include
#include
void main()
{
char arr[5]={1,2,3,4,5};
char (*ptr)[5];
ptr=&arr;
ptr=(*ptr)+2;
clrscr();
printf("%d",**ptr);
getch();
}
Output: 3

Q3. output?
void main()
{
char *arr[3];
char a=1,b=2,c=3;
arr[0]=&a;
arr[1]=&b;
arr[2]=&c;
clrscr();
printf("%u %u",&b,arr[1]);
printf("\n%d",*arr[2]);
getch();
}

Output :
6678(any addresss) 6678(same address)
3

No comments:

Blog List