Advanced Pointers
Ques 1. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int * add(int *p, int *q)
{
int sum;
sum=*p+*q;
return ∑
}
int main()
{
int r = 20, s=3;
int *sum;
int *p = &r, *q=&s;
sum=add(p, q);
printf("%d ", *sum);
return 0;
}
options:
A. runtime error
B. 23
C. 0
D. compiler error
Ques 2. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int * add(int *p, int *q)
{
int *sum =(int*)malloc(4);
*sum=*p+*q;
return sum;
}
int main()
{
int r = 20, s=3;
int *sum;
int *p = &r, *q=&s;
sum=add(p, q);
printf("%d ", *sum);
return 0;
}
options:
A. compiler error
B. runtime error
C. 23
D. 0
Ques 3. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
void swap(int *p, int *q)
{
int t;
t=*p;
*p=*q;
*q=t;
}
int main()
{
int r = 20, s=3;
int *p = &r, *q=&s;
swap(p, q);
printf("*p=%d *q=%d", *p, *q);
return 0;
}
options:
A. *p=20 *q=3
B. runtime error
C. *p=3 *q=20
D. compiler error
Ques 4. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
void swap(int *p, int *q)
{
int t;
t=p;
p=q;
q=t;
}
int main()
{
int r = 20, s=3;
int *p = &r, *q=&s;
swap(p, q);
printf("*p=%d *q=%d", *p, *q);
return 0;
}
options:
A. compiler error
B. *p=20 *q=3
C. *p=3 *q=20
D. run time error
Ques 5. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
int r = 20, s=3;
int *p = r, *q = s;
printf("*p=%d *q=%d", *p, *q);
return 0;
}
options:
A. 3, 20
B. 20, 3
C. compiler error
D. runtime error
Ques 6. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
int (*q)[5];
printf("%d", sizeof(*q));
return 0;
}
options:
A. compiler eror
B. 4
C. 20
D. runtime error
Ques 7. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
int (**q)[4] ={3,4,5,6,7,6};
printf("%d", sizeof(**q));
return 0;
}
options:
A. 4
B. 16
C. 24
D. runtime error
Ques 8. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
int q[2][3][2] ={3,4,5,6,7,6};
printf("%d", sizeof(q));
return 0;
}
options:
A. 20
B. 24
C. 4
D. 48
Ques 9. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
int q[6] ={3,4,5,6,7,6};
int *r=(q+1);
printf("%d %d", *(r+2), *r++);
return 0;
}
options:
A.
B.
C.
D.
Ques 10. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
int q[6] ={3,4,5,6,7,6};
int *r=(q+1);
printf("%d %d", *(r+2), *r++);
return 0;
}
options:
A. 7, 4
B. 6, 4
C. 5, 4
D. 5, 6
Ques 11. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
int p =32;
int *q=&p;
int **r=&q;
printf("%d %d", **r, *q);
return 0;
}
options:
A. 32 32
B. 0 0
C. grabage value
D. runtime error
Ques 12. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
int p =32;
int *q=&p;
int **r=q;
printf("%d %d", **r, *q);
return 0;
}
options:
A. 32 32
B. 0 0
C. grabage value
D. runtime error
Ques 13. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *p[] ={"welcome", "good", "test", "computer", "ptinstitute.in" };
int **q[]={ p+1, p+2, p+3};
int ***r=q;
printf("%s %s", **r, **(r+1));
return 0;
}
options:
A. good test
B. welcome good
C. welcome test
D. test good
Ques 14. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *p[] ={"welcome", "good", "test", "computer", "ptinstitute.in" };
int **q[]={ p+1, p+4, p+3};
int ***r=q;
r++;
printf("%s %s", **r, **(r+1));
return 0;
}
options:
A. computer ptinstitute.in
B. ptinstitute.in computer
C. welcome good
D. runtime error
Ques 15. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *p[] ={"welcome", "good", "test", "computer", "ptinstitute.in" };
int **q[]={ p+1, p+4, p+3};
printf("%s %s", ++(*p), *(p+2));
return 0;
}
options:
A. good test
B. welcome test
C. elcome test
D. ood test
Ques 16. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *p[] ={"welcome", "good", "test", "computer", "ptinstitute.in" };
int **q[]={ p+1, p+4, p+3};
printf("%s %s", **q, **(q+2));
return 0;
}
options:
A. test computer
B. welcome test
C. welcome good
D. good computer
Ques 17. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *p[] ={"welcome", "good", "test", "computer", "ptinstitute.in" };
int **q[]={ p+1, p+4, p+3};
printf("%s %s", *(*q++), **(q+2));
return 0;
}
options:
A. compiler error
B. runtime error
C. welcome good
D. good test
Ques 18. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *p[] ={"welcome", "good", "test", "computer", "ptinstitute.in" };
int **q[]={ p+1, p+4, p+3};
printf("%s %s", *(*q)++, **(q+2));
return 0;
}
options:
A. compiler error
B. runtime error
C. welcome good
D. good computer
Ques 19. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *p[] ={"welcome", "good", "test", "computer", "ptinstitute.in" };
int **q[]={ p+1, p+4, p+3};
p[1]= p[1] + 2;
p[3]= p[0] + 4;
printf("%s %s", *(*q)++, **(q+2));
return 0;
}
options:
A. od mputer
B. runtime error
C. welcome good
D. od ome
Ques 20. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
void fun( char *p)
{
printf("\n %s", ++p);
}
int main()
{
char *p[] ={"welcome", "good", "test", "computer", "ptinstitute.in" };
fun(p[2]);
return 0;
}
options:
A. est
B. runtime error
C. compiler error
D. test
Answers
1. A
2. C
3. C
4. B
5. D
6. C
7. B
8. D
9. C
10. A
11. A
12. D
13. A
14. B
15. C
16. D
17. A
18. D
19. D
20. A