C Programming Quiz Pointer Download
C Programming Quiz Pointer Download
C Programming Quiz Pointer Download
com
http://www.gkseries.com/computer-engineering/c-programming/pointer/multiple-choice-questions-and-answers-on-c-pointers-1
1.
main()
{
int row[20],i,sum=0;
int *p=row;
for(i=0;i<20;i++)
*(p+i)=1;
for(i=0;i<20;i+=sizeof(int))
sum+=*(p+i);
printf("sum=%d\n",sum);
}
[A] sum=10
[B] sum=40
[C] sum=60
[D] sum=190
2.
What is the missing statement in the following function which copies string x into string y?
[A] x=y
[B] *x++=*y++
[C] (*x)++=(*y)++
Pointer variable char *x is pointing to a location and the char *y is assigned to that location. If we assume the
missing statement is *x++=*y++ then both the variables point to the next respective location till null ('\0') found.
3.
char *ptr;
char myString[]="abcdefg";
ptr=myString
ptr+=5;
[A] fg
[B] efg
[C] defg
[D] cdefg
That means the pointer variable is incremented by 5. Hence it is pointing to the 6th location. i.e. fg
4.
main()
{
int a[]={1,2,9,8,6,3,5,7,8,9};
int *p=a+1;
int *q=a+6;
printf("\n%d",q-p);
}
[A] 9
[B] 5
[C] 2
5.