C pointers quiz with answers and explanation 1. What is meaning of following declaration?
int (*ptr[5])();
2. What is meaning of following pointer declaration?
int (*(*ptr1)())[2];
3. What is size of generic pointer in c?
Explanation: Size of any type of pointer is 2 byte (In case of near pointer)
Note. By default all pointers are near pointer if default memory model is small.
4. What will be output of following c code?
#include <stdio.h>
int main(){
int *p1,**p2;
double *q1,**q2;
clrscr();
printf( "%d %d " , sizeof (p1), sizeof (p2));
printf( "%d %d" , sizeof (q1), sizeof (q2));
getch();
return 0;
}
5. What will be output if you will compile and execute the following c code?
#include <stdio.h>
int main(){
char huge *p=( char *)0XC0563331;
char huge *q=( char *)0XC2551341;
if (p==q)
printf( "Equal" );
else if (p>q)
printf( "Greater than" );
else
printf( "Less than" );
return 0;
} 6. What will be output if you will compile and execute the following c code?
#include <stdio.h>
int main(){
int a=5,b=10,c=15;
int *arr[]={&a,&b,&c};
printf( "%d" ,*arr[1]);
return 0;
}
7. What will be output if you will compile and execute the following c code?
#include <stdio.h>
int main(){
int a[2][4]={3,6,9,12,15,18,21,24};
printf( "%d %d %d" ,*(a[1]+2),*(*(a+1)+2),2[1[a]]);
return 0;
}
8. What will be output if you will compile and execute the following c code?
#include <stdio.h>
int main(){
const int x=25;
int * const p=&x;
*p=2*x;
printf( "%d" ,x);
return 0;
}
9. What will be output if you will compile and execute the following c code?
#include <stdio.h>
int main(){
static char *s[3]={ "math" , "phy" , "che" };
typedef char *( *ppp)[3];
static ppp p1=&s,p2=&s,p3=&s;
char * (*(*array[3]))[3]={&p1,&p2,&p3};
char * (*(*(*ptr)[3]))[3]=&array;
p2+=1;
p3+=2;
printf( "%s" ,(***ptr[0])[2]);
return 0;
} 10. What will be output if you will compile and execute the following c code?
#include <conio.h>
#include <stdio.h>
int display();
int (*array[3])();
int (*(*ptr)[3])();
int main(){
array[0]=display;
array[1]=getch;
ptr=&array;
printf( "%d" ,(**ptr)());
(*(*ptr+1))();
return 0;
}
int display(){
int x=5;
return x++;
}
11. What will be output if you will compile and execute the following c code?
#include <stdio.h>
int main(){
int i;
char far *ptr=( char *)0XB8000000;
*ptr= 'A' ;
*(ptr+1)=1;
*(ptr+2)= 'B' ;
*(ptr+3)=2;
*(ptr+4)= 'C' ;
*(ptr+5)=4;
return 0;
}
Output: It output will be A, B and C in blue, green and red color respectively. As shown in following figure:
12. What will be output if you will compile and execute the following c code?
#include <stdio.h>
#include <dos.h>
int main(){
int j;
union REGS i,o;
char far *ptr=( char *)0XA0000000;
i.h.ah=0;
i.h.al=0x13;
int86(0x10,&i,&o);
for (j=1;j<=100;j++){
*(ptr+j)=4;
}
return 0;
}
Outpt: One red color line in the graphics console as shown in the following figure:
13. What will be output if you will compile and execute the following c code?
#include <stdio.h>
int dynamic( int ,...);
int main(){
int x,y;
x=dynamic(2,4,6,8,10,12,14);
y=dynamic(3,6,9,12);
printf( "%d %d " ,x,y);
return 0;
}
int dynamic( int s,...){
void *ptr;
ptr=...;
( int *)ptr+=2;
s=*( int *)ptr;
return s;
}
14. Which of the following is not correct pointer declaration?
(i)int * const * ptr
(ii)int const * const * ptr;
(iii)const int ** const ptr;
(iv)const int const **ptr;
(v)int const ** const ptr;
15. What will be output if you will compile and execute the following c code?
#include <stdio.h>
int main(){
char arr[]= "C Question Bank" ;
float *fptr;
fptr=( float *)arr;
fptr++;
printf( "%s" ,fptr);
return 0;
}
16. In the following declaration ptr is
far * near * huge * ptr;
17. What will be output if you will compile and execute the following c code?
#include <stdio.h>
int main(){
char arr[]= "C Question Bank" ;
char *p;
p+=3;
p=arr;
p+=3;
*p=100;
printf( "%s" ,arr);
return 0;
}
18. Which of the following ptr is not pointer? 19. Which of the following is incorrect c statement?
20. Which of the following incorrect about far pointer?
(i)Size of far pointer is four byte.
(ii)Far pointer can points all segment of residence memory
(iii)If we will increment far pointer it can move from one segment to another segment.
Choose correct option:
No comments:
Post a Comment