C Pointers 2

C Pointers 2



Ques 1. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int (*fun)();
int disp()
{
printf("\n this is display function");
}

int main()
{
fun=disp;
fun;
return 0;
}

options:
A. runtime error
B. this is display funtion
C. compiler error
D. prints some garbage string.


Ques 2. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int (*fun)();
int disp()
{
printf("\n this is display function");
}

int main()
{
fun=disp;
fun();
return 0;
}

options:
A. runtime error
B. this is display funtion
C. compiler error
D. prints some garbage string.




Ques 3. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int (*fun)(int, int, char );
int math(int x, int y, char ch)
{
if(ch == '+')
return x+y;
}

int main()
{
int ans;
fun=math;
ans = fun(22,33,'+');
printf("\n ans= %d", ans);
return 0;
}



options:
A. 0 
B. runtime error
C. compiler error
D. 55


Ques 4. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int (*fun[4])(int, int, char );
int math(int x, int y, char ch)
{
if(ch == '+')
return x+y;
else
return 0;
}

int main()
{
int ans;
fun[0]=math;
ans = fun[0](22,33,'+');
printf("\n ans = %d", ans);
return 0;
}

options:
A. 55
B. compiler error
C. 0 
D. 155


Ques 5. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
typedef int (*f)(int, int, char);
f funptr[3];

int math(int x, int y, char ch)
{
if(ch == '+')
return x+y;
else
return 0;
}

int main()
{
int ans;
funptr[0] = math;
ans = funptr[0](2,3,'+');
printf("\n ans = %d", ans);
return 0;
}

options:
A. 55
B. 5
C. 0
D. compiler error


Ques 6. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
void fun()
{
printf("\n this is fun().");
}

void math(int (*fee)())
{
fee();
}

int main()
{
math(fun);
return 0;
}

options:
A. prints garbage string.
B. run time error
C. compiler error
D. this is fun().


Ques 7. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
void fun()
{
printf("\n this is fun().");
}
void fun2();

int main()
{
fun2=fun;
fun2();
return 0;
}

options:
A. run time error
B. this is fun().
C. compiler error
D. garbage string.


Ques 8. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main ()
{
int arr[2][4] ={{4,1,3,4},{5,8,9,11}};
printf("%d, %d", ++(*arr[0]), *arr[0]);
return 0;
}

options:
A. 4 4
B. 5 5
C. 3 3
D. compiler error


Ques 9. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int arr[2][4] ={{4,1,3,4},{5,8,9,11}};
printf("%d, %d", *(arr+1)[0], *arr[0]);
return 0;
}

options:
A. compiler error
B. 4, 1
C. 1, 4
D. 5, 4


Ques 10. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int arr[2][4] ={{4,1,3,4},{5,8,9,11}};
arr++;
printf("%d, %d", *(arr+1)[0], *arr[0]);
return 0;
}
options:
A. 4, 1
B. 2, 3
C. Compiler error
D. 5, 8


Ques 11. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int arr[8] ={4,1,3,4,5,8,9,11};
int *p=arr;

printf("%d %d", *(p+1), *(arr+1));
return 0;
}

options:
A. 1 1
B. 4 4
C. 5 5
D. compiler error


Ques 12. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int arr[2][4] ={4,1,3,4,5,8,9,11};
int *p=arr[1];

printf("%d %d", *(p+1), *(arr[0]+2));
return 0;
}

options:
A. 1, 3
B. 8, 3
C. compiler error
D. 5, 9


Ques 13. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>

int main ()
{
int arr[2][4] ={4,1,3,4,5,8,9,11};
int *p=arr[0];

printf("%d %d", *(p+1), *(p+6));
return 0;
}

options:
A. 4, 8
B. compiler error
C. 1, 9 
D. 0, 0


Ques 14. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>

int main ()
{
int arr[2][4] ={4,1,3,4,5,8,9,11};
int *p=arr[0];

printf("%d %d", ++*(p+1), ++*(p+6));
return 0;
}
options:
A. 2, 10
B. compiler error
C. 3, 11
D. 0 , 0


Ques 15. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main ()
{
int arr[2][4] ={7,1,44,4,5,8,9,11};
int *p=arr[0];

printf("%d %d", *p, ++(*p));
return 0;
}
options:
A. 8 8
B. 7 7
C. 1 1
D. 7 1



Answers

1. C 2. B 3. D 4. A 5. B 6. D 7. C 8. B 9. D 10. C 11. A 12. B 13. C 14. D 15. A