# Exercise: Questions on Advanced Pointer

Questions on Advanced Pointer : Question 1 :
```void fun(int *p)
{
int q = 10;
p = &q;
}

int main()
{
int r = 20;
int *p = &r;
fun(p);
printf("%d", *p);
return 0;
}
```

 10 20  Correct Compiler error Runtime Error
Questions on Advanced Pointer : Question 2 :
Assume sizeof an integer and a pointer is 4 byte. Output?
```#include <stdio.h>

#define R 10
#define C 20

int main()
{
int (*p)[R][C];
printf("%d",  sizeof(*p));
getchar();
return 0;
}
```

 200 4 800  Correct 80
Questions on Advanced Pointer : Question 3 :
```#include <stdio.h>
int main()
{
int a[5] = {1,2,3,4,5};
int *ptr = (int*)(&a+1);
printf("%d %d", *(a+1), *(ptr-1));
return 0;
}
```

 2 5  Correct Garbage Value Compiler Error Segmentation Fault
Questions on Advanced Pointer : Question 4 :
```#include <stdio.h>

char *c[] = {"GeksQuiz", "MCQ", "TEST", "QUIZ"};
char **cp[] = {c+3, c+2, c+1, c};
char ***cpp = cp;

int main()
{
printf("%s ", **++cpp);
printf("%s ", *--*++cpp+3);
printf("%s ", *cpp[-2]+3);
printf("%s ", cpp[-1][-1]+1);
return 0;
}
```

 TEST sQuiz Z CQ  Correct MCQ Quiz Z CQ TEST Quiz Z CQ GarbageValue sQuiz Z CQ
Questions on Advanced Pointer : Question 5 :
Predict the output
``` #include <string.h>
#include <stdio.h>
#include <stdlib.h>

void fun(char** str_ref)
{
str_ref++;
}

int main()
{
char *str = (void *)malloc(100*sizeof(char));
strcpy(str, "PROcoders");
fun(&str);
puts(str);
free(str);
return 0;
}
```

 PROcoders  Correct ROcoders Garbage Value Compiler Error
Questions on Advanced Pointer : Question 6 :
Assume that the size of int is 4.
```#include <stdio.h>
void f(char**);
int main()
{
char *argv[] = { "ab", "cd", "ef", "gh", "ij", "kl" };
f(argv);
return 0;
}
void f(char **p)
{
char *t;
t = (p += sizeof(int))[-1];
printf("%s\n", t);
}
```

 ab cd ef gh  Correct
Questions on Advanced Pointer : Question 7 :
```#include <stdio.h>
int main()
{
int a[][3] = {1, 2, 3, 4, 5, 6};
int (*ptr)[3] = a;
printf("%d %d ", (*ptr)[1], (*ptr)[2]);
++ptr;
printf("%d %d\n", (*ptr)[1], (*ptr)[2]);
return 0;
}

```

 2 3 5 6  Correct 2 3 4 5 4 5 0 0 none of the above
Questions on Advanced Pointer : Question 8 :
```#include <stdio.h>
#include <stdlib.h>

int main(void)
{
int i;
int *ptr = (int *) malloc(5 * sizeof(int));

for (i=0; i<5; i++)
*(ptr + i) = i;

printf("%d ", *ptr++);
printf("%d ", (*ptr)++);
printf("%d ", *ptr);
printf("%d ", *++ptr);
printf("%d ", ++*ptr);
}
```

 Compiler Error 0 1 2 2 3  Correct 0 1 2 3 4 1 2 3 4 5
Questions on Advanced Pointer : Question 9 :
Output of following program
```#include <stdio.h>
int fun(int arr[]) {
arr = arr+1;
printf("%d ", arr[0]);
}
int main(void) {
int arr[2] = {10, 20};
fun(arr);
printf("%d", arr[0]);
return 0;
}
```

 Compiler Error 20 10  Correct 20 20 10 10
Questions on Advanced Pointer : Question 10 :
What is printed by the following C program?
```\$include <stdio.h>
int f(int x, int *py, int **ppz)
{
int y, z;
**ppz += 1;
z  = **ppz;
*py += 2;
y = *py;
x += 3;
return x + y + z;
}

void main()
{
int c, *b, **a;
c = 4;
b = &c;
a = &b;
printf( "%d", f(c,b,a));
getchar();
}
```

 18 19  Correct 21 22